Repositories / agent-snapshot.git

agent-snapshot.git

Clone (read-only): git clone http://git.guha-anderson.com/git/agent-snapshot.git

Branch

Add tests for git internals and written tracked files

Author
Arjun Guha <a.guha@northeastern.edu>
Date
2026-05-02 10:27:18 -0400
Commit
e25ef4d1edee3d516c0b6fae3a8ffbb2b7b1660d
test_programs/rewrite_clean_tracked.py
new file mode 100644
index 0000000..dabe208
--- /dev/null
+++ b/test_programs/rewrite_clean_tracked.py
@@ -0,0 +1,6 @@
+from pathlib import Path
+
+root = Path(__file__).resolve().parents[1]
+path = root / "testdata" / "clean.txt"
+
+path.write_text(path.read_text())
test_programs/write_git_internal.py
new file mode 100644
index 0000000..b174018
--- /dev/null
+++ b/test_programs/write_git_internal.py
@@ -0,0 +1,5 @@
+from pathlib import Path
+
+root = Path(__file__).resolve().parents[1]
+
+(root / ".git" / "delete_me").write_text("internal git scratch\n")
tests/test_agent_snapshot.py
index efb0ad4..e6419a0 100644
--- a/tests/test_agent_snapshot.py
+++ b/tests/test_agent_snapshot.py
@@ -48,6 +48,14 @@ def pristine_testdata():
 
 
 @pytest.fixture(autouse=True)
+def pristine_git_internal_file():
+    internal = ROOT / ".git" / "delete_me"
+    internal.unlink(missing_ok=True)
+    yield
+    internal.unlink(missing_ok=True)
+
+
+@pytest.fixture(autouse=True)
 def ignore_config(tmp_path, monkeypatch):
     config_home = tmp_path / "xdg-config"
     config_path = config_home / "agent-snapshot" / "ignore.json"
@@ -172,6 +180,23 @@ def test_clean_git_tracked_read_records_repo_without_blob(tmp_path):
     assert any(repo["root"] == str(ROOT.resolve()) for repo in snap.manifest["git_repositories"])
 
 
+def test_git_internal_directory_writes_are_ignored(tmp_path):
+    snap = capture(tmp_path, PYTHON, "test_programs/write_git_internal.py")
+    manifest_paths = {item["path"] for item in snap.manifest["files"]}
+
+    assert str((ROOT / ".git" / "delete_me").resolve()) not in manifest_paths
+
+
+def test_written_clean_git_tracked_file_gets_after_blob(tmp_path):
+    snap = capture(tmp_path, PYTHON, "test_programs/rewrite_clean_tracked.py")
+    clean = snap.file(TESTDATA / "clean.txt")
+
+    assert "write" in clean["operations"]
+    assert clean["git"]["tracked"] is True
+    assert clean["git"]["dirty"] is False
+    assert snap.blob_text(clean["after"]["blob"]) == (TESTDATA / "clean.txt").read_text()
+
+
 def test_dirty_untracked_created_and_deleted_files_are_captured(tmp_path):
     # This test covers the cases where Git metadata is not enough:
     # - dirty tracked files differ from HEAD, so their content must be blobbed