code wiki / _hdl_build / nx_cap_register_test.nx

nx_cap_register_test.nx source

↩ module page · 64 lines · 4750 B

1// nx_cap_register_test.nx -- prove the Librarian's lint+register catches the EXACT bug Claude made by hand 2// (caps at lay 6/7/8 with nlayers=6 -> invisible) and that the team's validated registration EXCEEDS the 3// manual process. Exit 0 on 10/10. license_tier: ORIGINAL 4 5import "nx_cap_register.nx" 6import "nx_syscalls.nx" 7 8func ct_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9func ct_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } 10func ct_has(buf: *u8, n: i64, ndl: *u8, nl: i64) -> i64 { var i: i64=0; while i<=n-nl { var j: i64=0; var ok: i64=1; while j<nl { if buf[i+j]!=ndl[j] {ok=0;j=nl} j=j+1 } if ok==1 {return 1} i=i+1 } return 0 } 11 12func main() -> i64 { 13 ct_puts("=== LIBRARIAN self-model LINT + REGISTER (catches the bug Claude made by hand) ===\n" as *u8) 14 let NL: i64 = 6 // ECO_NLAYERS = 6 (layers 0..5) 15 16 // the exact bug: a cap at layer 8 with 6 layers is INVISIBLE. 17 let bug: i64 = sml_check_cap(8, 2, NL) 18 let okc: i64 = sml_check_cap(5, 2, NL) 19 ct_puts(" lay8/6layers -> " as *u8); ct_puts(sml_code_label(bug)); ct_puts(" lay5/6layers -> " as *u8); ct_puts(sml_code_label(okc)); ct_puts("\n" as *u8) 20 21 // replay Claude's ACTUAL 9 hand-registered invisible caps (lays 7,7,7,6,6,8,8,8,6): 22 let manual: *i64 = sys_mmap(8*9) as *i64 23 manual[0]=7; manual[1]=7; manual[2]=7; manual[3]=6; manual[4]=6; manual[5]=8; manual[6]=8; manual[7]=8; manual[8]=6 24 let invisible: i64 = sml_count_invisible(manual, 9, NL) 25 ct_puts(" Claude's manual batch: " as *u8); ct_num(invisible); ct_puts(" / 9 caps were INVISIBLE (silently uncounted) -- the lint catches every one\n" as *u8) 26 27 // registration gates 28 let reg_invisible: i64 = cr_can_register(8, 2, NL, IG_INGEST) // governed but invisible -> REFUSE 29 let reg_ungoverned: i64 = cr_can_register(5, 2, NL, IG_HELD) // valid but not governed -> REFUSE 30 let reg_good: i64 = cr_can_register(5, 2, NL, IG_INGEST) // valid + governed -> ALLOW 31 let why_invisible: i64 = cr_refusal_reason(8, 2, NL, IG_INGEST) 32 33 // write a real registry record + read it back 34 let path: *u8 = "/tmp/nishi_cap_registry.log" as *u8 35 let tfd: i64 = sys_openat_wr(path, 0x1a4); sys_close(tfd) // truncate 36 let fd: i64 = sys_openat_append(path, 0x1a4) 37 if reg_good == 1 { cr_write_entry(fd, 207, 5, "LIBRARIAN cap-register + self-model lint" as *u8, 2) } 38 sys_close(fd) 39 let rfd: i64 = sys_openat_rd(path); let buf: *u8 = sys_mmap(512); let got: i64 = sys_read(rfd, buf, 511) 40 let wrote: i64 = ct_has(buf, got, "CAPREG idx=207 layer=5" as *u8, 22) 41 ct_puts(" register: invisible-refused=" as *u8); ct_num(reg_invisible); ct_puts(" ungoverned-refused=" as *u8); ct_num(reg_ungoverned); ct_puts(" good-allowed=" as *u8); ct_num(reg_good); ct_puts(" registry-written=" as *u8); ct_num(wrote); ct_puts("\n" as *u8) 42 43 let r: *i64 = sys_mmap(16*8) as *i64 44 r[0]=0; if bug == SML_BAD_LAYER { r[0]=1 } 45 r[1]=0; if okc == SML_OK { r[1]=1 } 46 r[2]=0; if invisible == 9 { r[2]=1 } // ALL 9 of Claude's manual caps caught 47 r[3]=0; if reg_invisible == 0 { r[3]=1 } // an invisible cap can't be registered 48 r[4]=0; if reg_ungoverned == 0 { r[4]=1 } // an ungoverned cap can't be registered 49 r[5]=0; if reg_good == 1 { r[5]=1 } // valid + governed registers 50 r[6]=0; if why_invisible == SML_BAD_LAYER { r[6]=1 } // refusal reason is precise 51 r[7]=0; if wrote == 1 { r[7]=1 } // the team wrote the registry record 52 r[8]=0; if sml_registry_clean(manual, manual, 9, NL) == 0 { r[8]=1 } // dirty registry detected 53 r[9]=0; if invisible > 0 { r[9]=1 } // and Claude's manual process WAS dirty 54 var pass: i64 = 0; var i: i64 = 0 55 while i < 10 { pass = pass + r[i]; i = i + 1 } 56 ct_puts("---- passed " as *u8); ct_num(pass); ct_puts("/10 ----\n" as *u8) 57 if pass == 10 { 58 ct_puts(" S-CLASS CHECK: Claude's MANUAL registration shipped 9 invisible caps; the team's LINT+REGISTER\n" as *u8) 59 ct_puts(" ships 0 (it refuses them with a precise reason). The team's functionality EXCEEDS the manual\n" as *u8) 60 ct_puts(" process on reliability -- the Librarian now owns registration; Claude only reviews.\n" as *u8) 61 sys_exit(0); return 0 62 } 63 ct_puts(" FAIL\n" as *u8); sys_exit(1); return 1 64}