aien-receipts
Append-only AIEN verification receipts, indexed by repository and exact source commit. Read verdicts, signatures and retained logs before making a claim.
Brought by drakestapleton
aien-receipts / tests / test_replay.py
| 1 | """Offline tests for tools/replay_receipt.py (DRA-167). |
| 2 | |
| 3 | Every test builds disposable Git repositories under a temporary directory and |
| 4 | serves them through file:// URLs, so the suite needs no network and never |
| 5 | touches the shelf in this checkout. Run from the repository root: |
| 6 | |
| 7 | python3 -m unittest discover -s tests -v |
| 8 | """ |
| 9 | import hashlib |
| 10 | import json |
| 11 | import os |
| 12 | import subprocess |
| 13 | import sys |
| 14 | import tempfile |
| 15 | import unittest |
| 16 | |
| 17 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 18 | TOOL = os.path.join(ROOT, "tools", "replay_receipt.py") |
| 19 | sys.path.insert(0, os.path.join(ROOT, "tools")) |
| 20 | import replay_receipt as rr # noqa: E402 |
| 21 | |
| 22 | GIT_ID = ["-c", "user.name=fixture", "-c", "user.email=fixture@example.invalid", "-c", "commit.gpgsign=false"] |
| 23 | |
| 24 | |
| 25 | def sha(b): |
| 26 | return hashlib.sha256(b).hexdigest() |
| 27 | |
| 28 | |
| 29 | def sh(*args, cwd=None, data=None): |
| 30 | return subprocess.run(args, cwd=cwd, check=True, capture_output=True, input=data).stdout |
| 31 | |
| 32 | |
| 33 | class Key: |
| 34 | def __init__(self, d, name): |
| 35 | self.pem = os.path.join(d, name + ".pem") |
| 36 | sh("openssl", "genpkey", "-algorithm", "ed25519", "-out", self.pem) |
| 37 | der = sh("openssl", "pkey", "-in", self.pem, "-pubout", "-outform", "DER") |
| 38 | self.pub = der[-32:].hex() |
| 39 | self.dir = d |
| 40 | |
| 41 | def sign(self, msg): |
| 42 | m, s = os.path.join(self.dir, "m.bin"), os.path.join(self.dir, "s.bin") |
| 43 | with open(m, "wb") as f: |
| 44 | f.write(msg) |
| 45 | sh("openssl", "pkeyutl", "-sign", "-inkey", self.pem, "-rawin", "-in", m, "-out", s) |
| 46 | with open(s, "rb") as f: |
| 47 | return f.read().hex() |
| 48 | |
| 49 | |
| 50 | class Remotes: |
| 51 | def __init__(self, root): |
| 52 | self.root = root |
| 53 | |
| 54 | def commit(self, name, files, msg="fixture"): |
| 55 | d = os.path.join(self.root, name) |
| 56 | if not os.path.isdir(d): |
| 57 | os.makedirs(d) |
| 58 | sh("git", "init", "-q", "-b", "main", cwd=d) |
| 59 | sh("git", "config", "uploadpack.allowFilter", "true", cwd=d) |
| 60 | sh("git", "config", "uploadpack.allowAnySHA1InWant", "true", cwd=d) |
| 61 | for path, data in files.items(): |
| 62 | p = os.path.join(d, path) |
| 63 | os.makedirs(os.path.dirname(p), exist_ok=True) |
| 64 | with open(p, "wb") as f: |
| 65 | f.write(data) |
| 66 | sh("git", "add", "-A", cwd=d) |
| 67 | sh("git", *GIT_ID, "commit", "-q", "--allow-empty", "-m", msg, cwd=d) |
| 68 | return sh("git", "rev-parse", "HEAD", cwd=d).decode().strip() |
| 69 | |
| 70 | |
| 71 | def bundle(key, repo, commit, checks, verdict, signer=None): |
| 72 | b = { |
| 73 | "schema": rr.BUNDLE_SCHEMA, "repository": "github.com/" + repo, "commit": commit, |
| 74 | "executor": {"class": "spark", "id": sha(bytes.fromhex(key.pub)), "machine_digest": "a" * 64}, |
| 75 | "tree_digest": "b" * 64, "graph_digest": "c" * 64, "receipt_id_scheme": "sha256-canonical-json", |
| 76 | "started_utc": "2026-11-06T00:00:00Z", "finished_utc": "2026-11-06T00:01:00Z", |
| 77 | "checks": [{"backend": "host", "check_id": "d" * 64, "exactness": "EXACT", "gate": g, "receipt": "e" * 64, |
| 78 | "required": True, "status": "run", "verdict": v} for g, v in checks], |
| 79 | "verdict": verdict, |
| 80 | } |
| 81 | signer = signer or key |
| 82 | b["signature"] = {"alg": "ed25519", "pubkey": signer.pub, "sig": signer.sign(rr.canonical(b))} |
| 83 | return b |
| 84 | |
| 85 | |
| 86 | def receipt(commit, **fields): |
| 87 | d = {"status": "QUALIFIED / PASS", "milestone": "MILESTONE T", "contract_id": "CONTRACT-T", "git_commit": commit, |
| 88 | "artifacts": {"build/omegatool": {"sha256": "0" * 64}, "src/a.c": {"sha256": sha(b"int a;\n")}}} |
| 89 | d.update(fields) |
| 90 | return json.dumps({k: v for k, v in d.items() if v is not None}, indent=2).encode() |
| 91 | |
| 92 | |
| 93 | def correction(path, digest, cid="T-1"): |
| 94 | return json.dumps({"schema": rr.CORRECTION_SCHEMA, "correction_id": cid, "recorded_on": "2026-11-06", |
| 95 | "corrects": {"repository": "aien-dev/omega-evidence", "path": path, "sha256": digest}, |
| 96 | "disposition": {"supersedes_historical_status_for_admission": True, |
| 97 | "qualification_claim": "REFUSED_UNSUPPORTED_PROVENANCE"}}).encode() |
| 98 | |
| 99 | |
| 100 | OMEGA_ISSUE = {"value": "Omega MILESTONE T qualification (CONTRACT-T)", |
| 101 | "basis": "receipt fields milestone and contract_id", "verified": True} |
| 102 | |
| 103 | |
| 104 | class ReplayTests(unittest.TestCase): |
| 105 | @classmethod |
| 106 | def setUpClass(cls): |
| 107 | cls.tmp = tempfile.TemporaryDirectory() |
| 108 | t = cls.tmp.name |
| 109 | cls.base = "file://" + os.path.join(t, "remotes") + "/" |
| 110 | cls.cache = os.path.join(t, "cache") |
| 111 | r = Remotes(os.path.join(t, "remotes")) |
| 112 | trusted, other = Key(t, "trusted"), Key(t, "other") |
| 113 | # Source repository: the base commit carries the trust anchor. |
| 114 | r.commit("aien-dev/demo", {".aien/verify.pub": (trusted.pub + "\n").encode(), |
| 115 | ".aien/always": b"# required\nG-ONE\n"}, "base") |
| 116 | c = [r.commit("aien-dev/demo", {"f": str(i).encode()}, f"c{i}") for i in range(6)] |
| 117 | good = bundle(trusted, "aien-dev/demo", c[0], [("G-ONE", "PASS"), ("G-TWO", "PASS")], "PASS") |
| 118 | fail = bundle(trusted, "aien-dev/demo", c[1], [("G-ONE", "FAIL")], "FAIL") |
| 119 | tampered = bundle(trusted, "aien-dev/demo", c[2], [("G-ONE", "FAIL")], "FAIL") |
| 120 | tampered["checks"][0]["verdict"], tampered["verdict"] = "PASS", "PASS" |
| 121 | alien = bundle(trusted, "aien-dev/demo", c[3], [("G-ONE", "PASS")], "PASS", signer=other) |
| 122 | missing = bundle(trusted, "aien-dev/demo", c[4], [("G-TWO", "PASS")], "PASS") |
| 123 | corrected = bundle(trusted, "aien-dev/demo", c[5], [("G-ONE", "PASS")], "PASS") |
| 124 | cls.good_bytes = rr.canonical(good) |
| 125 | cls.bundles = {} |
| 126 | files = {} |
| 127 | for name, b in (("good", good), ("fail", fail), ("tampered", tampered), ("alien", alien), |
| 128 | ("missing", missing), ("corrected", corrected)): |
| 129 | path = f"demo/{b['commit']}/bundle.json" |
| 130 | files[path] = rr.canonical(b) |
| 131 | cls.bundles[name] = path |
| 132 | files[f"demo/{c[5]}/bundle.correction.json"] = b"{}\n" |
| 133 | cls.shelf = r.commit("aien-dev/aien-receipts", files, "shelf") |
| 134 | # Omega receipts: source commits, then a shelf without and with corrections. |
| 135 | o1 = r.commit("aien-dev/omega-mv", {"src/a.c": b"int a;\n"}, "o1") |
| 136 | o2 = r.commit("aien-dev/omega-mv", {"src/a.c": b"int a2;\n"}, "o2") |
| 137 | cls.receipts = {"ok.json": receipt(o1), "mismatch.json": receipt(o2), "unresolved.json": receipt("f" * 40), |
| 138 | "unbound.json": receipt(o1), "nameless.json": receipt(o1, milestone=None, contract_id=None)} |
| 139 | cls.e1 = r.commit("aien-dev/omega-evidence", dict(cls.receipts), "receipts") |
| 140 | cls.e2 = r.commit("aien-dev/omega-evidence", { |
| 141 | "ok.correction.json": correction("ok.json", sha(cls.receipts["ok.json"])), |
| 142 | "unbound.correction.json": correction("unbound.json", "1" * 64)}, "corrections") |
| 143 | |
| 144 | @classmethod |
| 145 | def tearDownClass(cls): |
| 146 | cls.tmp.cleanup() |
| 147 | |
| 148 | def tool(self, *args, base=None, cache=None): |
| 149 | p = subprocess.run([sys.executable, TOOL, "--remote-base", base or self.base, "--cache", cache or self.cache, |
| 150 | *args], capture_output=True, text=True) |
| 151 | lines = p.stdout.strip().splitlines() |
| 152 | return p.returncode, (lines[-1] if lines else p.stderr.strip()), p.stdout |
| 153 | |
| 154 | def admit(self, eid, kind, repo, commit, path, source=None, issue=None, **where): |
| 155 | args = ["admit", "--kind", kind, "--shelf", f"{repo}@{commit}:{path}", "--id", eid] |
| 156 | if source: |
| 157 | args += ["--source-repo", source] |
| 158 | if issue is not None: |
| 159 | args += ["--issue-or-gate", issue] |
| 160 | rc, last, out = self.tool(*args, **where) |
| 161 | return rc, (json.loads(out) if rc == 0 else last) |
| 162 | |
| 163 | def index(self, *entries, **extra): |
| 164 | path = os.path.join(self.tmp.name, f"index-{len(os.listdir(self.tmp.name))}.json") |
| 165 | with open(path, "w") as f: |
| 166 | json.dump({"schema": rr.INDEX_SCHEMA, "index_version": 2, "entries": list(entries), **extra}, f) |
| 167 | return path |
| 168 | |
| 169 | def bundle_entry(self, name): |
| 170 | return self.admit(f"demo-{name}", "signed-bundle", "aien-dev/aien-receipts", self.shelf, self.bundles[name]) |
| 171 | |
| 172 | def omega_entry(self, path, shelf_commit, issue=None, **where): |
| 173 | return self.admit(f"omega-{path}", "omega-qualification-receipt", "aien-dev/omega-evidence", |
| 174 | shelf_commit, path, "aien-dev/omega-mv", issue, **where) |
| 175 | |
| 176 | # -- canonical encoder: golden cases from evidence.rs (aien-sovereign-core@c26f4d7a) |
| 177 | def test_canonical_sorts_keys_and_is_compact(self): |
| 178 | v = {"b": [1, True, None], "a": {"z": "x", "y": -3}} |
| 179 | self.assertEqual(rr.canonical(v), b'{"a":{"y":-3,"z":"x"},"b":[1,true,null]}') |
| 180 | |
| 181 | def test_canonical_escapes(self): |
| 182 | v = "a\"b\\c\nd\r\te\x1ff\x7f\xe9" |
| 183 | self.assertEqual(rr.canonical(v), '"a\\"b\\\\c\\nd\\r\\te\\u001ff\x7f\xe9"'.encode("utf-8")) |
| 184 | |
| 185 | def test_canonical_rejects_floats(self): |
| 186 | for v in ({"x": 1.5}, [0.0]): |
| 187 | with self.assertRaises(ValueError): |
| 188 | rr.canonical(v) |
| 189 | |
| 190 | def test_verdict_algebra(self): |
| 191 | self.assertEqual(rr.compute_verdict([("A", True, "run", "PASS"), ("B", False, "run", "FAIL")]), "PASS") |
| 192 | self.assertEqual(rr.compute_verdict([("A", True, "run", "PASS"), ("B", True, "run", "FAIL")]), "FAIL") |
| 193 | self.assertEqual(rr.compute_verdict([("A", True, "not_run", "NOT_RUN")]), "NOT_RUN") |
| 194 | |
| 195 | # -- signed bundles |
| 196 | def test_signed_pass_bundle_replays_pass(self): |
| 197 | rc, entry = self.bundle_entry("good") |
| 198 | self.assertEqual(rc, 0, entry) |
| 199 | self.assertEqual(set(entry), rr.ENTRY_FIELDS["signed-bundle"]) |
| 200 | self.assertEqual(entry["shelf"]["sha256"], sha(self.good_bytes)) |
| 201 | self.assertEqual(entry["issue_or_gate"], {"value": "aien-dev/demo required gates: G-ONE, G-TWO", |
| 202 | "basis": "bundle repository and the gate of every required check", |
| 203 | "verified": True}) |
| 204 | rc, last, out = self.tool("replay", "--index", self.index(entry), entry["id"]) |
| 205 | self.assertEqual((rc, last), (0, "REPLAY demo-good: PASS rc=0")) |
| 206 | self.assertIn("correction: none at the shelf commit or at shelf HEAD", out) |
| 207 | |
| 208 | def test_corrupted_copy_is_rejected(self): |
| 209 | rc, entry = self.bundle_entry("good") |
| 210 | corrupt = bytearray(self.good_bytes) |
| 211 | corrupt[corrupt.index(b'"verdict":"PASS"') + 11] ^= 0x01 |
| 212 | p = os.path.join(self.tmp.name, "corrupt.json") |
| 213 | with open(p, "wb") as f: |
| 214 | f.write(corrupt) |
| 215 | rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"], "--bytes", p) |
| 216 | self.assertEqual(rc, 3) |
| 217 | self.assertIn("REJECTED DIGEST_MISMATCH", last) |
| 218 | |
| 219 | def test_authenticated_fail_bundle_replays_fail(self): |
| 220 | rc, entry = self.bundle_entry("fail") |
| 221 | self.assertEqual(rc, 0, entry) |
| 222 | rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) |
| 223 | self.assertEqual((rc, last), (1, "REPLAY demo-fail: FAIL rc=1")) |
| 224 | |
| 225 | def test_tampered_bundle_bad_signature(self): |
| 226 | rc, last = self.bundle_entry("tampered") |
| 227 | self.assertEqual(rc, 3) |
| 228 | self.assertIn("BAD_SIGNATURE", last) |
| 229 | |
| 230 | def test_key_not_on_base_branch(self): |
| 231 | rc, last = self.bundle_entry("alien") |
| 232 | self.assertEqual(rc, 3) |
| 233 | self.assertIn("UNKNOWN_KEY", last) |
| 234 | |
| 235 | def test_missing_required_gate(self): |
| 236 | rc, last = self.bundle_entry("missing") |
| 237 | self.assertEqual(rc, 3) |
| 238 | self.assertIn("MISSING_REQUIRED_CHECK: G-ONE", last) |
| 239 | |
| 240 | def test_bundle_with_a_correction_file_is_rejected(self): |
| 241 | rc, last = self.bundle_entry("corrected") |
| 242 | self.assertEqual(rc, 3) |
| 243 | self.assertIn("CORRECTION_UNSUPPORTED", last) |
| 244 | |
| 245 | def test_kind_on_the_wrong_shelf_is_rejected(self): |
| 246 | rc, last = self.admit("x", "signed-bundle", "aien-dev/omega-evidence", self.e2, "ok.json") |
| 247 | self.assertEqual(rc, 3) |
| 248 | self.assertIn("SHELF_REPOSITORY", last) |
| 249 | |
| 250 | # -- omega receipts and correction precedence |
| 251 | def test_correction_supersedes_historical_pass(self): |
| 252 | self.assertEqual(sh("git", "-C", os.path.join(self.tmp.name, "remotes/aien-dev/omega-evidence"), |
| 253 | "show", f"{self.e2}:ok.json"), self.receipts["ok.json"]) |
| 254 | rc, entry = self.omega_entry("ok.json", self.e2) |
| 255 | self.assertEqual(rc, 0, entry) |
| 256 | self.assertEqual(set(entry), rr.ENTRY_FIELDS["omega-qualification-receipt"]) |
| 257 | self.assertEqual(entry["historical_verdict"], "QUALIFIED / PASS") |
| 258 | rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) |
| 259 | self.assertEqual((rc, last), (4, "REPLAY omega-ok.json: REFUSED_UNSUPPORTED_PROVENANCE rc=4")) |
| 260 | # The commit before the correction is not admissible while the HEAD carries one. |
| 261 | rc, last = self.omega_entry("ok.json", self.e1) |
| 262 | self.assertEqual(rc, 3) |
| 263 | self.assertIn(f"REJECTED STALE_CORRECTION: ok.correction.json at aien-dev/omega-evidence HEAD {self.e2}", last) |
| 264 | |
| 265 | def test_index_that_misses_a_correction_drifts(self): |
| 266 | rc, entry = self.omega_entry("ok.json", self.e2) |
| 267 | stale = json.loads(json.dumps(entry)) |
| 268 | stale["correction"] = None |
| 269 | stale["effective_verdict"] = "PASS" |
| 270 | rc, last, _ = self.tool("replay", "--index", self.index(stale), stale["id"]) |
| 271 | self.assertEqual(rc, 3) |
| 272 | self.assertIn("INDEX_DRIFT", last) |
| 273 | self.assertIn("correction", last) |
| 274 | |
| 275 | def test_correction_landing_after_the_indexed_commit_fails(self): |
| 276 | # The index stays on the old commit while a correction lands one commit later. |
| 277 | root = os.path.join(self.tmp.name, "late") |
| 278 | where = {"base": "file://" + root + "/", "cache": os.path.join(self.tmp.name, "late-cache")} |
| 279 | r = Remotes(root) |
| 280 | o1 = r.commit("aien-dev/omega-mv", {"src/a.c": b"int a;\n"}, "o1") |
| 281 | data = receipt(o1) |
| 282 | s1 = r.commit("aien-dev/omega-evidence", {"late.json": data}, "receipt") |
| 283 | rc, entry = self.omega_entry("late.json", s1, **where) |
| 284 | self.assertEqual(rc, 0, entry) |
| 285 | index = self.index(entry) |
| 286 | rc, last, out = self.tool("replay", "--index", index, entry["id"], **where) |
| 287 | self.assertEqual((rc, last), (0, "REPLAY omega-late.json: PASS rc=0"), out) # positive control |
| 288 | s2 = r.commit("aien-dev/omega-evidence", {"late.correction.json": correction("late.json", sha(data))}, "corr") |
| 289 | rc, last, _ = self.tool("replay", "--index", index, entry["id"], **where) |
| 290 | self.assertEqual(rc, 3, last) |
| 291 | self.assertIn(f"REJECTED STALE_CORRECTION: late.correction.json at aien-dev/omega-evidence HEAD {s2} " |
| 292 | f"has sha256", last) |
| 293 | rc, last, _ = self.tool("replay", "--all", "--index", index, **where) |
| 294 | self.assertEqual(rc, 3, last) |
| 295 | self.assertTrue(last.endswith("0/1 entries reproduce as indexed rc=3"), last) |
| 296 | # Re-admitted at the HEAD, the correction decides. |
| 297 | rc, fresh = self.omega_entry("late.json", s2, **where) |
| 298 | self.assertEqual(rc, 0, fresh) |
| 299 | self.assertEqual(fresh["effective_verdict"], "REFUSED_UNSUPPORTED_PROVENANCE") |
| 300 | # A correction rewritten after the pinned commit fails the same way. |
| 301 | r.commit("aien-dev/omega-evidence", {"late.correction.json": correction("late.json", sha(data), "T-2")}, "c2") |
| 302 | rc, last, _ = self.tool("replay", "--index", self.index(fresh), fresh["id"], **where) |
| 303 | self.assertEqual(rc, 3, last) |
| 304 | self.assertIn("STALE_CORRECTION", last) |
| 305 | |
| 306 | def test_unbound_correction_is_rejected(self): |
| 307 | rc, last = self.omega_entry("unbound.json", self.e2) |
| 308 | self.assertEqual(rc, 3) |
| 309 | self.assertIn("CORRECTION_UNBOUND", last) |
| 310 | |
| 311 | def test_source_mismatch_is_refused(self): |
| 312 | rc, entry = self.omega_entry("mismatch.json", self.e1) |
| 313 | self.assertEqual(rc, 0, entry) |
| 314 | self.assertEqual(entry["source"]["artifacts"][1]["at_source_commit"], "mismatch") |
| 315 | rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) |
| 316 | self.assertEqual((rc, last), (4, "REPLAY omega-mismatch.json: REFUSED_SOURCE_PROVENANCE rc=4")) |
| 317 | |
| 318 | def test_unresolved_source_commit_is_refused(self): |
| 319 | rc, entry = self.omega_entry("unresolved.json", self.e1) |
| 320 | self.assertEqual(rc, 0, entry) |
| 321 | self.assertFalse(entry["source"]["commit_resolves"]) |
| 322 | self.assertEqual(entry["effective_verdict"], "REFUSED_SOURCE_PROVENANCE") |
| 323 | |
| 324 | # -- issue_or_gate and unknown fields |
| 325 | def test_edited_issue_or_gate_fails(self): |
| 326 | rc, entry = self.omega_entry("mismatch.json", self.e1) |
| 327 | self.assertEqual(entry["issue_or_gate"], OMEGA_ISSUE) |
| 328 | for edit in ({"value": "hardware qualified on GB10"}, |
| 329 | {"basis": rr.UNVERIFIED_ISSUE_BASIS, "verified": False}): |
| 330 | edited = json.loads(json.dumps(entry)) |
| 331 | edited["issue_or_gate"].update(edit) |
| 332 | rc, last, _ = self.tool("replay", "--index", self.index(edited), edited["id"]) |
| 333 | self.assertEqual(rc, 3, last) |
| 334 | self.assertTrue(last.endswith("INDEX_DRIFT: recomputed fields differ from the index: issue_or_gate rc=3"), |
| 335 | last) |
| 336 | |
| 337 | def test_unknown_entry_field_fails(self): |
| 338 | rc, entry = self.bundle_entry("good") |
| 339 | entry["qualification"] = "hardware qualified on GB10" |
| 340 | rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) |
| 341 | self.assertEqual(rc, 3, last) |
| 342 | self.assertIn("REJECTED UNKNOWN_FIELD", last) |
| 343 | self.assertIn("qualification", last) |
| 344 | |
| 345 | def test_unknown_index_field_fails(self): |
| 346 | rc, entry = self.bundle_entry("good") |
| 347 | rc, last, _ = self.tool("replay", "--all", "--index", self.index(entry, hardware="qualified on GB10")) |
| 348 | self.assertEqual(rc, 3, last) |
| 349 | self.assertIn("REJECTED", last) |
| 350 | self.assertIn("UNKNOWN_FIELD", last) |
| 351 | |
| 352 | def test_edited_replay_command_fails(self): |
| 353 | rc, entry = self.bundle_entry("good") |
| 354 | entry["replay"] = "true" |
| 355 | rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) |
| 356 | self.assertEqual(rc, 3, last) |
| 357 | self.assertIn("INDEX_DRIFT", last) |
| 358 | |
| 359 | def test_issue_not_in_receipt_is_marked_unverified(self): |
| 360 | rc, last = self.omega_entry("nameless.json", self.e2) |
| 361 | self.assertEqual(rc, 3) |
| 362 | self.assertIn("names no issue or gate", last) |
| 363 | rc, entry = self.omega_entry("nameless.json", self.e2, issue="DRA-0 test gate") |
| 364 | self.assertEqual(rc, 0, entry) |
| 365 | self.assertEqual(entry["issue_or_gate"], {"value": "DRA-0 test gate", "basis": rr.UNVERIFIED_ISSUE_BASIS, |
| 366 | "verified": False}) |
| 367 | rc, last, out = self.tool("replay", "--index", self.index(entry), entry["id"]) |
| 368 | self.assertEqual((rc, last), (0, "REPLAY omega-nameless.json: PASS rc=0 issue_or_gate=UNVERIFIED")) |
| 369 | self.assertIn("issue_or_gate: UNVERIFIED", out) |
| 370 | # A receipt that names its own issue does not take operator text. |
| 371 | rc, last = self.omega_entry("ok.json", self.e2, issue="DRA-0 test gate") |
| 372 | self.assertEqual(rc, 2) |
| 373 | self.assertIn("drop the option", last) |
| 374 | |
| 375 | # -- whole index and unreachable inputs |
| 376 | def test_replay_all(self): |
| 377 | entries = [self.bundle_entry("good")[1], self.bundle_entry("fail")[1], self.omega_entry("ok.json", self.e2)[1]] |
| 378 | rc, last, _ = self.tool("replay", "--all", "--index", self.index(*entries)) |
| 379 | self.assertEqual(rc, 0, last) |
| 380 | self.assertTrue(last.endswith("3/3 entries reproduce as indexed rc=0"), last) |
| 381 | |
| 382 | def test_unreachable_remote_is_not_run(self): |
| 383 | rc, entry = self.bundle_entry("good") |
| 384 | rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"], |
| 385 | base="file://" + os.path.join(self.tmp.name, "nowhere") + "/") |
| 386 | self.assertEqual(rc, 2) |
| 387 | self.assertIn("NOT_RUN cannot reach", last) |
| 388 | |
| 389 | |
| 390 | class ShippedIndexTests(unittest.TestCase): |
| 391 | """Structure of index/receipt_index.json; replaying it needs the network (docs/receipt-index.md).""" |
| 392 | |
| 393 | def test_shipped_index_shape(self): |
| 394 | idx = rr.load_index(rr.DEFAULT_INDEX) |
| 395 | self.assertEqual(idx["index_version"], 2) |
| 396 | for e in idx["entries"]: |
| 397 | self.assertEqual(set(e), rr.ENTRY_FIELDS[e["kind"]]) |
| 398 | self.assertNotIn(":", e["id"]) |
| 399 | self.assertEqual(e["shelf"]["repository"], rr.SHELF_REPOS[e["kind"]]) |
| 400 | self.assertEqual(e["replay"], rr.replay_command(e["id"])) |
| 401 | self.assertTrue(rr.is_hex(e["shelf"]["sha256"], 64) and rr.is_hex(e["shelf"]["commit"], 40)) |
| 402 | self.assertTrue(e["issue_or_gate"]["verified"], e["id"]) |
| 403 | self.assertIn(rr.exit_for(e["effective_verdict"]), (0, 1, 4)) |
| 404 | c = e["correction"] |
| 405 | if c and c["supersedes_historical_status_for_admission"]: |
| 406 | self.assertEqual(e["effective_verdict"], c["qualification_claim"]) |
| 407 | |
| 408 | def test_shipped_index_refuses_m8_and_m9(self): |
| 409 | idx = rr.load_index(rr.DEFAULT_INDEX) |
| 410 | by_id = {e["id"]: e for e in idx["entries"]} |
| 411 | for m in ("omega-evidence/M8", "omega-evidence/M9"): |
| 412 | self.assertEqual(by_id[m]["historical_verdict"], "QUALIFIED / PASS") |
| 413 | self.assertEqual(by_id[m]["effective_verdict"], "REFUSED_UNSUPPORTED_PROVENANCE") |
| 414 | |
| 415 | def test_shipped_m4_issue_comes_from_the_receipt(self): |
| 416 | by_id = {e["id"]: e for e in rr.load_index(rr.DEFAULT_INDEX)["entries"]} |
| 417 | self.assertEqual(by_id["omega-evidence/M4"]["issue_or_gate"]["value"], |
| 418 | "Omega MILESTONE 4 — OMEGA_SEMANTICS qualification (CONTRACT-OMEGA-SEMANTICS-M4)") |
| 419 | |
| 420 | |
| 421 | if __name__ == "__main__": |
| 422 | unittest.main() |