fix(client): preserve index-only snapshot state

This commit is contained in:
Nirav Patel
2026-08-24 04:41:22 -04:00
parent 7eb57acdbe
commit 444275cb6c
2 changed files with 75 additions and 10 deletions
+48
View File
@@ -1346,6 +1346,54 @@ class TestCodexReviewFindings(GitScenarioBase):
client.build_snapshot(self.local)
self.assertEqual(run_git(self.local, "status", "--porcelain"), before)
def test_index_only_work_survives_a_pushed_snapshot(self):
"""A staged version remains backed up when worktree bytes equal HEAD."""
self.write(self.local, "a.txt", "committed")
run_git(self.local, "add", "-A")
run_git(self.local, "commit", "-m", "base")
run_git(self.local, "push", "-u", "granthi", "main")
head_before = run_git(self.local, "rev-parse", "HEAD")
self.write(self.local, "a.txt", "INDEX-ONLY STAGED VERSION")
run_git(self.local, "add", "a.txt")
self.write(self.local, "a.txt", "committed")
status_before = run_git(self.local, "status", "--porcelain")
index_before = run_git(self.local, "write-tree")
with open(os.path.join(self.local, "a.txt")) as f:
file_before = f.read()
self.assertEqual(status_before, "MM a.txt")
ref = client.push_snapshot(self.local, "dev-index-only")
self.assertIsNotNone(ref)
snapshot = run_git(self.bare, "rev-parse", ref)
parents = run_git(self.bare, "log", "-1", "--format=%P", snapshot).split()
self.assertTrue(
any(run_git(self.bare, "show", f"{parent}:a.txt")
== "INDEX-ONLY STAGED VERSION" for parent in parents),
f"staged version unreachable from {parents}")
self.assertEqual(run_git(self.local, "rev-parse", "HEAD"), head_before)
self.assertEqual(run_git(self.local, "write-tree"), index_before)
self.assertEqual(run_git(self.local, "status", "--porcelain"), status_before)
with open(os.path.join(self.local, "a.txt")) as f:
self.assertEqual(f.read(), file_before)
self.write(self.local, "a.txt", "A NEW STAGED VERSION")
run_git(self.local, "add", "a.txt")
self.write(self.local, "a.txt", "committed")
second_ref = f"refs/granthi-backup/dev-index-only/second"
with mock.patch.object(client, "snapshot_ref",
return_value=(second_ref, "second")):
self.assertEqual(
client.push_snapshot(self.local, "dev-index-only"), second_ref)
second = run_git(self.bare, "rev-parse", second_ref)
second_parents = run_git(
self.bare, "log", "-1", "--format=%P", second).split()
self.assertTrue(
any(run_git(self.bare, "show", f"{parent}:a.txt")
== "A NEW STAGED VERSION" for parent in second_parents),
f"updated staged version unreachable from {second_parents}")
def test_a_truncated_listing_refuses_instead_of_guessing(self):
"""[P3] A name that is merely beyond the page cap must not resolve to a
different repo that happens to exist under your own account."""