Files
leleka/engine/strata/tools/test_setup_feed_engine.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

84 lines
4.2 KiB
Python

"""#3469 #3437: the 0.2 releases carry no flat engine zip, so a source checkout (UPDATE.bat, setup) fetches the engine package
for its card from the signed update feed and installs its files in engine/.
python -m unittest tools.test_setup_feed_engine
"""
from __future__ import annotations
import json
import sys
import tempfile
import types
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(ROOT / "tools"))
import setup # noqa: E402
from strata_control import engine_component as ec # noqa: E402
class FeedEngine(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.addCleanup(self.tmp.cleanup)
self.root = Path(self.tmp.name)
self.eng = self.root / "engine"
self.eng.mkdir()
(self.eng / "BUILD.json").write_text(json.dumps({"version": "0.1.45", "source": "prebuilt", "archs": [89]}), encoding="utf-8")
(self.eng / setup.EXE).write_bytes(b"old")
self.package = self.root / "components" / "engine" / "0.1.46-test"
self.package.mkdir(parents=True)
(self.package / "BUILD.json").write_text(json.dumps({"version": "0.1.46", "archs": [89]}), encoding="utf-8")
(self.package / setup.EXE).write_bytes(b"new")
for name, value in (("home", lambda: self.root), ("say", lambda *a, **k: None), ("ok", lambda *a, **k: None),
("warn", lambda *a, **k: None)):
patch = mock.patch.object(setup, name, value)
patch.start()
self.addCleanup(patch.stop)
patch = mock.patch.object(setup.acquisition, "require", lambda what: None)
patch.start()
self.addCleanup(patch.stop)
def run_update(self, code=0):
return mock.patch.object(setup.subprocess, "run", return_value=types.SimpleNamespace(returncode=code, stdout="", stderr="no feed"))
def test_the_package_becomes_the_installed_engine(self):
with self.run_update() as run, mock.patch.object(ec, "resolve", return_value=types.SimpleNamespace(root=self.package)):
got = setup.engine_from_feed(self.eng, updating=True)
self.assertEqual(got, self.eng)
cmd = run.call_args.args[0]
self.assertIn("update", cmd)
self.assertIn("--no-control", cmd)
self.assertNotIn("STRATA_NO_ACQUIRE", run.call_args.kwargs["env"]) # this one step may fetch
self.assertEqual((self.eng / setup.EXE).read_bytes(), b"new")
meta = json.loads((self.eng / "BUILD.json").read_text(encoding="utf-8"))
self.assertEqual((meta["version"], meta["source"]), ("0.1.46", "prebuilt"))
self.assertEqual((self.eng / ".previous" / setup.EXE).read_bytes(), b"old") # one generation to roll back to
def test_no_feed_keeps_the_installed_engine(self):
with self.run_update(code=6):
self.assertIsNone(setup.engine_from_feed(self.eng, updating=True))
self.assertEqual((self.eng / setup.EXE).read_bytes(), b"old")
def test_a_release_without_the_zip_falls_back_to_the_feed(self):
gpu = {"arch": 89, "archs": [89], "vram_gb": 8.0, "index": 0}
(self.eng / "BUILD.json").write_text(json.dumps({"version": "0.1.45", "source": "prebuilt", "archs": [89]}), encoding="utf-8")
with mock.patch.object(setup, "engine_dir", lambda toolkit=13: self.eng), mock.patch.object(setup, "_urlopen", side_effect=OSError("HTTP Error 404")), mock.patch.object(setup, "engine_from_feed", return_value=self.eng) as feed:
got = setup.get_prebuilt(setup.PREBUILT_URL, gpu, "none", updating=True)
self.assertEqual(got, self.eng)
feed.assert_called_once()
feed.reset_mock()
setup.get_prebuilt(setup.PREBUILT_URL, gpu, "none", updating=True, toolkit=12)
feed.assert_not_called() # the experimental CUDA 12 engine has no feed package here
def test_the_minimum_is_the_0_2_engine(self):
self.assertLess((0, 1, 45), setup.MIN_ENGINE)
self.assertGreaterEqual((0, 1, 46), setup.WIN_HIP_MIN_ENGINE)
if __name__ == "__main__":
unittest.main()