From 4e8ea6725d9120fa0e92439b13694a1fc7b6ef34 Mon Sep 17 00:00:00 2001 From: fotedev Date: Fri, 30 Oct 2026 04:50:24 +0200 Subject: [PATCH] test(core): backup uniquify contract (-2/-3 suffix, never clobber) --- tests/python/test_ghost_core.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/python/test_ghost_core.py b/tests/python/test_ghost_core.py index d8a3741..afbab3c 100644 --- a/tests/python/test_ghost_core.py +++ b/tests/python/test_ghost_core.py @@ -586,7 +586,11 @@ def test_label_may_carry_a_subdirectory(self): self.assertTrue(os.path.isfile( os.path.join(self.backup_root, "sub", "state.vscdb"))) - def test_existing_destination_is_clobbered(self): + def test_existing_destination_is_uniquified_not_clobbered(self): + # 4f308f8 changed the contract: an existing same-label destination is + # NEVER overwritten (that destroyed pristine pre-run copies); the new + # backup uniquifies with a -2 suffix instead. The old copy must + # survive untouched and the report must point at the unique path. dst = os.path.join(self.backup_root, "state.vscdb") os.makedirs(self.backup_root, exist_ok=True) with open(dst, "wb") as f: @@ -594,8 +598,18 @@ def test_existing_destination_is_clobbered(self): r = backup.backup_to_timestamped_dir( self.src_file, self.backup_root, "state.vscdb") self.assertTrue(r["ok"], r) + self.assertEqual(r["destination"], dst + "-2") with open(dst, "rb") as f: + self.assertEqual(f.read(), b"stale-backup-bytes") + with open(dst + "-2", "rb") as f: self.assertEqual(f.read(), b"sqlite-bytes" * 64) + # A third run keeps walking the suffix chain (-3), never touching -1. + r2 = backup.backup_to_timestamped_dir( + self.src_file, self.backup_root, "state.vscdb") + self.assertTrue(r2["ok"], r2) + self.assertEqual(r2["destination"], dst + "-3") + with open(dst, "rb") as f: + self.assertEqual(f.read(), b"stale-backup-bytes") def test_transient_lock_retries_then_succeeds(self): calls = []