From a94cb3b8cd94dbfd5415958233755f963118988f Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 24 Nov 2026 16:56:59 +0300 Subject: [PATCH] mode_round_probe: publish mode on Windows (MODE-ROUND-PROBE-STAGE-CLEANUP) agent: yes AI-assisted: yes --- tests/test_mode_round_probe.py | 37 ++++++++++++++++++++++++++++++++++ tools/mode_round_probe.py | 3 +-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/test_mode_round_probe.py b/tests/test_mode_round_probe.py index 0bfe590da..447ec8f75 100644 --- a/tests/test_mode_round_probe.py +++ b/tests/test_mode_round_probe.py @@ -216,6 +216,43 @@ class SummaryLineTests(unittest.TestCase): self.assertIn("6/7 f16 transcendentals 0/65536 RNE/RTZ diffs", out) self.assertIn("v_sin_f16_e32: 3/65536 RNE/RTZ diffs", out) + def test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly(self): + with tempfile.TemporaryDirectory() as tmp: + report = os.path.join(tmp, "report.json") + with open(report, "w", encoding="utf-8") as f: + f.write('{"initial": 1}\n') + os.chmod(report, 0o444) + + real_unlink = os.unlink + + def windows_strict_unlink(p): + mode = os.stat(p).st_mode + if not (mode & 0o200): + raise PermissionError(13, f"Access is denied: {p}") + return real_unlink(p) + + with mock.patch.object(probe, "replace_retry", side_effect=OSError(13, "Permission denied")), \ + mock.patch("os.unlink", side_effect=windows_strict_unlink): + err = probe.write_json_report(report, {"new": True}) + self.assertIsNotNone(err) + + leftover = [f for f in os.listdir(tmp) if f.startswith(".mode_round_probe-")] + self.assertEqual(leftover, []) + + def test_publish_applies_published_mode_on_windows(self): + with tempfile.TemporaryDirectory() as tmp: + report = os.path.join(tmp, "report_win.json") + chmod_calls = [] + real_chmod = os.chmod + + def track_chmod(p, mode): + chmod_calls.append((p, mode)) + real_chmod(p, mode) + + with mock.patch("os.name", "nt"), mock.patch("os.chmod", side_effect=track_chmod): + probe.write_json_report(report, {"win": True}) + self.assertTrue(len(chmod_calls) > 0) + if __name__ == "__main__": unittest.main() diff --git a/tools/mode_round_probe.py b/tools/mode_round_probe.py index 2506d1731..966d497cb 100644 --- a/tools/mode_round_probe.py +++ b/tools/mode_round_probe.py @@ -230,8 +230,7 @@ def write_json_report(path, data): with open(fd, "w", encoding="utf-8", newline="\n") as f: fd = None json.dump(data, f, indent=2) - if os.name != "nt": - os.chmod(tmp, published_mode(destination)) + os.chmod(tmp, published_mode(destination)) replace_retry(tmp, destination) except BaseException: if fd is not None: