Skip to content

The agent that grows with you

test(kanban): keep two shared-scratch invariants

kshitijk4poorff8102310ca7
diff --git a/tests/hermes_cli/test_kanban_gc_retention.py b/tests/hermes_cli/test_kanban_gc_retention.py
index e804072d91b..1546d185920 100644
--- a/tests/hermes_cli/test_kanban_gc_retention.py
+++ b/tests/hermes_cli/test_kanban_gc_retention.py
@@ -163,72 +163,32 @@ def test_cmd_gc_keeps_a_scratch_dir_a_live_task_still_uses(board):
assert kinds
-def test_cleanup_workspace_keeps_a_scratch_dir_a_live_task_still_uses(board):
- from hermes_cli import kanban_db_workspace as kbw
-
- with kbc.connect_closing() as conn:
- archived, _live, shared = _shared_scratch(conn)
- kbw._cleanup_workspace(conn, archived)
- assert (shared / "note.txt").read_text(encoding="utf-8") == "still needed"
-
-
-def test_cleanup_workspace_keeps_a_scratch_dir_a_live_task_on_another_board_uses(board):
- """An archived task on the default board must not rmtree a dir a named board still has ready."""
+def test_cleanup_workspace_keeps_scratch_when_other_boards_cannot_be_listed(board, monkeypatch):
+ """A named board's live task uses the dir; if boards cannot be listed, refuse the delete."""
from hermes_cli import kanban_db_workspace as kbw
kb.create_board("other")
+ shared = kb.workspaces_root() / "cross-board"
+ shared.mkdir(parents=True)
+ (shared / "note.txt").write_text("still needed", encoding="utf-8")
with kbc.connect_closing() as conn:
archived = kb.create_task(conn, title="archived on default")
- shared = kb.workspaces_root() / "cross-board"
- shared.mkdir(parents=True)
- (shared / "note.txt").write_text("still needed", encoding="utf-8")
- with kb.write_txn(conn):
- conn.execute(
- "UPDATE tasks SET status='archived', workspace_kind='scratch', "
- "workspace_path=? WHERE id=?",
- (str(shared), archived),
- )
with kbc.connect_closing(board="other") as other:
live = kb.create_task(other, title="live on other")
- with kb.write_txn(other):
- other.execute(
- "UPDATE tasks SET status='ready', workspace_kind='scratch', "
- "workspace_path=? WHERE id=?",
- (str(shared), live),
+ for board_slug, task_id, status in ((None, archived, "archived"), ("other", live, "ready")):
+ with kbc.connect_closing(board=board_slug) as conn, kb.write_txn(conn):
+ conn.execute(
+ "UPDATE tasks SET status=?, workspace_kind='scratch', workspace_path=? WHERE id=?",
+ (status, str(shared), task_id),
)
- with kbc.connect_closing() as conn:
- kbw._cleanup_workspace(conn, archived)
- assert (shared / "note.txt").read_text(encoding="utf-8") == "still needed"
+ real_iterdir = Path.iterdir
+ def iterdir(self):
+ if self.name == "boards":
+ raise PermissionError("boards dir unreadable")
+ return real_iterdir(self)
-def test_cleanup_workspace_keeps_scratch_when_another_board_reuses_the_task_id(board):
- """A sibling board may reuse this board's task id for a different live task."""
- from hermes_cli import kanban_db_workspace as kbw
-
- kb.create_board("other")
- with kbc.connect_closing() as conn:
- archived = kb.create_task(conn, title="archived on default")
- shared = kb.workspaces_root() / "same-id"
- shared.mkdir(parents=True)
- (shared / "note.txt").write_text("still needed", encoding="utf-8")
- with kb.write_txn(conn):
- conn.execute(
- "UPDATE tasks SET status='archived', workspace_kind='scratch', "
- "workspace_path=? WHERE id=?",
- (str(shared), archived),
- )
- with kbc.connect_closing(board="other") as other:
- live = kb.create_task(other, title="live on other")
- with kb.write_txn(other):
- other.execute(
- "UPDATE task_events SET task_id=? WHERE task_id=?",
- (archived, live),
- )
- other.execute(
- "UPDATE tasks SET id=?, status='ready', workspace_kind='scratch', "
- "workspace_path=? WHERE id=?",
- (archived, str(shared), live),
- )
+ monkeypatch.setattr(Path, "iterdir", iterdir)
with kbc.connect_closing() as conn:
kbw._cleanup_workspace(conn, archived)
assert (shared / "note.txt").read_text(encoding="utf-8") == "still needed"