diff --git a/src/project_manager/check.py b/src/project_manager/check.py index fc7a53b..c814d93 100644 --- a/src/project_manager/check.py +++ b/src/project_manager/check.py @@ -17,6 +17,7 @@ class Kind(StrEnum): BROKEN = "broken" # forward points at a missing slot ORPHAN_FORWARD = "orphan-forward" # forward exists, no db row ORPHAN_OWNER = "orphan-owner" # slot .owner points at a forward not claimed by db + OPS_OWNED = "ops-owned" # slot .owner -> stacker_ops_marker (ephemeral ownership) @dataclass(frozen=True) @@ -111,6 +112,7 @@ def _orphan_owners( if not paths.worktrees.is_dir(): return scope_dir = paths.project(scope) if scope is not None else None + ops_marker = paths.stacker_ops_marker() for repo_dir in sorted(paths.worktrees.iterdir()): if not repo_dir.is_dir(): continue @@ -118,6 +120,17 @@ def _orphan_owners( owner = s.owner_target() if owner is None: continue + if _is_ops_marker(owner, ops_marker): + if scope_dir is not None: + continue + yield Finding( + kind=Kind.OPS_OWNED, + repo=repo_dir.name, + slot_path=s.path, + forward_path=owner, + detail="slot held by a stacker ops operation", + ) + continue if scope_dir is not None and owner.parent != scope_dir: continue if (s.path, owner) in active_pairs: @@ -131,6 +144,13 @@ def _orphan_owners( ) +def _is_ops_marker(owner: Path, ops_marker: Path) -> bool: + try: + return owner.resolve() == ops_marker.resolve() + except OSError: + return False + + def _project_findings( paths: Paths, project: str, ) -> tuple[list[Finding], set[tuple[Path, Path]]]: diff --git a/src/project_manager/pool/ls.py b/src/project_manager/pool/ls.py index 030654c..1249b28 100644 --- a/src/project_manager/pool/ls.py +++ b/src/project_manager/pool/ls.py @@ -8,7 +8,7 @@ from project_manager.pool import slot as slot_mod class PoolRow: repo: str uuid: str - status: str # "FREE" or project name + status: str # "FREE", a project name, or "OPS" for stacker-ops slots def ls(paths: Paths, repo: str | None) -> list[PoolRow]: @@ -22,11 +22,24 @@ def ls(paths: Paths, repo: str | None) -> list[PoolRow]: entry.name for entry in paths.worktrees.iterdir() if entry.is_dir() ) + ops_marker = paths.stacker_ops_marker() rows: list[PoolRow] = [] for r in repos: for s in slot_mod.list_slots(paths, r): owner = s.owner_target() - # owner points at //; parent.name is the project - status = "FREE" if owner is None else owner.parent.name + if owner is None: + status = "FREE" + elif _is_ops_marker(owner, ops_marker): + status = "OPS" + else: + # owner points at //; parent.name is the project + status = owner.parent.name rows.append(PoolRow(repo=r, uuid=s.uuid, status=status)) return rows + + +def _is_ops_marker(owner, ops_marker) -> bool: # noqa: ANN001 + try: + return owner.resolve() == ops_marker.resolve() + except OSError: + return False diff --git a/src/project_manager/project/ls.py b/src/project_manager/project/ls.py index 3259ed0..fc9a66c 100644 --- a/src/project_manager/project/ls.py +++ b/src/project_manager/project/ls.py @@ -10,6 +10,7 @@ _KIND_TO_LABEL: dict[check_mod.Kind, str] = { check_mod.Kind.DRIFT: "drift", check_mod.Kind.STALE: "stale", check_mod.Kind.BROKEN: "broken", + check_mod.Kind.OPS_OWNED: "ops-owned", }