okami.mom/strata

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

Niko1221Merge branch 'f-clean-step0' into f-clean-1abe32c7f3f

main
1.3 KiB35 linesraw
1"""The Python Control the app's host talks to, for the config snapshot: ``python control_shim.py drafting plan|fetch ...``.
2
3The app's host runs ``strata drafting plan --config ...`` and ``strata drafting fetch --config ... --if-needed`` before a Load.  Here the same commands run through the
4real strata_cli on the simulated machine (STRATA_SNAPSHOT_WORLD names the world file), with the download replaced by a recorder (tests/snapshot/world.py)."""
5
6from __future__ import annotations
7
8import json
9import os
10import sys
11from pathlib import Path
12
13ROOT = Path(__file__).resolve().parents[2]
14sys.path.insert(0, str(ROOT))
15
16
17def main(argv: list[str]) -> int:
18    from tests.snapshot.driver import run_cli
19    from tests.snapshot.matrix import machine, model_set
20    from tests.snapshot.world import World
21    spec = json.loads(Path(os.environ["STRATA_SNAPSHOT_WORLD"]).read_text(encoding="utf-8"))
22    world = World(machine(spec["machine"]), model_set(spec["set"]), Path(spec["root"]))
23    with world.patched():
24        code, out, err = run_cli(argv)
25        log = Path(spec["root"]) / "shim-fetches.jsonl"
26        with log.open("a", encoding="utf-8") as f:
27            for item in world.fetches:
28                f.write(json.dumps(item) + "\n")
29    sys.stdout.write(out)
30    sys.stderr.write(err)
31    return code
32
33
34if __name__ == "__main__":
35    raise SystemExit(main(sys.argv[1:]))