okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
2.8 KiB67 linesraw
1"""The gate of CLEAN-1A: in every machine class x model set, the app's plain Load and the app's Models-screen Load start the engine as `strata launch` does,
2apart from the allow-list (tests/snapshot/allowlist.py).  Reads the golden files, so it needs no Node and no machine; test_config_snapshot.py keeps the golden files true."""
3
4from __future__ import annotations
5
6import json
7import sys
8import unittest
9from pathlib import Path
10
11ROOT = Path(__file__).resolve().parents[2]
12if str(ROOT) not in sys.path:
13    sys.path.insert(0, str(ROOT))
14
15from tests.snapshot import allowlist  # noqa: E402
16from tests.snapshot.generate import GOLDEN  # noqa: E402
17
18
19def flat(value, prefix=""):
20    if isinstance(value, dict):
21        out = {}
22        for k, v in value.items():
23            out.update(flat(v, f"{prefix}/{k}"))
24        return out
25    return {prefix: value}
26
27
28def comparable(rec: dict, allowed_cfg: set[str]) -> dict:
29    cfg = {k: v for k, v in rec["config_file"].items() if k not in allowed_cfg}
30    env = {k: v for k, v in rec["engine"]["env_set"].items() if k not in allowed_cfg and k not in allowlist.ENV_BY_DESIGN}
31    return {"config": flat(cfg), "argv": rec["engine"]["argv"], "env": env, "fetches": rec.get("fetches")}
32
33
34class EntryPointsAgree(unittest.TestCase):
35    maxDiff = None
36
37    def cells(self):
38        for path in sorted(GOLDEN.glob("*/*.json")):
39            yield path.parent.name + "/" + path.stem, json.loads(path.read_text(encoding="utf-8"))["entries"]
40
41    def check(self, other: str, allowed: set[str]):
42        seen = 0
43        for cell, entries in self.cells():
44            with self.subTest(cell=cell, entry=other):
45                want, got = comparable(entries["launch"], allowed), comparable(entries[other], allowed)
46                self.assertEqual(want["argv"], got["argv"], f"{cell}: engine arguments")
47                self.assertEqual(want["env"], got["env"], f"{cell}: engine environment")
48                self.assertEqual(want["config"], got["config"], f"{cell}: run config")
49                self.assertEqual(want["fetches"], got["fetches"], f"{cell}: the drafter downloads asked for")
50            seen += 1
51        self.assertGreaterEqual(seen, 24)
52
53    def test_the_plain_load_starts_the_engine_as_launch_does(self):
54        self.check("app_plain", set(allowlist.BY_DESIGN))
55
56    def test_the_models_screen_load_differs_only_by_the_choice_it_saves(self):
57        self.check("app_models", set(allowlist.BY_DESIGN) | set(allowlist.MODELS_SCREEN))
58
59    def test_no_app_entry_writes_request_slots(self):
60        for cell, entries in self.cells():
61            for entry in ("app_plain", "app_models"):
62                self.assertNotIn("parallel", entries[entry]["config_file"], f"{cell}/{entry}")
63                self.assertNotIn("--batch-mtp", entries[entry]["engine"]["argv"], f"{cell}/{entry}")
64
65
66if __name__ == "__main__":
67    unittest.main()