This repository has been archived on 2026-08-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
kb-skills/gsd-openclaw/tests/conftest.py
T
starmen1265 96f06f3751
PR Test / lint (pull_request) Successful in 2s
feat: 添加 gsd-openclaw 技能
2026-03-11 10:41:01 +08:00

93 lines
2.5 KiB
Python

"""Pytest fixtures for gsd-openclaw tests."""
import shutil
import pytest
from pathlib import Path
from gsd_openclaw.workspace import Workspace, WorkspaceManager
from gsd_openclaw.state_manager import SessionState
@pytest.fixture
def tmp_workspaces_root(tmp_path: Path) -> Path:
"""Temporary root for workspace testing.
This ensures tests don't pollute the real ~/gsd-workspaces directory.
Args:
tmp_path: Pytest's built-in temporary directory fixture.
Returns:
Path to a temporary gsd-workspaces directory.
"""
return tmp_path / "gsd-workspaces"
@pytest.fixture
def workspace_manager(tmp_workspaces_root: Path) -> WorkspaceManager:
"""WorkspaceManager with temporary root for isolation.
Creates a WorkspaceManager that uses a temporary directory instead
of the user's home directory. Automatically cleans up after the test.
Args:
tmp_workspaces_root: Fixture providing temporary workspace root.
Yields:
WorkspaceManager instance configured for testing.
"""
manager = WorkspaceManager("test-project", tmp_workspaces_root)
yield manager
# Cleanup
if manager.workspace.root.exists():
shutil.rmtree(manager.workspace.root)
@pytest.fixture
def created_workspace(workspace_manager: WorkspaceManager) -> Workspace:
"""A workspace that has been created (directories exist).
Args:
workspace_manager: Fixture providing WorkspaceManager.
Returns:
Workspace object with all directories created.
"""
return workspace_manager.create()
@pytest.fixture
def tmp_state_dir(tmp_path: Path) -> Path:
"""Temporary directory for state file testing.
Args:
tmp_path: Pytest's built-in temporary directory fixture.
Returns:
Path to a temporary directory for state files.
"""
state_dir = tmp_path / ".gsd"
state_dir.mkdir(parents=True, exist_ok=True)
return state_dir
@pytest.fixture
def sample_state() -> SessionState:
"""A valid SessionState instance for testing.
Returns:
SessionState with all fields populated.
"""
return SessionState(
schema_version="1.0",
session_id="test-session-fixture",
project_name="test-project",
tmux_session_name="gsd-test-project",
tmux_pane_id="%100",
created_at="2026-03-10T10:00:00Z",
last_active_at="2026-03-10T12:00:00Z",
command_count=10,
last_output_snapshot="Test output snapshot",
display_name="Test Project Display Name"
)