From 15396d11136e5987e1cbee391d94b482befb4e5e Mon Sep 17 00:00:00 2001 From: WebIdentity1 <212448219+WebIdentity1@users.noreply.github.com> Date: Mon, 23 Nov 2026 18:25:56 -0500 Subject: [PATCH] test: exercise AWC manifest staged cleanup on all hosts --- tests/test_awc_manifest.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test_awc_manifest.py b/tests/test_awc_manifest.py index 8188ed82e..b77b98fde 100644 --- a/tests/test_awc_manifest.py +++ b/tests/test_awc_manifest.py @@ -389,24 +389,29 @@ class ManifestTest(unittest.TestCase): self.assertEqual(f.read(), previous) self.assertEqual(os.listdir(self.tmp.name), ["manifest.json"]) - def test_failed_replace_removes_the_staging_file_and_keeps_the_manifest(self): + def test_failed_replace_of_read_only_staged_manifest_removes_writable_temp(self): out = os.path.join(self.tmp.name, "manifest.json") previous = '{"previous": true}\n' with open(out, "w", encoding="utf-8") as f: f.write(previous) - made_writable = [] + staged_modes = [] real_chmod = os.chmod def chmod(path, mode, *args, **kwargs): - if isinstance(path, str) and os.path.basename(path).startswith(".awc_manifest-") and mode == 0o600: - made_writable.append(path) + if isinstance(path, str) and os.path.basename(path).startswith(".awc_manifest-"): + staged_modes.append((path, mode)) return real_chmod(path, mode, *args, **kwargs) - with mock.patch.object(awc_manifest, "replace_retry", side_effect=OSError("replace denied")), \ + def denied_replace(staged, _destination): + os.chmod(staged, 0o444) + raise OSError("replace denied") + + with mock.patch.object(awc_manifest, "replace_retry", side_effect=denied_replace), \ mock.patch.object(awc_manifest.os, "chmod", chmod): with self.assertRaises(OSError): awc_manifest.write_manifest([], 0, 0, "json", out) - self.assertEqual(len(made_writable), 1) + self.assertEqual([mode for _, mode in staged_modes[-2:]], [0o444, 0o600]) + self.assertEqual(staged_modes[-2][0], staged_modes[-1][0]) with open(out, encoding="utf-8") as f: self.assertEqual(f.read(), previous) self.assertEqual(os.listdir(self.tmp.name), ["manifest.json"])