nx_claude_harvest_gate.nx source
↩ module page · 81 lines · 4321 B
1// nx_claude_harvest_gate.nx -- END-TO-END gate for the outside-reliance miner: forks the SUBJECT ARTIFACT and
2// runs its own selftest (the 44-tooth proof that lived only in a verb), inheriting the exit code as the
3// verdict. Exists because on 2026-09-05 the honest-gauge fix shipped through nx_organ_ship with
4// prove=NO-GATE-FOUND: the proof existed, nothing could resolve it. A proof nothing can resolve is a
5// comment. Resolvable by the <target>_gate convention, so no organ_gate.conf row is needed.
6//
7// ARTIFACT IDENTITY (the promoted-first defect nx_organ_ship documents): the ship loop PROVEs BEFORE it
8// promotes, so the serving root still holds the PREVIOUS binary at PROVE time. This gate therefore prefers
9// the JUST-BUILT artifact buildroot/_build/nx_claude_harvest.sov.elf and falls back to the promoted
10// ./nx_claude_harvest.elf, and PRINTS which one it tested. T4 is the identity tooth: the partition
11// non-vacuity tooth (T23) exists ONLY in the fixed source, so a stale binary cannot pass this gate.
12//
13// exit: 0 GREEN / 1 RED (gv_verdict law: the exit code IS the verdict)
14import "nx_syscalls.nx"
15import "nx_gate_verdict.nx"
16import "nx_tool_run.nx"
17
18const CHG_OUT: i64 = 262144
19const CHG_PATH: i64 = 256
20
21func chg_find(q: *u8, n: i64, lit: *u8) -> i64 {
22 var ll: i64 = 0
23 while lit[ll] != (0 as u8) { ll = ll + 1 }
24 if ll == 0 { return 0 }
25 var i: i64 = 0
26 while i + ll <= n {
27 var j: i64 = 0
28 var ok: i64 = 1
29 while j < ll { if q[i + j] != lit[j] { ok = 0; j = ll } else { j = j + 1 } }
30 if ok == 1 { return 1 }
31 i = i + 1
32 }
33 return 0
34}
35
36func chg_exists(path: *u8) -> i64 {
37 let fd: i64 = sys_openat_rd(path)
38 if fd < 0 { return 0 }
39 sys_close(fd)
40 return 1
41}
42
43func main(argc: i64, argv: *i64) -> i64 {
44 let ctr: *i64 = gv_ctr()
45 gv_head("nx_claude_harvest_gate -- forks the subject artifact's own selftest; the exit code carries the verdict; T4 pins artifact identity" as *u8)
46 // resolve the subject: just-built first (PROVE runs before promote), promoted second, announced
47 let built: *u8 = "buildroot/_build/nx_claude_harvest.sov.elf" as *u8
48 let promoted: *u8 = "./nx_claude_harvest.elf" as *u8
49 var subject: *u8 = promoted
50 var which: *u8 = "PROMOTED" as *u8
51 if chg_exists(built) == 1 { subject = built; which = "JUST-BUILT" as *u8 }
52 let have: i64 = chg_exists(subject)
53 gv_puts("SUBJECT " as *u8); gv_puts(which); gv_puts(" " as *u8); gv_puts(subject); gv_puts("\n" as *u8)
54 gv_check("T1 subject artifact resolved and openable" as *u8, have, ctr)
55 if have == 0 { return gv_verdict("nx_claude_harvest_gate" as *u8, ctr, "no subject artifact at either root; nothing was proven" as *u8) }
56 // unique scratch prefix so a re-run is idempotent
57 let pfx: *u8 = sys_mmap(CHG_PATH)
58 var o: i64 = gv_cat(pfx, 0, "/tmp/chg_" as *u8)
59 o = gv_catn(pfx, o, sys_now_realtime_sec())
60 o = gv_cat(pfx, o, "_" as *u8)
61 pfx[o] = 0 as u8
62 let av: *i64 = sys_mmap(64) as *i64
63 av[0] = subject as i64
64 av[1] = "selftest" as *u8 as i64
65 av[2] = pfx as i64
66 av[3] = 0
67 let cout: *u8 = sys_mmap(CHG_OUT)
68 let colen: *i64 = sys_mmap(16) as *i64
69 colen[0] = 0
70 let ex: i64 = tr_run_capture(subject, av, cout, CHG_OUT - 8, colen)
71 let n: i64 = colen[0]
72 gv_kv("selftest_exit" as *u8, ex)
73 gv_kv("selftest_bytes" as *u8, n)
74 gv_check("T2 subject selftest exit 0 (its own verdict is GREEN)" as *u8, (ex == 0) as i64, ctr)
75 gv_check("T3 subject printed its verdict line verdict=GREEN" as *u8, chg_find(cout, n, "verdict=GREEN" as *u8), ctr)
76 // T4 ARTIFACT IDENTITY: the partition non-vacuity tooth exists only in the 2026-09-05 fix
77 gv_check("T4 artifact identity: partition non-vacuity tooth present (stale pre-fix binary cannot pass)" as *u8, chg_find(cout, n, "T23 non-vacuity: claude_outside_permil" as *u8), ctr)
78 gv_check("neg-control-no-red: subject output carries no verdict=RED" as *u8, (chg_find(cout, n, "verdict=RED" as *u8) == 0) as i64, ctr)
79 gv_check("T6 non-vacuity: captured output is not empty (a dead fork cannot pass)" as *u8, (n > 0) as i64, ctr)
80 return gv_verdict("nx_claude_harvest_gate" as *u8, ctr, "end-to-end: the subject's own selftest is the proof; T4 pins that the tested bytes carry the fix" as *u8)
81}