Test the pruning on open and kill its surviving mutants

This commit is contained in:
2026-11-15 23:17:22 +01:00
parent dbc8cfe854
commit 36d9ddb6f5
2 changed files with 22 additions and 4 deletions
+8 -3
View File
@@ -54,9 +54,7 @@ def main(argv: list[str]) -> int:
return 2
home = pathlib.Path.home()
config = located(None, home)
if not isinstance(config, Failure) and argv[0] == "open":
pruned(config, home)
done = config if isinstance(config, Failure) else act(argv[0], *opened(config, argv[1], home))
done = config if isinstance(config, Failure) else performed(config, argv[0], argv[1], home)
if isinstance(done, Failure):
print(f"project-record: {done.reason}", file=sys.stderr)
return 1
@@ -64,6 +62,13 @@ def main(argv: list[str]) -> int:
return 0
def performed(config: ProjectConfig, command: str, name: str, home: pathlib.Path, run: Git = git) -> str | Failure:
"""What command, one of COMMANDS, prints for the record called name. An open also prunes the copies of removed worktrees."""
if command == "open":
pruned(config, home, run)
return act(command, *opened(config, name, home))
def opened(config: ProjectConfig, name: str, home: pathlib.Path) -> tuple[RecordStore, pathlib.Path]:
"""The store of the record called name, and the copy it gets where it isn't kept as a file. A store that keeps the version it read, for a later save, keeps it beside the copy."""
copy = home / COPIES / config.key / worktree_folder(config.top) / f"{name}.md"
+14 -1
View File
@@ -69,7 +69,7 @@ class Pruned(unittest.TestCase):
return {folder.name for folder in self.folders.iterdir()}
def listed(self, *tops: str):
return lambda *args, **kwargs: "".join(f"worktree {top}\nHEAD abc\nbranch refs/heads/x\n\n" for top in tops)
return lambda *args, **kwargs: "" if args != ("worktree", "list", "--porcelain") else "".join(f"worktree {top}\nHEAD abc\nbranch refs/heads/x\n\n" for top in tops)
def test_removes_the_copies_of_worktrees_git_no_longer_lists_and_keeps_the_others(self):
main.pruned(self.config, self.home, self.listed("/code/acme", "/code/acme-item-5"))
@@ -88,6 +88,19 @@ class Pruned(unittest.TestCase):
main.pruned(self.config, self.home, self.listed("/code/acme"))
self.assertTrue((self.folders / "decisions.md").exists())
def test_a_copy_that_cannot_be_removed_does_not_fail_the_open(self):
self.folders.chmod(0o500)
self.addCleanup(self.folders.chmod, 0o700)
main.pruned(self.config, self.home, self.listed("/code/acme"))
self.assertEqual(len(self.kept()), 3)
def test_an_open_prunes_and_a_save_does_not(self):
run = self.listed("/code/acme-item-5")
self.assertEqual(main.performed(self.config, "save", "goals-and-audience", self.home, run), "/code/acme-item-5/README.md is the record itself, so nothing is left to store.")
self.assertEqual(len(self.kept()), 3)
self.assertEqual(main.performed(self.config, "open", "goals-and-audience", self.home, run), "/code/acme-item-5/README.md")
self.assertEqual(self.kept(), {main.worktree_folder(pathlib.Path("/code/acme-item-5"))})
def test_does_nothing_where_the_project_has_no_copies(self):
main.pruned(worktree_config("/code/acme"), self.home / "elsewhere", self.listed("/code/acme"))