code wiki / _hdl_build / nx_tpl_parts_gate.nx
nx_tpl_parts_gate.nx source
↩ module page · 105 lines · 5536 B
1// nx_tpl_parts_gate.nx -- referee for R-PARTS (nx_tpl_parts). Proves the LEGO half of the ingest: section-level
2// bricks extracted, content-addressed + deduped (near-dup template contributes 0 new bricks), idempotent across
3// runs, budget-guarded (fail-fast), junk skipped, and a recomputed brick key round-trips through the store with
4// a faithful record. GREEN iff 7/7. Wrapper pre-cleans /tmp/partcorpus_gate and /tmp/partcorpus_gate2.
5// license_tier: ORIGINAL expect_exit: 0
6import "nx_gate.nx"
7import "nx_tpl_parts.nx"
8import "nx_gate_verdict.nx"
9
10func pg_row(name: *u8, ok: i64) -> i64 { gw(" " as *u8); gw(name); if ok==1 { gw(" PASS\n" as *u8) } else { gw(" FAIL\n" as *u8) } return 0 }
11func pg_has(hay: *u8, hn: i64, needle: *u8) -> i64 {
12 if (hay as i64)==0 { return 0 }
13 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1}
14 if nl==0 { return 1 }
15 var i: i64=0
16 while i+nl<=hn { var j: i64=0; var ok: i64=1; while j<nl { if (hay[i+j] as i64)!=(needle[j] as i64) { ok=0; j=nl } else { j=j+1 } } if ok==1 { return 1 } i=i+1 }
17 return 0
18}
19
20func main() -> i64 {
21 // T1/T3: first run over the seed dir (landing + landing2 near-dup + shop + resume + junk)
22 let c1: *i64 = sys_mmap(64) as *i64
23 tp_run("web_assets/_tpl_seed" as *u8, "/tmp/partcorpus_gate/" as *u8, 2000, c1)
24 var t1: i64=0; if c1[0] >= 6 { t1=1 } // bricks stored
25 var t3: i64=0; if c1[1] >= 4 { t3=1 } // near-dup landing2 collapsed into dups
26 var t7: i64=0; if c1[2] >= 1 { t7=1 } // junk file skipped (no markup)
27 // T2: re-run is idempotent (cross-run dedup)
28 let c2: *i64 = sys_mmap(64) as *i64
29 tp_run("web_assets/_tpl_seed" as *u8, "/tmp/partcorpus_gate/" as *u8, 2000, c2)
30 var t2: i64=0; if c2[0] == 0 { if c2[1] >= c1[0] { t2=1 } }
31 // T4 (NEG): budget trap fires fail-fast on a fresh store
32 let c3: *i64 = sys_mmap(64) as *i64
33 tp_run("web_assets/_tpl_seed" as *u8, "/tmp/partcorpus_gate2/" as *u8, 2, c3)
34 var t4: i64=0; if c3[5] == 1 { if c3[0] <= 2 { t4=1 } }
35 // T5/T6: recompute the landing hero brick's key EXACTLY as the organ does -> present in store + faithful record
36 let szp: *i64 = sys_mmap(16) as *i64
37 let land: *u8 = sys_read_file("web_assets/_tpl_seed/landing.html" as *u8, szp)
38 let ln: i64 = szp[0]
39 let toks: *i64 = sys_mmap(TP_MAXK * 8) as *i64
40 let offs: *i64 = sys_mmap(TP_MAXK * 8) as *i64
41 let mets: *i64 = sys_mmap(8 * 8) as *i64
42 let key: *u8 = sys_mmap(64)
43 let np: i64 = tp_scan(land, ln, toks, offs)
44 var t5: i64=0
45 var t6: i64=0
46 if np >= 4 {
47 // find the hero token among the scanned parts
48 var hi: i64 = 0 - 1
49 var i: i64 = 0
50 while i < np {
51 let tk: *u8 = toks[i] as *u8
52 if tk[0] == (104 as u8) { if tk[1] == (101 as u8) { hi = i; i = np } }
53 i = i + 1
54 }
55 if hi >= 0 {
56 var to2: i64 = ln
57 if hi + 1 < np { to2 = offs[hi + 1] }
58 tp_metrics(land, offs[hi], to2, mets)
59 tp_mkkey("hero" as *u8, mets, key)
60 let pbox: *i64 = sys_mmap(16) as *i64
61 let lbox: *i64 = sys_mmap(16) as *i64
62 let hh: *i64 = ss_open("/tmp/partcorpus_gate/" as *u8)
63 if (hh as i64) != 0 {
64 if ss_hget(hh, key, pbox, lbox) == 1 {
65 t5 = 1
66 let rp: *u8 = pbox[0] as *u8
67 let rl: i64 = lbox[0]
68 if pg_has(rp, rl, "kind|hero" as *u8) == 1 { if pg_has(rp, rl, "src|" as *u8) == 1 { t6 = 1 } }
69 }
70 }
71 }
72 }
73
74 var passes: i64=0
75 if t1==1 { passes=passes+1 } if t2==1 { passes=passes+1 } if t3==1 { passes=passes+1 }
76 if t4==1 { passes=passes+1 } if t5==1 { passes=passes+1 } if t6==1 { passes=passes+1 } if t7==1 { passes=passes+1 }
77 var green: i64=0; if passes==7 { green=1 }
78
79 gw("=== nx_tpl_parts_gate -- R-PARTS section-brick (lego) ingest ===\n" as *u8)
80 pg_row("T1-bricks-stored " as *u8, t1)
81 pg_row("T2-idempotent-rerun " as *u8, t2)
82 pg_row("T3-neardup-collapse(neg) " as *u8, t3)
83 pg_row("T4-budget-trap-firefast(neg) " as *u8, t4)
84 pg_row("T5-recomputed-key-roundtrip " as *u8, t5)
85 pg_row("T6-record-faithful " as *u8, t6)
86 pg_row("T7-junk-skipped(neg) " as *u8, t7)
87 gw("verdict=" as *u8); if green==1 { gw("GREEN" as *u8) } else { gw("RED" as *u8) }
88 gw(" passes=" as *u8); gn(passes); gw("/7 stored=" as *u8); gn(c1[0]); gw(" dups=" as *u8); gn(c1[1]); gw(" parts_seen=" as *u8); gn(c1[7]); gw("\n" as *u8)
89
90 let lg: i64 = sys_openat_append("knowledge/status/tpl_parts.log" as *u8, 0x1a4)
91 if lg >= 0 {
92 if green==1 { let m: *u8 = "TPL-PARTS rows=7 pass=7 verdict=GREEN\n" as *u8; sys_write(lg, m, 38) }
93 else { let m2: *u8 = "TPL-PARTS verdict=RED\n" as *u8; sys_write(lg, m2, 22) }
94 sys_close(lg)
95 }
96 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
97 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
98 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
99 let ctr__dry: *i64 = gv_ctr()
100 ctr__dry[0] = green
101 ctr__dry[1] = 1
102 let rc__dry: i64 = gv_verdict("TPL-PARTS-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
103 sys_exit(rc__dry)
104 return rc__dry
105}