"""Live pilot admission preparation (NK-WP-0056-T06).""" from __future__ import annotations import datetime as dt import hashlib import importlib.util import json import pathlib import subprocess import sys import tempfile import unittest HERE = pathlib.Path(__file__).resolve().parent spec = importlib.util.spec_from_file_location("prepare_admission", HERE.parent / "prepare_admission.py") P = importlib.util.module_from_spec(spec) sys.modules["prepare_admission"] = P spec.loader.exec_module(P) START = dt.datetime(2026, 11, 5, 9, 0, tzinfo=dt.UTC) @unittest.skipUnless((P.REPO / ".git").exists(), "needs a git checkout (CI tests a source tarball)") class Prepare(unittest.TestCase): def setUp(self): self.commit = subprocess.run(["git", "-C", str(P.REPO), "rev-parse", "HEAD"], capture_output=True, text=True, check=True).stdout.strip() def test_pins_the_commits_content_and_is_valid(self): doc = P.prepare("BEA-2026-0099", self.commit, START, 2) spec = doc["spec"] self.assertEqual(spec["window"], {"not_before": "2026-11-05T09:00:00Z", "not_after": "2026-11-05T11:00:00Z"}) self.assertEqual(spec["plan"]["source"]["commit"], self.commit[:12]) for f in spec["plan"]["source"]["files"]: blob = subprocess.run(["git", "-C", str(P.REPO), "show", f"{self.commit}:{f['path']}"], capture_output=True, check=True).stdout self.assertEqual(f["sha256"], hashlib.sha256(blob).hexdigest()) report = P.bea.evaluate(doc, json.loads(P.bea.SCHEMA.read_text()), as_of=START) self.assertTrue(report["valid"], report["findings"]) def test_refusals(self): with tempfile.TemporaryDirectory() as tmp: out = pathlib.Path(tmp) / "a.yaml" out.write_text("exists") with self.assertRaises(SystemExit): P.main(["--id", "BEA-2026-0099", "--commit", self.commit, "--not-before", "2026-11-05T09:00:00Z", "--out", str(out)]) with self.assertRaises(SystemExit): P.main(["--id", "BEA-2026-0099", "--commit", self.commit, "--not-before", "2026-11-05T09:00:00Z", "--hours", "3", "--out", str(pathlib.Path(tmp) / "b.yaml")]) self.assertEqual(P.main(["--id", "BEA-2026-0099", "--commit", "0" * 40, "--not-before", "2026-11-05T09:00:00Z", "--out", str(pathlib.Path(tmp) / "c.yaml")]), 4) if __name__ == "__main__": unittest.main()