nx_cap_census_gate.nx source
↩ module page · 69 lines · 4857 B
1// nx_cap_census_gate.nx -- proves the unified capability driver: (1) LIAR-KILL grounding cannot be fooled,
2// (2) the dynamic surface registry dedups labels, (3) pct math, and (4) the WHOLE pipeline reproduces the
3// known-good torrent number end-to-end (score 483, HAVE 26 / PARTIAL 7 / GAP 28, 0 ungrounded) -- so a
4// registry edit that silently changes the score is caught here. Imports the driver (main stripped).
5import "nx_cap_census.nx"
6import "nx_syscalls.nx"
7
8func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8) { n=n+1 } sys_write(1,s,n); return 0 }
9func gnum(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } while k>0 { k=k-1; sys_write(1,(((t as i64)+k) as *u8),1) } return 0 }
10func chk(name: *u8, got: i64, want: i64, pass: *i64, fail: *i64) -> i64 {
11 if got==want { pass[0]=pass[0]+1; gp(" ok " as *u8) } else { fail[0]=fail[0]+1; gp(" FAIL " as *u8) }
12 gp(name); gp(" got=" as *u8); gnum(got); gp(" want=" as *u8); gnum(want); gp("\n" as *u8)
13 return 0
14}
15
16func main() -> i64 {
17 gp("=== nx_cap_census_gate ===\n" as *u8)
18 let pass: *i64=sys_mmap(16) as *i64; let fail: *i64=sys_mmap(16) as *i64; pass[0]=0; fail[0]=0
19 let fbuf: *u8=sys_mmap(524288)
20
21 // substring + grounding liar-kill
22 let hay: *u8="the quick brown fox" as *u8
23 chk("T1 contains-hit" as *u8, cap_contains(hay,19,"brown" as *u8), 1, pass, fail)
24 chk("T2 contains-miss" as *u8, cap_contains(hay,19,"purple" as *u8), 0, pass, fail)
25 chk("T3 real-file+real-marker grounds" as *u8, cap_grounded("runtime/nx_torrent_daemon.nx" as *u8,"d_status_two" as *u8,fbuf,524288), 1, pass, fail)
26 chk("T4 real-file+bogus-marker rejected" as *u8, cap_grounded("runtime/nx_torrent_daemon.nx" as *u8,"zzz_no_such_q8x" as *u8,fbuf,524288), 0, pass, fail)
27 chk("T5 missing-file rejected" as *u8, cap_grounded("runtime/nx_nope_qq.nx" as *u8,"-" as *u8,fbuf,524288), 0, pass, fail)
28 chk("T6 dash-file never grounds" as *u8, cap_grounded("-" as *u8,"-" as *u8,fbuf,524288), 0, pass, fail)
29
30 // dynamic surface registry: distinct labels get new indices, a repeat returns the same index
31 let labs: *i64=sys_mmap(32*8) as *i64; let nlab: *i64=sys_mmap(8) as *i64; nlab[0]=0
32 chk("T7 reg acquire=0" as *u8, cap_surf_reg(labs,nlab,"acquire" as *u8), 0, pass, fail)
33 chk("T8 reg ops=1" as *u8, cap_surf_reg(labs,nlab,"ops" as *u8), 1, pass, fail)
34 chk("T9 reg acquire again=0" as *u8, cap_surf_reg(labs,nlab,"acquire" as *u8), 0, pass, fail)
35 chk("T10 nlab==2" as *u8, nlab[0], 2, pass, fail)
36
37 // pct math
38 chk("T11 pct half" as *u8, cap_pct(1,0,1), 500, pass, fail)
39 chk("T12 pct full" as *u8, cap_pct(2,0,0), 1000, pass, fail)
40
41 // END-TO-END: the whole pipeline over the real torrent registry must reproduce the known-good number
42 let out4: *i64=sys_mmap(4*8) as *i64
43 let s: i64=cap_census_one("torrent" as *u8, 0, fbuf, out4)
44 chk("T13 torrent score==483" as *u8, s, 483, pass, fail)
45 chk("T14 torrent HAVE==26" as *u8, out4[0], 26, pass, fail)
46 chk("T15 torrent PARTIAL==7" as *u8, out4[1], 7, pass, fail)
47 chk("T16 torrent GAP==28" as *u8, out4[2], 28, pass, fail)
48 chk("T17 torrent ungrounded==0" as *u8, out4[3], 0, pass, fail)
49
50 // external-SOTA anchoring: each target declares the frontier it is measured against
51 chk("T18 torrent SOTA sources==5" as *u8, cap_count_sources("torrent" as *u8), 5, pass, fail)
52 chk("T19 protocol SOTA sources==4" as *u8, cap_count_sources("torrent-protocol" as *u8), 4, pass, fail)
53
54 // drift-check log parsing (the autonomy primitive): recover a target's score from a prior ecosystem log
55 let synth: *u8="torrent score=483 H=26\ntorrent-protocol score=611 H=29\n" as *u8
56 var sl: i64=0; while synth[sl]!=(0 as u8) { sl=sl+1 }
57 chk("T20 prev torrent==483" as *u8, cap_prev_score(synth,sl,"torrent" as *u8), 483, pass, fail)
58 chk("T21 prev protocol==611" as *u8, cap_prev_score(synth,sl,"torrent-protocol" as *u8), 611, pass, fail)
59 chk("T22 prev absent==-1" as *u8, cap_prev_score(synth,sl,"gallery" as *u8), 0-1, pass, fail)
60
61 // JUDGE tier: a "gate:<name>" probe is behavior-proven iff the gate organ is on disk
62 chk("T23 probe gate-present" as *u8, cap_probe_grounded("gate:nx_net_polite_gate" as *u8), 1, pass, fail)
63 chk("T24 probe gate-absent" as *u8, cap_probe_grounded("gate:nx_zzz_no_such_gate" as *u8), 0, pass, fail)
64 chk("T25 probe non-gate" as *u8, cap_probe_grounded("-" as *u8), 0, pass, fail)
65
66 gp("\n-- RESULT pass=" as *u8); gnum(pass[0]); gp(" fail=" as *u8); gnum(fail[0]); gp("\n" as *u8)
67 if fail[0]==0 { gp("GATE verdict=GREEN\n" as *u8); sys_exit(0) } else { gp("GATE verdict=RED\n" as *u8); sys_exit(1) }
68 return 0
69}