Coverage for src / harnessutils / workspace.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.2, created at 2026-04-07 09:04 -0600
« prev ^ index » next coverage.py v7.13.2, created at 2026-04-07 09:04 -0600
1"""Workspace management for harness-utils.
3Manages the .harness/ directory under a workspace root, providing a
4stable project UUID that persists across sessions.
5"""
7import uuid
8from pathlib import Path
11def resolve_workspace(workspace_root: Path, harness_name: str = ".harness") -> tuple[Path, str]:
12 """Ensure the harness directory exists and return (harness_dir, project_id).
14 Creates the harness directory and project_id file if they don't exist.
15 Reads existing project_id if present.
17 Args:
18 workspace_root: Root directory of the workspace
19 harness_name: Name of the harness directory (default: ".harness")
21 Returns:
22 Tuple of (harness_dir, project_id)
23 """
24 harness_dir = workspace_root / harness_name
25 harness_dir.mkdir(parents=True, exist_ok=True)
27 id_file = harness_dir / "project_id"
28 if id_file.exists():
29 project_id = id_file.read_text().strip()
30 else:
31 project_id = str(uuid.uuid4())
32 id_file.write_text(project_id)
34 return harness_dir, project_id