Files
leleka/engine/strata/tests/time_skip/test_atomic.py
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

63 lines
2.4 KiB
Python

"""atomic.replace: a file another program is reading is waited for, not failed on (Windows "Access is denied")."""
from __future__ import annotations
import os
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from strata_control import atomic # noqa: E402
class TestReplace(unittest.TestCase):
def setUp(self) -> None:
self.tmp = Path(tempfile.mkdtemp(prefix="strata-atomic-"))
def test_plain_replace(self):
(self.tmp / "a.tmp").write_text("new")
(self.tmp / "a").write_text("old")
atomic.replace(self.tmp / "a.tmp", self.tmp / "a")
self.assertEqual((self.tmp / "a").read_text(), "new")
def test_a_held_file_is_waited_for_on_windows_and_the_error_is_kept_elsewhere(self):
real = os.replace
calls = {"n": 0}
def held(src, dst):
calls["n"] += 1
if calls["n"] < 4:
raise PermissionError(5, "Access is denied")
return real(src, dst)
(self.tmp / "b.tmp").write_text("new")
slept = []
with mock.patch("os.replace", held), mock.patch.object(atomic.os, "name", "nt"):
atomic.replace(self.tmp / "b.tmp", self.tmp / "b", sleep=slept.append)
self.assertEqual(calls["n"], 4)
self.assertEqual(len(slept), 3)
self.assertEqual((self.tmp / "b").read_text(), "new")
# on a system without this behaviour a PermissionError is a real error
(self.tmp / "c.tmp").write_text("x")
with mock.patch("os.replace", side_effect=PermissionError(13, "denied")), mock.patch.object(atomic.os, "name", "posix"):
with self.assertRaises(PermissionError):
atomic.replace(self.tmp / "c.tmp", self.tmp / "c")
def test_a_file_that_stays_held_is_given_up_on_after_the_patience(self):
now = [0.0]
with mock.patch("os.replace", side_effect=PermissionError(5, "Access is denied")), mock.patch.object(atomic.os, "name", "nt"):
with self.assertRaises(PermissionError):
atomic.replace("x", "y", patience=1.0, sleep=lambda s: now.__setitem__(0, now[0] + 0.5), clock=lambda: now[0])
def test_write_text_leaves_no_temporary_file(self):
atomic.write_text(self.tmp / "run.json", "{}")
self.assertEqual(sorted(p.name for p in self.tmp.iterdir()), ["run.json"])
if __name__ == "__main__":
unittest.main()