nx_blocklist_store_gate.nx source
↩ module page · 66 lines · 3631 B
1// nx_blocklist_store_gate.nx -- proves the SUPERVISED blocklist on the real seg_store (test prefix, production
2// untouched): an entry is stored PENDING (does not block) -> operator approve flips it to APPROVED -> the earlier
3// version is still in the store (additive history = the audit trail). Enumerable via __blidx__. license_tier: ORIGINAL
4import "nx_blocklist_store.nx"
5import "nx_gate.nx"
6import "nx_tabrec.nx"
7// compare the trailing field (after the last TAB) of buf[0..len) to z (NUL-term); 1 if equal
8func tail_eq(buf: *u8, len: i64, z: *u8) -> i64 {
9 var lt: i64=0-1; var i: i64=0
10 while i<len { if buf[i]==0x09 as u8 { lt=i } i=i+1 }
11 let s: i64=lt+1
12 var zl: i64=0; while z[zl]!=(0 as u8) { zl=zl+1 }
13 if len-s != zl { return 0 }
14 var c: i64=0; while c<zl { if buf[s+c]!=z[c] { return 0 } c=c+1 }
15 return 1
16}
17
18func main() -> i64 {
19 gw("=== nx_blocklist_store_gate: supervised blocklist on seg_store (pending -> approve, history kept) ===\n" as *u8)
20 let TP: *u8 = "knowledge/blocklist-test-" as *u8
21
22 // a fully-justified record, status pending
23 let rec: *u8 = sys_mmap(512)
24 var o: i64=0
25 o=tr_cat(rec,o,"80800080204a1000" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"10" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"NCII" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"StopNCII" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"2026-06-30" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"SNCII-00042" as *u8); o=tr_tab(rec,o); o=tr_cat(rec,o,"pending" as *u8)
26 bl_put_pfx(TP, "1" as *u8, rec, o)
27
28 var pass: i64=0; var tot: i64=0
29 let po: *i64=sys_mmap(16) as *i64
30 let lo: *i64=sys_mmap(16) as *i64
31
32 // T1 stored, status PENDING
33 let g1: i64=bl_get_pfx(TP, "1" as *u8, po, lo)
34 tot=tot+1; var t1: i64=0
35 if g1==1 { if tail_eq(po[0] as *u8, lo[0], "pending" as *u8)==1 { t1=1 } }
36 if t1==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
37 gw("T1 entry stored on seg_store, status=PENDING -- does NOT block until approved\n" as *u8)
38
39 // T2 operator approve -> APPROVED
40 bl_set_status_pfx(TP, "1" as *u8, "approved" as *u8)
41 let g2: i64=bl_get_pfx(TP, "1" as *u8, po, lo)
42 tot=tot+1; var t2: i64=0
43 if g2==1 { if tail_eq(po[0] as *u8, lo[0], "approved" as *u8)==1 { t2=1 } }
44 if t2==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
45 gw("T2 operator approve -> status=APPROVED (now eligible to block)\n" as *u8)
46
47 // T3 enumerable via __blidx__
48 let idxbuf: *u8=sys_mmap(65536)
49 let il: i64=bl_index_pfx(TP, idxbuf)
50 tot=tot+1; var t3: i64=0
51 if il>0 { if bl_id_present(idxbuf, il, "1" as *u8, 1)==1 { t3=1 } }
52 if t3==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
53 gw("T3 __blidx__ enumerates the whole list (for the viewable page)\n" as *u8)
54
55 // T4 history preserved: >=2 versions of bl:1 (pending + approved)
56 let kinds: *i64=sys_mmap(8*260) as *i64
57 let ptrs: *i64=sys_mmap(8*260) as *i64
58 let lens: *i64=sys_mmap(8*260) as *i64
59 let nv: i64=ss_scan(TP, "bl:1" as *u8, kinds, ptrs, lens)
60 tot=tot+1; if nv>=2 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
61 gw("T4 history preserved: " as *u8); gn(nv); gw(" versions of bl:1 kept (additive audit trail, never deleted)\n" as *u8)
62
63 gw("\n=== nx_blocklist_store_gate " as *u8); gn(pass); gw("/" as *u8); gn(tot); gw(" ===\n" as *u8)
64 if pass==tot { gw("BLOCKLIST-STORE GREEN -- supervised, pending-by-default, on seg_store, history kept (no TSV)\n" as *u8); sys_exit(0); return 0 }
65 gw("BLOCKLIST-STORE RED\n" as *u8); sys_exit(1); return 1
66}