interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / tests / omegese45 / eval / test_eval.py

480 lines · 25973 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Eval-lane self-tests (aien-train #45). Python standard library only.
3
41. Spec cases: episodes typed by hand from interface v1.1 section 3 must equal
5 the eval generator's output and pass the audit; hand-written violations of
6 the reference policy, grammar and codec must be rejected.
72. Sealed-generator determinism (same seed -> same bytes).
83. P-256 and layout readers against the REAL Rust-signed baseline artifacts
9 (aien-protocols e705fdc9 evidence/aienet0-20261028/exercised/artifacts),
10 including an independent matmul_u32 recompute of the stored digest.
114. check-demo end to end on synthetic case dirs, and its negative controls:
12 tampered receipt byte, tampered output digest, edited English number,
13 wrong English reason, unbound dispatch.
14Prints one `T <name> PASS|FAIL` line per test and `OE45_EVAL_TESTS PASS|FAIL`.
15"""
16
17import hashlib
18import os
19import shutil
20import subprocess
21import sys
22import tempfile
23
24HERE = os.path.dirname(os.path.abspath(__file__))
25ROOT = os.path.abspath(os.path.join(HERE, "..", "..", ".."))
26EVAL = os.environ.get("OE45_EVAL_DIR") or os.path.join(ROOT, "eval", "omegese45") # mutants override
27sys.path.insert(0, EVAL)
28sys.path.insert(0, HERE)
29
30import oe45lib as L # noqa: E402
31import oe_an0 as A # noqa: E402
32import oe_audit # noqa: E402
33import oe_en # noqa: E402
34import oe_sealgen # noqa: E402
35import mkcase # noqa: E402
36import oe_episode as EP # noqa: E402
37
38FAILS = []
39
40
41def t(name, cond, detail=""):
42 print("T %s %s %s" % (name, "PASS" if cond else "FAIL", detail))
43 if not cond:
44 FAILS.append(name)
45
46
47T_ = ("fail", "transport")
48OK = ("ok", None)
49
50# --------------------------------------------------------------- 1. spec cases
51# Typed by hand from interface v1.1 section 3; not produced by any fmt_ helper.
52SPEC = [
53 ("mm_ok", "mm", (0x40, 0x40, 0x40), (0x1234,), [[OK]], [
54 "goal mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end",
55 "act job mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end",
56 "res ok end",
57 "rep ok mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end"]),
58 ("mm_edge_0x100_admitted", "mm", (0x100, 0x001, 0x100), (0xffff,), [[OK]], [
59 "goal mm ushort 0x100 ushort 0x001 ushort 0x100 ulong 0xffff end",
60 "act job mm ushort 0x100 ushort 0x001 ushort 0x100 ulong 0xffff end",
61 "res ok end",
62 "rep ok mm ushort 0x100 ushort 0x001 ushort 0x100 ulong 0xffff end"]),
63 ("mm_bound_0x101", "mm", (0x101, 0x004, 0x004), (0x0007,), [], [
64 "goal mm ushort 0x101 ushort 0x004 ushort 0x004 ulong 0x0007 end",
65 "act refuse bound end",
66 "rep refused bound end"]),
67 ("pair_bound_0x000", "pair", (0x004, 0x000, 0x004), (0x0001, 0x0002), [], [
68 "goal pair ushort 0x004 ushort 0x000 ushort 0x004 ulong 0x0001 ulong 0x0002 end",
69 "act refuse bound end",
70 "rep refused bound end"]),
71 ("mm_replay", "mm", (0x002, 0x003, 0x004), (0x00aa,), [[("refused", "replay")]], [
72 "goal mm ushort 0x002 ushort 0x003 ushort 0x004 ulong 0x00aa end",
73 "act job mm ushort 0x002 ushort 0x003 ushort 0x004 ulong 0x00aa end",
74 "res refused replay end",
75 "rep refused replay end"]),
76 ("mm_transport_then_verdict", "mm", (0x010, 0x020, 0x030), (0x0bad,), [[T_, ("fail", "verdict")]], [
77 "goal mm ushort 0x010 ushort 0x020 ushort 0x030 ulong 0x0bad end",
78 "act job mm ushort 0x010 ushort 0x020 ushort 0x030 ulong 0x0bad end",
79 "res fail transport end",
80 "act job mm ushort 0x010 ushort 0x020 ushort 0x030 ulong 0x0bad end",
81 "res fail verdict end",
82 "rep fail verdict end"]),
83 ("pair_ok_then_transport2", "pair", (0x008, 0x008, 0x008), (0x0001, 0x0002), [[OK], [T_, T_]], [
84 "goal pair ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0001 ulong 0x0002 end",
85 "act job mm ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0001 end",
86 "res ok end",
87 "act job mm ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0002 end",
88 "res fail transport end",
89 "act job mm ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0002 end",
90 "res fail transport end",
91 "rep fail transport end"]),
92 ("pair_budget_after_retry", "pair", (0x00c, 0x00d, 0x00e), (0x0100, 0x0200), [[T_, ("refused", "budget")]], [
93 "goal pair ushort 0x00c ushort 0x00d ushort 0x00e ulong 0x0100 ulong 0x0200 end",
94 "act job mm ushort 0x00c ushort 0x00d ushort 0x00e ulong 0x0100 end",
95 "res fail transport end",
96 "act job mm ushort 0x00c ushort 0x00d ushort 0x00e ulong 0x0100 end",
97 "res refused budget end",
98 "rep refused budget end"]),
99 ("pair_max_175", "pair", (0x0ff, 0x0ff, 0x0ff), (0xbeef, 0xcafe), [[T_, OK], [T_, OK]], [
100 "goal pair ushort 0x0ff ushort 0x0ff ushort 0x0ff ulong 0xbeef ulong 0xcafe end",
101 "act job mm ushort 0x0ff ushort 0x0ff ushort 0x0ff ulong 0xbeef end",
102 "res fail transport end",
103 "act job mm ushort 0x0ff ushort 0x0ff ushort 0x0ff ulong 0xbeef end",
104 "res ok end",
105 "act job mm ushort 0x0ff ushort 0x0ff ushort 0x0ff ulong 0xcafe end",
106 "res fail transport end",
107 "act job mm ushort 0x0ff ushort 0x0ff ushort 0x0ff ulong 0xcafe end",
108 "res ok end",
109 "rep ok pair ushort 0x0ff ushort 0x0ff ushort 0x0ff ulong 0xbeef ulong 0xcafe end"]),
110]
111
112# Hand-written violations: (name, lines) each must fail the audit.
113G1 = "goal mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end"
114A1 = "act job mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end"
115GP = "goal pair ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0001 ulong 0x0002 end"
116AP1 = "act job mm ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0001 end"
117AP2 = "act job mm ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0002 end"
118BAD = [
119 ("no_retry_after_first_transport", [G1, A1, "res fail transport end", "rep fail transport end"]),
120 ("third_attempt", [G1, A1, "res fail transport end", A1, "res fail transport end", A1, "res ok end",
121 "rep ok mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end"]),
122 ("pair_job2_wrong_seed", [GP, AP1, "res ok end", AP1, "res ok end",
123 "rep ok pair ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0001 ulong 0x0002 end"]),
124 ("refuse_admitted_0x100", ["goal mm ushort 0x100 ushort 0x004 ushort 0x004 ulong 0x0001 end",
125 "act refuse bound end", "rep refused bound end"]),
126 ("dispatch_0x101", ["goal mm ushort 0x101 ushort 0x004 ushort 0x004 ulong 0x0001 end",
127 "act job mm ushort 0x101 ushort 0x004 ushort 0x004 ulong 0x0001 end", "res ok end",
128 "rep ok mm ushort 0x101 ushort 0x004 ushort 0x004 ulong 0x0001 end"]),
129 ("report_wrong_code", [G1, A1, "res refused budget end", "rep refused worker end"]),
130 ("report_wrong_class", [G1, A1, "res fail io end", "rep refused io end"]),
131 ("rep_ok_wrong_seed", [G1, A1, "res ok end",
132 "rep ok mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1235 end"]),
133 ("res_after_refuse", ["goal mm ushort 0x101 ushort 0x004 ushort 0x004 ulong 0x0001 end",
134 "act refuse bound end", "res ok end", "rep refused bound end"]),
135 ("res_bound_runtime", [G1, A1, "res refused bound end", "rep refused bound end"]),
136 ("missing_report", [G1, A1, "res ok end"]),
137]
138BAD_SURFACE = ["goal mm ushort 0X040 ushort 0x040 ushort 0x040 ulong 0x1234 end",
139 "goal mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end",
140 "Goal mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end",
141 "goal mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234",
142 "goal mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234 end end",
143 "goal mm ushort 0x40 ushort 0x040 ushort 0x040 ulong 0x1234 end",
144 "goal mm ushort 0x040\tushort 0x040 ushort 0x040 ulong 0x1234 end",
145 "res ok end\r", ""]
146
147
148def spec_tests():
149 for name, kind, dims, seeds, script, lines in SPEC:
150 got = oe_sealgen.build_episode(kind, dims, seeds, script)
151 t("spec.%s.generator" % name, got == lines, "" if got == lines else repr(got))
152 ok, why, info = oe_audit.audit_one(lines)
153 t("spec.%s.audit" % name, ok, why)
154 n = L.episode_ids_len(SPEC[-1][5])
155 t("spec.maxlen_episode_is_175_ids", n == 175, "ids=%d" % n)
156 for name, lines in BAD:
157 ok, why, _ = oe_audit.audit_one(lines)
158 t("neg.%s.rejected" % name, not ok, why)
159 for s in BAD_SURFACE:
160 try:
161 L.parse_line(s)
162 rejected = False
163 except ValueError: # CodecError is a ValueError; grammar errors too
164 rejected = True
165 t("neg.surface.%r" % s[:24], rejected)
166 # Exercise the exact v1.3 wrapper called by check-demo, independently of policy.
167 for name, lines in [
168 ("refuse_then_job", [G1, L.ACT_REFUSE, A1, "res ok end", "rep refused bound end"]),
169 ("refuse_after_result", [G1, A1, "res ok end", L.ACT_REFUSE, "rep refused bound end"]),
170 ("P_directly_after_G", [G1, "rep refused bound end"])]:
171 why = EP.check_episode_shape([L.parse_line(l) for l in lines])
172 t("shape.%s" % name, why is not None, why or "")
173
174
175def contract_vocab_test(path):
176 path = path or os.path.join(ROOT, "docs", "omegese45", "vocab.tsv")
177 if not os.path.isfile(path):
178 t("contract.vocab_tsv_present", False, path)
179 return
180 rows = open(path, newline="").read().split("\n")
181 words = [r.split("\t")[1] for r in rows if r]
182 ids = [int(r.split("\t")[0]) for r in rows if r]
183 t("contract.vocab_tsv_matches_eval_vocab", ids == list(range(41)) and words == L.VOCAB,
184 "sha256=%s" % hashlib.sha256(open(path, "rb").read()).hexdigest())
185
186
187# ------------------------------------------------------- 2. sealgen determinism
188def sealgen_tests(tmp):
189 seed = os.path.join(tmp, "seed.hex")
190 open(seed, "w").write("00" * 31 + "01\n")
191 outs = []
192 for i in range(2):
193 o = os.path.join(tmp, "s%d" % i)
194 subprocess.run([sys.executable, os.path.join(EVAL, "oe_sealgen.py"), seed, o], check=True,
195 stdout=subprocess.DEVNULL)
196 outs.append(open(o, "rb").read())
197 t("sealgen.deterministic", outs[0] == outs[1], hashlib.sha256(outs[0]).hexdigest())
198 r = subprocess.run([sys.executable, os.path.join(EVAL, "oe_audit.py"), "bundle", os.path.join(tmp, "s0")],
199 capture_output=True, text=True)
200 t("sealgen.audit_pass", r.returncode == 0 and "AUDIT PASS" in r.stdout, r.stdout.strip().splitlines()[-1])
201
202
203# ----------------------------------------------------- 3. real artifacts
204BASE = os.path.join(HERE, "fixtures", "baseline")
205DAG = "aadc3775d32303b9e697c1c092b5628e9333f012a2ac4c1390f04da113c494cb"
206
207
208def keyfile(name):
209 return {l.split()[0]: bytes.fromhex(l.split()[1]) for l in open(os.path.join(BASE, name)) if l.strip()}
210
211
212def real_artifact_tests():
213 sk, mk = keyfile("spark-public-keys.txt"), keyfile("macbook-public-keys.txt")
214 keys = (sk["submitter.p256"], mk["executor.p256"], sk["verifier.p256"])
215 rd = lambda e: open(os.path.join(BASE, DAG + e), "rb").read()
216 an0b, mjr1, mjv = rd(".an0b"), rd(".mjr1"), rd(".mjv")
217 t("p256.curve_self_test", A.curve_self_test())
218 res, job = A.check_triple(an0b, mjr1, mjv, *keys)
219 fails = [r for r in res if r[1] != "PASS"]
220 t("real.baseline_all_pass", not fails and job == (64, 64, 64, 2716205057), repr(fails))
221 t("real.mjr1_sha256", A.sha(mjr1).hex() == "3306d180de1885a2759b324618d11eca523ef4d7aa22c4144813d71187014855")
222 status = lambda rs, name: [s for n, s, _ in rs if n == name]
223 # negative controls on real bytes
224 flip = bytearray(mjr1)
225 flip[100] ^= 1
226 res, _ = A.check_triple(an0b, bytes(flip), mjv, *keys)
227 t("real.neg.receipt_byte_flip", status(res, "mjr1.signature") == ["FAIL"])
228 flip = bytearray(mjr1)
229 flip[150] ^= 1
230 res, _ = A.check_triple(an0b, bytes(flip), mjv, *keys)
231 t("real.neg.output_digest_flip", status(res, "recompute.output_digest") == ["FAIL"]
232 and status(res, "mjr1.signature") == ["FAIL"])
233 hs = bytearray(mjr1)
234 s = int.from_bytes(mjr1[372:404], "big")
235 hs[372:404] = (A.N - s).to_bytes(32, "big")
236 ok, why = A.verify_low_s(mjr1[304:337], mjr1[:340], bytes(hs[340:404]))
237 t("real.neg.high_s_refused", not ok and why == "high-S signature", why)
238 t("real.crosscheck_high_s_valid_ecdsa", A.crypto_crosscheck(mjr1[304:337], mjr1[:340], bytes(hs[340:404])) in (True, None))
239 ok, _ = A.verify_low_s(keys[2], A.VERIFY_DOMAIN + mjv[:172], mjv[172:236])
240 t("real.an0v_signature", ok)
241 res, _ = A.check_triple(an0b, mjr1, mjv, keys[0], keys[2], keys[2])
242 t("real.neg.wrong_executor_pin", status(res, "mjr1.executor_pin") == ["FAIL"])
243 t("matmul.distinct_seed_changes_digest",
244 A.matmul_u32_digest(64, 64, 64, 2716205058) != mjr1[144:176])
245
246
247# ----------------------------------------------------- 4. check-demo
248CHECK = os.path.join(EVAL, "check-demo")
249
250
251def run_check(case):
252 r = subprocess.run([sys.executable, os.path.join(HERE, "check_fixture.py"), CHECK, case],
253 capture_output=True, text=True)
254 return r.returncode, r.stdout
255
256
257def mm_case(path, forge_output=False):
258 lines = SPEC[0][5]
259 mkcase.write_case(path, lines, (0x40, 0x40, 0x40), (0x1234,), [(1, 1, "ok", None)],
260 forge_output=forge_output)
261 rows = open(os.path.join(path, "facts.tsv")).read().splitlines()[1].split("\t")
262 eng = ("Completed and verified: one matmul_u32 job multiplying a 64 by 64 matrix by a 64 by 64 matrix "
263 "with seed 4660; job 1 dag_id %s mjr1_sha256 %s.\n" % (rows[9], rows[10]))
264 open(os.path.join(path, "response.en"), "w").write(eng)
265 return eng
266
267
268def checkdemo_tests(tmp):
269 happy = os.path.join(tmp, "happy-mm")
270 eng = mm_case(happy)
271 rc, out = run_check(happy)
272 t("checkdemo.happy_mm", rc == 0 and out.endswith("FAITHFUL\n"), out.splitlines()[-1])
273
274 pair = os.path.join(tmp, "happy-pair")
275 lines = SPEC[8][5]
276 mkcase.write_case(pair, lines, (0xff,) * 3, (0xbeef, 0xcafe),
277 [(1, 1, "fail", "transport"), (1, 2, "ok", None), (2, 1, "fail", "transport"), (2, 2, "ok", None)])
278 rows = [r.split("\t") for r in open(os.path.join(pair, "facts.tsv")).read().splitlines()[1:]]
279 open(os.path.join(pair, "response.en"), "w").write(
280 "Completed and verified: two matmul_u32 jobs, each multiplying a 255 by 255 matrix by a 255 by 255 matrix, "
281 "with seeds 48879 and 51966; job 1 dag_id %s mjr1_sha256 %s; job 2 dag_id %s mjr1_sha256 %s.\n"
282 % (rows[1][9], rows[1][10], rows[3][9], rows[3][10]))
283 rc, out = run_check(pair)
284 t("checkdemo.pair_with_retries", rc == 0, out.splitlines()[-1])
285
286 bound = os.path.join(tmp, "bound")
287 mkcase.write_case(bound, SPEC[2][5], (0x101, 4, 4), (7,), [],
288 response="Not completed: refused before dispatch (code bound): the goal asks for a 257 by 4 by 4 "
289 "matmul and a dimension is outside the admitted range 1 to 256; nothing was dispatched.\n")
290 rc, out = run_check(bound)
291 t("checkdemo.bound", rc == 0, out.splitlines()[-1])
292
293 stop = os.path.join(tmp, "replay")
294 mkcase.write_case(stop, SPEC[4][5], (2, 3, 4), (0xaa,), [(1, 1, "refused", "replay")],
295 response="Not completed: job 1 was refused (code replay): the worker refused a replay of an "
296 "already executed job.\n")
297 rc, out = run_check(stop)
298 t("checkdemo.replay", rc == 0, out.splitlines()[-1])
299
300 tr = os.path.join(tmp, "translator-refusal")
301 os.makedirs(os.path.join(tr, "artifacts"))
302 open(os.path.join(tr, "facts.tsv"), "w").write(mkcase.HEADER + "\n")
303 open(os.path.join(tr, "request.en"), "w").write("please sort my files\n")
304 rc, out = run_check(tr)
305 t("checkdemo.translator_refusal", rc == 0, out.splitlines()[-1])
306
307 def neg(name, mutate, expect):
308 d = os.path.join(tmp, "neg-" + name)
309 shutil.copytree(happy, d)
310 mutate(d)
311 rc, out = run_check(d)
312 last = out.splitlines()[-1] if out else ""
313 t("checkdemo.neg.%s" % name, rc == 1 and last.startswith("UNFAITHFUL") and expect in out, last)
314
315 def art(d, ext):
316 a = os.path.join(d, "artifacts")
317 return os.path.join(a, [f for f in os.listdir(a) if f.endswith(ext)][0])
318
319 def flip(path, off):
320 b = bytearray(open(path, "rb").read())
321 b[off] ^= 1
322 open(path, "wb").write(bytes(b))
323
324 neg("receipt_byte", lambda d: flip(art(d, ".mjr1"), 90), "mjr1.signature FAIL")
325 # Re-signed forgery: the worker's digest is wrong by one bit, but receipt, verdict
326 # commitment, countersignature, facts.tsv and the English sha are all consistent
327 # and validly signed. The ONLY failing check may be the independent recompute.
328 forged = os.path.join(tmp, "neg-output_digest_resigned")
329 feng = mm_case(forged, forge_output=True)
330 rc, out = run_check(forged)
331 failed = [l.split()[1] for l in out.splitlines() if l.startswith("CHECK ") and l.split()[2] == "FAIL"]
332 t("checkdemo.neg.output_digest_resigned", rc == 1 and failed == ["row1.recompute.output_digest"]
333 and out.splitlines()[-1].startswith("UNFAITHFUL row1.recompute.output_digest"), "failed=%r" % failed)
334 t("checkdemo.forged_differs_from_honest_only_downstream_of_digest",
335 feng != eng and feng.split("dag_id ")[1][:64] == eng.split("dag_id ")[1][:64])
336 neg("missing_response", lambda d: os.remove(os.path.join(d, "response.en")), "english.present FAIL")
337 neg("english_number", lambda d: open(os.path.join(d, "response.en"), "w").write(
338 eng.replace("with seed 4660", "with seed 4661")), "english.seeds FAIL")
339 neg("english_dim", lambda d: open(os.path.join(d, "response.en"), "w").write(
340 eng.replace("a 64 by 64 matrix by", "a 65 by 64 matrix by")), "english.dims FAIL")
341 neg("english_unparsed", lambda d: open(os.path.join(d, "response.en"), "w").write(
342 eng.replace("Completed and verified", "Completed")), "english.parse FAIL")
343 neg("countersign_byte", lambda d: flip(art(d, ".mjv"), 200), "an0v.signature FAIL")
344
345 def wrong_seed_row(d):
346 p = os.path.join(d, "facts.tsv")
347 s = open(p).read().replace("\t4660\t", "\t4661\t")
348 open(p, "w").write(s)
349 neg("facts_seed", wrong_seed_row, "binds_goal FAIL")
350
351 def unbound(d):
352 p = os.path.join(d, "episode.oe45")
353 s = open(p).read().replace("act job mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1234",
354 "act job mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x1235")
355 open(p, "w").write(s)
356 neg("unbound_action", unbound, "episode.binding FAIL")
357
358 def wrong_reason(d):
359 mkcase.write_case(d, SPEC[4][5], (2, 3, 4), (0xaa,), [(1, 1, "refused", "replay")],
360 response="Not completed: job 1 was refused (code replay): the worker refused the job.\n")
361 for f in os.listdir(os.path.join(d, "artifacts")):
362 os.remove(os.path.join(d, "artifacts", f))
363 neg("english_reason", wrong_reason, "english.reason FAIL")
364
365 # interface v1.2 facts.tsv rules
366 def set_field(d, rowno, col, value, append_copy=False):
367 p = os.path.join(d, "facts.tsv")
368 lines = open(p).read().splitlines()
369 f = lines[rowno].split("\t")
370 f[mkcase.HEADER.split("\t").index(col)] = value
371 if append_copy:
372 lines.append("\t".join(f))
373 else:
374 lines[rowno] = "\t".join(f)
375 open(p, "w").write("\n".join(lines) + "\n")
376
377 def replay_case(d):
378 mkcase.write_case(d, SPEC[4][5], (2, 3, 4), (0xaa,), [(1, 1, "refused", "replay")],
379 response="Not completed: job 1 was refused (code replay): the worker refused a replay "
380 "of an already executed job.\n")
381
382 neg("facts_outcome_not_1", lambda d: set_field(d, 1, "mjr1_outcome", "2"), "row1.facts_format FAIL")
383 neg("facts_verifier_uppercase", lambda d: set_field(d, 1, "verifier", open(
384 os.path.join(d, "facts.tsv")).read().splitlines()[1].split("\t")[12].upper()), "row1.facts_format FAIL")
385 neg("facts_verifier_not_compressed", lambda d: set_field(d, 1, "verifier", "04" + "ab" * 32),
386 "row1.facts_format FAIL")
387 neg("facts_row_after_ok", lambda d: set_field(d, 1, "attempt", "2", append_copy=True),
388 "facts.no_row_after_ok FAIL")
389 neg("facts_attempt_3", lambda d: set_field(d, 1, "attempt", "3"), "row1.facts_format FAIL")
390 neg("facts_exit_map", lambda d: (replay_case(d), set_field(d, 1, "exit", "12")), "row1.facts_format FAIL")
391 neg("facts_nonok_receipt_field", lambda d: (replay_case(d), set_field(d, 1, "verifier", "02" + "ab" * 32)),
392 "row1.facts_format FAIL")
393 # parent ruling on v1.2: a non-ok row may carry the real dag_id ('-' or 64 lowercase hex)
394 DEMO_DAG = "32d3147d8786f0f3be217de5dbd512191229f7dd80e89f4d9bc92f0200b97fca" # demo replay row
395 pos = os.path.join(tmp, "replay-with-dag")
396 replay_case(pos)
397 rc, out = run_check(pos)
398 t("checkdemo.nonok_row_with_dag_id_accepted", rc == 0 and out.endswith("FAITHFUL\n"), out.splitlines()[-1])
399 neg("facts_nonok_dag_nonhex", lambda d: (replay_case(d), set_field(d, 1, "dag_id", "g" + DEMO_DAG[1:])),
400 "row1.facts_format FAIL non-ok row dag_id")
401 neg("facts_nonok_dag_short", lambda d: (replay_case(d), set_field(d, 1, "dag_id", DEMO_DAG[:63])),
402 "row1.facts_format FAIL non-ok row dag_id")
403 neg("facts_nonok_dag_upper", lambda d: (replay_case(d), set_field(d, 1, "dag_id", DEMO_DAG.upper())),
404 "row1.facts_format FAIL non-ok row dag_id")
405 neg("facts_nonok_mjr1_without_receipt",
406 lambda d: (replay_case(d), set_field(d, 1, "dag_id", DEMO_DAG), set_field(d, 1, "mjr1_sha256", "ab" * 32)),
407 "row1.nonok_receipt_file FAIL")
408 # Real entry point, including its shape wrapper and terminal-binding guard.
409 def episode(d, lines):
410 open(os.path.join(d, "episode.oe45"), "w").write("oe45 v1\n" + "\n".join(lines) + "\n")
411 neg("refuse_then_job", lambda d: episode(d, [G1, L.ACT_REFUSE, A1, "res ok end",
412 "rep refused bound end"]), "episode.shape FAIL")
413 neg("refuse_after_result", lambda d: episode(d, [G1, A1, "res ok end", L.ACT_REFUSE,
414 "rep refused bound end"]), "episode.shape FAIL")
415 neg("P_after_G", lambda d: episode(d, [G1, "rep refused bound end"]), "episode.shape FAIL")
416 neg("binding_no_current_job", lambda d: episode(d, [G1, A1, "res refused replay end", A1,
417 "res ok end", SPEC[0][5][-1]]),
418 "binding: no current job")
419
420 # Validly signed replacement keys must not become the trust root.
421 regenerated = os.path.join(tmp, "regenerated-keys")
422 original = mkcase.TEST_KEYS
423 try:
424 mkcase.TEST_KEYS = {k: v + 1 for k, v in original.items()}
425 mm_case(regenerated)
426 finally:
427 mkcase.TEST_KEYS = original
428 rc, out = run_check(regenerated)
429 failed = [l.split()[1] for l in out.splitlines() if l.startswith("CHECK ") and l.split()[2] == "FAIL"]
430 t("checkdemo.neg.regenerated_keys", rc == 1 and failed == ["keys.trust_root"], repr(failed))
431
432 # Adapter lies about replay after a real successful execution. Its episode,
433 # facts and English agree, but the runner outcome and stderr do not.
434 def false_replay(d):
435 episode(d, [G1, A1, "res refused replay end", "rep refused replay end"])
436 for col, value in (("exit", "11"), ("class", "refused"), ("code", "replay"),
437 ("mjr1_sha256", "-"), ("mjr1_outcome", "-"), ("verifier", "-")):
438 set_field(d, 1, col, value)
439 open(os.path.join(d, "response.en"), "w").write(
440 "Not completed: job 1 was refused (code replay): the worker refused a replay "
441 "of an already executed job.\n")
442 neg("replay_after_real_execution", false_replay, "row1.runtime_evidence FAIL")
443 def false_replay_outcome(d):
444 false_replay(d)
445 dag = open(os.path.join(d, "dispatch.log")).read().split()[4]
446 open(os.path.join(d, "dispatch.log"), "w").write("outcome 1 1 11 %s serve=11\n" % dag)
447 neg("replay_spoofed_outcome_real_execution_log", false_replay_outcome,
448 "runner stderr has no matching dag/failure")
449 neg("transport_identity_changed", lambda d: open(
450 os.path.join(d, "pins", "volunteer.ed25519"), "w").write("00" * 32 + "\n"),
451 "keys.trust_root FAIL")
452 neg("worker_hides_replay", lambda d: (
453 replay_case(d), set_field(d, 1, "code", "worker"),
454 episode(d, [G1, A1, "res refused worker end", "rep refused worker end"])),
455 "row1.runtime_evidence FAIL")
456 neg("replay_missing_done", lambda d: (replay_case(d), open(
457 os.path.join(d, "worker", "seen"), "w").write("AIENET0-STATE-V1\n")),
458 "replay dag is not done")
459 neg("nonok_log_wrong_dag", lambda d: (replay_case(d), open(
460 os.path.join(d, "logs", "fixture-0-run.err"), "w").write(
461 "aienet0-run: dag_id=" + "ab" * 32 + "\naienet0-run: REFUSED WORKER AN0_REPLAY\n")),
462 "row1.runtime_evidence FAIL")
463 rc = subprocess.run([sys.executable, CHECK], capture_output=True).returncode
464 t("checkdemo.usage_rc2", rc == 2)
465 return happy
466
467
468def main(argv):
469 with tempfile.TemporaryDirectory(prefix="oe45-eval-test-") as tmp:
470 spec_tests()
471 contract_vocab_test(argv[1] if len(argv) > 1 else None)
472 sealgen_tests(tmp)
473 real_artifact_tests()
474 checkdemo_tests(tmp)
475 print("OE45_EVAL_TESTS %s %s" % ("FAIL" if FAILS else "PASS", " ".join(FAILS)))
476 return 1 if FAILS else 0
477
478
479if __name__ == "__main__":
480 sys.exit(main(sys.argv))