From bc667e54d62bbd7d072558b6fc00d5412d75d4f7 Mon Sep 17 00:00:00 2001 From: Dusk-92 Date: Thu, 3 Sep 2026 10:52:40 +0200 Subject: [PATCH] Test stale backup cleanup safety --- tests/test_safety.py | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/test_safety.py b/tests/test_safety.py index c8728f8..16b3862 100644 --- a/tests/test_safety.py +++ b/tests/test_safety.py @@ -646,6 +646,62 @@ class SmartUpdateTests(unittest.TestCase): remote_packages._package_state_is_current(root, "example", "v1") ) + def test_current_package_cleans_stale_transaction_backup(self): + with tempfile.TemporaryDirectory() as root: + dll = os.path.join(root, "UnitXP_SP3.dll") + with open(dll, "wb") as handle: + handle.write(b"current-unitxp") + + remote_packages._record_package_state( + root, + "unitxp_sp3", + "v90", + ["UnitXP_SP3.dll"], + ) + + stale_backup = dll + ".modernization-backup-941614e28c62" + with open(stale_backup, "wb") as handle: + handle.write(b"old-unitxp") + + self.assertTrue( + remote_packages._package_state_is_current( + root, + "unitxp_sp3", + "v90", + ) + ) + self.assertFalse(os.path.exists(stale_backup)) + self.assertTrue(os.path.isfile(dll)) + + def test_non_current_package_keeps_transaction_backup_for_recovery(self): + with tempfile.TemporaryDirectory() as root: + dll = os.path.join(root, "UnitXP_SP3.dll") + with open(dll, "wb") as handle: + handle.write(b"current-unitxp") + + remote_packages._record_package_state( + root, + "unitxp_sp3", + "v90", + ["UnitXP_SP3.dll"], + ) + + stale_backup = dll + ".modernization-backup-recovery" + with open(stale_backup, "wb") as handle: + handle.write(b"old-unitxp") + + with open(dll, "wb") as handle: + handle.write(b"modified-after-state") + + self.assertFalse( + remote_packages._package_state_is_current( + root, + "unitxp_sp3", + "v90", + ) + ) + self.assertTrue(os.path.exists(stale_backup)) + def test_release_asset_revision_detects_replaced_asset_under_same_tag(self): release_a = { "tag_name": "Release",