Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/specify_cli/integrations/_file_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ def after_file_change(path: Path) -> None:
def changing_file(path: Path, *, removal: bool = False):
"""Journal a host mutation without claiming the file for uninstall."""
before_file_change(path, removal=removal)
yield
after_file_change(path)
try:
yield
finally:
after_file_change(path)
Comment on lines +74 to +75


def write_text(path: Path, content: str, *, encoding: str = "utf-8", errors: str | None = None) -> int:
Expand Down
16 changes: 16 additions & 0 deletions tests/specify_cli/integrations/test_file_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,19 @@ def after_change(path):
assert not (tmp_path / "retained" / "SKILL.md").exists()
elif swap_at in ("after_unlink", "before_rmdir_self") or not descriptor_io:
assert directory.is_dir()


def test_changing_file_reports_completion_when_mutation_raises(tmp_path):
path = tmp_path / "file.txt"
observed = []
token = _file_changes.file_change_observer.set(lambda *args: observed.append(args))
try:
with pytest.raises(RuntimeError, match="mutation failed"), _file_changes.changing_file(
path
):
path.write_text("partial")
raise RuntimeError("mutation failed")
finally:
_file_changes.file_change_observer.reset(token)

assert observed == [(path, True, False), (path, False, False)]