code wiki / _hdl_build / nx_spec_ingest_test.nx

nx_spec_ingest_test.nx source

↩ module page · 67 lines · 4478 B

1// nx_spec_ingest_test.nx -- prove the SPEC -> BUILDER -> INGEST bridge end to end. A spec PATH->BINARY 2// is handed to the Builder (bc_compose -> [READ, COMPILE], len 2); on verify it BANKS a capability record 3// by APPENDING to /tmp/nishi_registry.log via sys_write; we re-read the file and confirm the line the 4// LOOP wrote is there (automatic ingestion, not hand-edited). An unbuildable spec is rejected, unbanked. 5// Exit 0 on 7/7. license_tier: ORIGINAL 6 7import "nx_spec_ingest.nx" 8import "nx_syscalls.nx" 9 10func st_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func st_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 } 12 13func main() -> i64 { 14 st_puts("=== SPEC -> BUILDER -> INGEST bridge ===\n" as *u8) 15 let regpath: *u8 = "/tmp/nishi_registry.log" as *u8 16 17 // 1. spec: PATH -> BINARY. hand it to the Builder. 18 let seq: *i64 = sys_mmap(8*8) as *i64 19 let chain_len: i64 = si_buildable(BC_T_PATH, BC_T_BINARY, seq, 8) 20 st_puts(" spec PATH->BINARY: Builder composed a chain of length " as *u8); st_num(chain_len); st_puts(" (expect 2: READ,COMPILE)\n" as *u8) 21 let verdict: i64 = si_ingest_verdict(chain_len, 1) // Builder verified by exec = 1 (pre-check only) 22 23 // 2. GOVERNANCE, not a flag: the candidate goes through Engineer rigor + Council + docs before banking. 24 let eng: i64 = ig_engineer(1, 1, 1, 1) // built clean (compile/link/run/exit ok) 25 let council: i64 = ig_council(eng, 1, 10, 20) // additive; admitted by Council (id 20) != Builder (id 10) 26 let documented: i64 = ig_documented(1, 1) // Scribe logged catalog + doc 27 let gov: i64 = ig_decision(eng, council, documented) // == IG_INGEST only if all hold 28 let fd: i64 = sys_openat_wr(regpath, 420) 29 let banked: i64 = si_bank_if_governed(fd, "build-path-to-binary" as *u8, 20, chain_len, gov) 30 31 // 3. read the registry back -- did the loop's write land? (automatic ingestion, on disk) 32 let rfd: i64 = sys_openat_rd(regpath) 33 let buf: *u8 = sys_mmap(512) 34 let got: i64 = sys_read(rfd, buf, 511) 35 // scan for "CAP " to confirm the banked line is present. 36 var found: i64 = 0; var i: i64 = 0 37 while i < got - 3 { 38 if buf[i] == (67 as u8) { if buf[i+1] == (65 as u8) { if buf[i+2] == (80 as u8) { found = 1 } } } 39 i = i + 1 40 } 41 st_puts(" registry now holds " as *u8); st_num(got); st_puts(" bytes; CAP record present = " as *u8); st_num(found); st_puts("\n" as *u8) 42 43 // 4. an UNBUILDABLE spec (HASH->PATH: no primitive yields PATH) must be rejected, unbanked. 44 let seq2: *i64 = sys_mmap(8*8) as *i64 45 let bad_len: i64 = si_buildable(BC_T_HASH, BC_T_PATH, seq2, 8) 46 let bad_verdict: i64 = si_ingest_verdict(bad_len, 1) 47 st_puts(" unbuildable spec HASH->PATH: chain_len=" as *u8); st_num(bad_len); st_puts(" verdict=" as *u8); st_num(bad_verdict); st_puts(" (0=REJECT, correctly unbanked)\n" as *u8) 48 49 let r: *i64 = sys_mmap(8*8) as *i64 50 r[0]=0; if chain_len == 2 { r[0]=1 } // Builder ingested the spec + composed 51 r[1]=0; if verdict == SI_OK { if gov == IG_INGEST { r[1]=1 } } // verified AND governed -> ingest 52 r[2]=0; if banked == 1 { r[2]=1 } // banked only after governance admitted it 53 r[3]=0; if got > 20 { r[3]=1 } // registry actually written 54 r[4]=0; if found == 1 { r[4]=1 } // the CAP record is on disk (automatic ingestion) 55 r[5]=0; if bad_len <= 0 { r[5]=1 } // unbuildable spec honestly not composed 56 r[6]=0; if bad_verdict == SI_REJECT { r[6]=1 } // and not banked 57 var pass: i64 = 0; var j: i64 = 0 58 while j < 7 { pass = pass + r[j]; j = j + 1 } 59 st_puts("----\n passed " as *u8); st_num(pass); st_puts("/7\n" as *u8) 60 if pass == 7 { 61 st_puts(" GOVERNED CLOSE: loop pick -> SPEC -> BUILDER composes -> ENGINEER+COUNCIL+docs admit -> only THEN\n" as *u8) 62 st_puts(" the record is banked to the registry by the team's own sys_write. No auto-insert; the self-model\n" as *u8) 63 st_puts(" regenerates FROM this governed registry.\n" as *u8) 64 sys_exit(0); return 0 65 } 66 st_puts(" FAIL\n" as *u8); sys_exit(1); return 1 67}