code wiki / _hdl_build / nx_spec_anchor_gate.nx
nx_spec_anchor_gate.nx source
↩ module page · 65 lines · 3233 B
1// nx_spec_anchor_gate.nx -- REGRESSION TOOTH for the NXA format spec. The spec is the format's
2// ONLY documentation BY DESIGN ("this file IS the spec"), so a rewrite that drops a normative
3// paragraph is silent contract loss -- MEASURED 2026-07-29: the entire channel-2 PACKED
4// WORLD-DELTA section vanished in the POSE-amendment rewrite and nothing noticed until the
5// seq1285 unit audit re-read the file. Each tooth asserts a normative ANCHOR substring exists.
6// usage: nx_spec_anchor_gate [specpath] (default knowledge/nxa_format_spec.md)
7// Mutation-proof without touching the real spec: run against a COPY with an anchor removed.
8// license_tier: ORIGINAL No hw writes (Rule 26).
9import "nx_syscalls.nx"
10import "nx_gate_verdict.nx"
11
12const SAG_CAP: i64 = 1048576
13
14func sag_find(hay: *u8, n: i64, needle: *u8) -> i64 {
15 var nl: i64 = 0
16 while needle[nl] != (0 as u8) { nl = nl + 1 }
17 if nl == 0 { return 0 - 1 }
18 var i: i64 = 0
19 while i + nl <= n {
20 var j: i64 = 0
21 var hit: i64 = 1
22 while j < nl {
23 if hay[i + j] != needle[j] { hit = 0; j = nl } else { j = j + 1 }
24 }
25 if hit == 1 { return i }
26 i = i + 1
27 }
28 return 0 - 1
29}
30
31func main(argc: i64, argv: *i64) -> i64 {
32 var path: *u8 = "knowledge/nxa_format_spec.md" as *u8
33 if argc >= 2 { path = argv[1] as *u8 }
34 let szp: *i64 = sys_mmap(16) as *i64
35 let b: *u8 = sys_read_file(path, szp)
36 let n: i64 = szp[0]
37 let ctr: *i64 = gv_ctr()
38 gv_head("nx_spec_anchor_gate -- the NXA spec's normative anchors must survive every rewrite" as *u8)
39 gv_check("T1 spec readable and non-trivial (>4KB)" as *u8, (n > 4096) as i64, ctr)
40 if n <= 0 {
41 gv_check("T2..T9 skipped: no bytes" as *u8, 0, ctr)
42 sys_exit(gv_verdict("SPEC-ANCHOR" as *u8, ctr, "" as *u8))
43 }
44 gv_check("T2 magic NXANIM01 documented" as *u8,
45 (sag_find(b, n, "NXANIM01" as *u8) >= 0) as i64, ctr)
46 gv_check("T3 channel-2 PACKED WORLD-DELTA section present" as *u8,
47 (sag_find(b, n, "channel 2 = PACKED WORLD-DELTA" as *u8) >= 0) as i64, ctr)
48 gv_check("T4 packed key lane layout documented (t_ms u16)" as *u8,
49 (sag_find(b, n, "t_ms u16" as *u8) >= 0) as i64, ctr)
50 gv_check("T5 VERT unit truth: 0.01 mm units named" as *u8,
51 (sag_find(b, n, "0.01 mm" as *u8) >= 0) as i64, ctr)
52 gv_check("T6 dt-lane mm x100 consumer warning present" as *u8,
53 (sag_find(b, n, "MILLIMETERS, NOT" as *u8) >= 0) as i64, ctr)
54 gv_check("T7 runtime LBS law present (M x = D)" as *u8,
55 (sag_find(b, n, "D\xc2\xb7(x \xe2\x88\x92 bind_t)" as *u8) >= 0 ||
56 sag_find(b, n, "M x = D" as *u8) >= 0) as i64, ctr)
57 gv_check("T8 rolling checksum constant documented (1000003)" as *u8,
58 (sag_find(b, n, "1000003" as *u8) >= 0) as i64, ctr)
59 gv_check("T9 POSE section documented" as *u8,
60 (sag_find(b, n, "POSE" as *u8) >= 0) as i64, ctr)
61 gv_check("T10 refuse-the-future version law present" as *u8,
62 (sag_find(b, n, "refuse" as *u8) >= 0) as i64, ctr)
63 sys_exit(gv_verdict("SPEC-ANCHOR" as *u8, ctr, "the spec cannot silently lose its contract" as *u8))
64 return 0
65}