nx_io_envelope_census_gate.nx source
↩ module page · 73 lines · 5171 B
1// nx_io_envelope_census_gate.nx -- END-TO-END gate for the envelope census (/compare/dataio DI2): forks the SUBJECT
2// ARTIFACT's own selftest (the classifier on planted readers: literal, named constant, dynamic, comment, string, the
3// derived primitive, an unresolved name, a prefix-named constant, a call expression) and inherits its verdict, then
4// pins the artifact to THIS generation by a tooth only this generation prints. Same shape as nx_actlog_gate.
5// exit: 0 GREEN / 1 RED (gv_verdict law).
6import "nx_syscalls.nx"
7import "nx_gate_verdict.nx"
8import "nx_tool_run.nx"
9import "nx_srcfresh.nx"
10
11const EG_OUT: i64 = 262144
12
13func eg_find(q: *u8, n: i64, lit: *u8) -> i64 {
14 var ll: i64 = 0
15 while lit[ll] != (0 as u8) { ll = ll + 1 }
16 if ll == 0 { return 0 }
17 var i: i64 = 0
18 while i + ll <= n {
19 var j: i64 = 0
20 var ok: i64 = 1
21 while j < ll { if q[i + j] != lit[j] { ok = 0; j = ll } else { j = j + 1 } }
22 if ok == 1 { return 1 }
23 i = i + 1
24 }
25 return 0
26}
27func eg_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
28
29func main(argc: i64, argv: *i64) -> i64 {
30 let ctr: *i64 = gv_ctr()
31 gv_head("nx_io_envelope_census_gate -- forks the census's own selftest; the exit code carries the verdict" as *u8)
32 let built: *u8 = "buildroot/_build/nx_io_envelope_census.sov.elf" as *u8
33 let built_local: *u8 = "_build/nx_io_envelope_census.sov.elf" as *u8
34 let promoted: *u8 = "./nx_io_envelope_census.elf" as *u8
35 var subject: *u8 = promoted
36 var which: *u8 = "PROMOTED" as *u8
37 // A JUST-BUILT fossil is the subject ONLY when it is NEWER than the promoted binary. A refused build leaves the
38 // previous generation's fossil standing, and a gate that prefers it reports on bytes nothing serves. MEASURED
39 // 2026-09-06 on the NAS: this gate read RED 6/8 against a 2026-09-05 fossil while the promoted census carried the
40 // DI12 teeth. An absent promoted binary reads mtime -1, so a fossil still wins when nothing is promoted yet.
41 if eg_exists(built_local) == 1 { if sf_mtime_ns(built_local) > sf_mtime_ns(promoted) { subject = built_local; which = "JUST-BUILT-local(newer than promoted)" as *u8 } }
42 if eg_exists(built) == 1 { if sf_mtime_ns(built) > sf_mtime_ns(promoted) { subject = built; which = "JUST-BUILT(newer than promoted)" as *u8 } }
43 let have: i64 = eg_exists(subject)
44 gv_puts("SUBJECT " as *u8); gv_puts(which); gv_puts(" " as *u8); gv_puts(subject); gv_puts("\n" as *u8)
45 gv_check("T1 subject artifact resolved and openable" as *u8, have, ctr)
46 if have == 0 { return gv_verdict("nx_io_envelope_census_gate" as *u8, ctr, "no subject artifact at any root; nothing was proven" as *u8) }
47 let av: *i64 = sys_mmap(32) as *i64
48 av[0] = subject as i64
49 av[1] = "selftest" as *u8 as i64
50 av[2] = 0
51 let cout: *u8 = sys_mmap(EG_OUT)
52 let colen: *i64 = sys_mmap(16) as *i64
53 colen[0] = 0
54 let ex: i64 = tr_run_capture(subject, av, cout, EG_OUT - 8, colen)
55 let n: i64 = colen[0]
56 gv_kv("selftest_exit" as *u8, ex)
57 gv_kv("selftest_bytes" as *u8, n)
58 gv_check("T2 subject selftest exit 0" as *u8, (ex == 0) as i64, ctr)
59 // last line by position must be the verdict line
60 var ls: i64 = n
61 if ls > 0 { if cout[ls - 1] == (10 as u8) { ls = ls - 1 } }
62 var lb: i64 = ls
63 var scanning: i64 = 1
64 while scanning == 1 { if lb == 0 { scanning = 0 } else { if cout[lb - 1] == (10 as u8) { scanning = 0 } else { lb = lb - 1 } } }
65 gv_check("T3 the LAST line is the verdict line and reads verdict=GREEN" as *u8, eg_find(((cout as i64) + lb) as *u8, ls - lb, "verdict=GREEN" as *u8), ctr)
66 gv_check("T4 artifact identity, this generation: the prefix-named-constant tooth (T9) is present" as *u8, eg_find(cout, n, "T9 a name that is a PREFIX of another const" as *u8), ctr)
67 gv_check("T4b artifact identity, DI12 generation: the ratchet's fall tooth (T15) and the LOOPED class tooth (T11) are present" as *u8, eg_find(cout, n, "T15 a baseline site no longer silent is a FALL" as *u8) * eg_find(cout, n, "T11 a read INSIDE a while block is LOOPED" as *u8), ctr)
68 gv_check("T4c the subject printed its ratchet on fixtures (baseline=TIGHTENED and baseline=MIGRATED both witnessed)" as *u8, eg_find(cout, n, "baseline=TIGHTENED" as *u8) * eg_find(cout, n, "baseline=MIGRATED" as *u8), ctr)
69 gv_check("T4d artifact identity, DI15 generation: the loop-exit judge (T20 STREAMING, T22 CAPPED) and the loop-DRIVING rule (neg-control-T26) are present" as *u8, eg_find(cout, n, "T20 nx_sizeguard's shape" as *u8) * eg_find(cout, n, "T22 a streaming loop that ALSO stops" as *u8) * eg_find(cout, n, "neg-control-T26 a per-connection read" as *u8), ctr)
70 gv_check("neg-control-no-red: subject output carries no verdict=RED" as *u8, (eg_find(cout, n, "verdict=RED" as *u8) == 0) as i64, ctr)
71 gv_check("T6 non-vacuity: captured output is not empty" as *u8, (n > 0) as i64, ctr)
72 return gv_verdict("nx_io_envelope_census_gate" as *u8, ctr, "end-to-end: the census's own selftest is the proof; T4 pins the tested bytes to this generation" as *u8)
73}