diff --git a/strata_control/updater.py b/strata_control/updater.py index a32ac750..d7118378 100644 --- a/strata_control/updater.py +++ b/strata_control/updater.py @@ -705,15 +705,31 @@ def stage_engine(ctx: Context, feed: feedmod.Feed, pkg: feedmod.EnginePackage, a raise +def _runs_on_dsv41_engine(config) -> bool: + """True for a DeepSeek run config. The test start swaps the engine for the one being updated (the Strata engine), and a DeepSeek model + runs on strata-dsv41, which has its own package: the Strata engine rejects its options ('unknown argument: --eos') and a good engine + would be refused. Unreadable configs count as not DeepSeek, so they are tried as before.""" + try: + cfg = json.loads(Path(config).read_text(encoding="utf-8-sig")) + except (OSError, ValueError): + return False + if not isinstance(cfg, dict): + return False + exe = cfg.get("exe") + return cfg.get("arch") == "deepseek41" or (isinstance(exe, str) and "strata-dsv41" in exe.replace("\\", "/").rsplit("/", 1)[-1].lower()) + + def discover_run_config(environ=None) -> Path | None: """A saved model's run config for the test start: the one a saved profile uses if its files are all present, otherwise any - installed model whose files are present. None when no model is installed (the first run).""" + installed model whose files are present. DeepSeek models are left out (they run on strata-dsv41, not on the engine under test). + None when no model can be used (the first run).""" from strata_control import models, profiles try: listed = models.list_installed() except Exception: # noqa: BLE001 - discovery is best effort return None - ready = [m for m in listed.get("models", []) if m.get("component_status") == "present" and m.get("source_config")] + ready = [m for m in listed.get("models", []) if m.get("component_status") == "present" and m.get("source_config") + and not _runs_on_dsv41_engine(m["source_config"])] if not ready: return None try: diff --git a/tests/terminal/test_update_test_start_model.py b/tests/terminal/test_update_test_start_model.py new file mode 100644 index 00000000..af0208b7 --- /dev/null +++ b/tests/terminal/test_update_test_start_model.py @@ -0,0 +1,54 @@ +"""The update's test start must not pick a DeepSeek model: it runs the engine under test (the Strata engine) with the model's options, and a +DeepSeek model runs on strata-dsv41 (a separate package). Seen on a PC with a DeepSeek and a Qwen model: the test start failed with +'unknown argument: --eos' and engine 0.1.50 was refused.""" + +import json +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +from strata_control import models, updater + + +class DiscoverRunConfigCase(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory(prefix="strata-discover-") + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + + def config(self, name: str, **fields) -> str: + path = self.root / f"strata-{name}.json" + path.write_text(json.dumps(fields), encoding="utf-8") + return str(path) + + def discover(self, *entries): + listed = {"models": [{"id": i, "component_status": "present", "source_config": c} for i, c in entries]} + with mock.patch.object(models, "list_installed", return_value=listed), \ + mock.patch("strata_control.profiles.list_profiles", return_value=[]): + return updater.discover_run_config() + + def test_deepseek_is_skipped_for_a_model_the_engine_under_test_can_run(self): + deep = self.config("deepseek", exe="C:/e/engine-dsv41/0.1.51/strata-dsv41.exe", arch="deepseek41", args=["--eos", "1"]) + qwen = self.config("qwen", exe="C:/e/engine/strata.exe", args=["--pack", "x"]) + # "deepseek..." sorts first by id, which is how the update picked it before + self.assertEqual(self.discover(("deepseek-v4.1-flash", deep), ("unsloth-ud-iq4_xs", qwen)), Path(qwen)) + + def test_deepseek_is_recognised_by_its_exe_alone(self): + deep = self.config("deepseek", exe=r"C:\e\engine-dsv41\0.1.51\strata-dsv41.exe", args=[]) + self.assertIsNone(self.discover(("deepseek-v4.1-flash", deep))) + + def test_only_deepseek_installed_means_no_model(self): + deep = self.config("deepseek", exe="x", arch="deepseek41") + self.assertIsNone(self.discover(("deepseek-v4.1-flash", deep))) + + def test_other_and_unreadable_configs_are_still_used(self): + qwen = self.config("qwen", exe="C:/e/engine/strata.exe") + broken = self.root / "strata-broken.json" + broken.write_text("{not json", encoding="utf-8") + self.assertEqual(self.discover(("a-broken", str(broken))), broken) + self.assertEqual(self.discover(("b-qwen", qwen)), Path(qwen)) + + +if __name__ == "__main__": + unittest.main()