code wiki / (root) / nx_compare_regen_gate_t138.nx

nx_compare_regen_gate_t138.nx source

↩ module page · 77 lines · 4882 B

1// nx_compare_regen_gate_t138.nx -- Tests integration of a receipt emitter with journaling and file system operations. 2import "nx_compare_regen.nx" 3import "nx_gate_verdict.nx" 4func it_path(root:*u8,name:*u8)->*u8 { 5 let b:*u8=rgr_alloc(rgr_len(root)+rgr_len(name)+2) 6 var o:i64=rgr_copy(b,0,root);o=rgr_copy(b,o,"/" as *u8);rgr_copy(b,o,name);return b 7} 8func it_exact(path:*u8,body:*u8,n:i64)->i64 { 9 let len:*i64=rgr_alloc(8) as *i64 10 let b:*u8=sys_read_file(path,len) 11 var ok:i64=1 12 if (b as i64)<=0 {rgr_free(len as *u8,8);return 0} 13 if len[0]!=n {ok=0} 14 var i:i64=0 15 while i<n && ok==1 {if b[i]!=body[i] {ok=0} i=i+1} 16 sys_free_file(b,len[0]);rgr_free(len as *u8,8);return ok 17} 18func it_exit_probe(mode:*u8, expected:i64, marker:*u8, ctr:*i64)->i64 { 19 let out:*u8=rgr_alloc(512) 20 let len:*i64=rgr_alloc(8) as *i64 21 let rc:i64=rg_run("_build/nx_compare_regen_gate_t138.sov.elf" as *u8,mode,0 as *u8,out,512,len) 22 w(1,"child_finalizer mode=" as *u8);w(1,mode);w(1," exit=" as *u8);wn(1,rc);w(1," output=" as *u8);sys_write(1,out,len[0]) 23 gv_check(mode,rc==expected && tr_contains(out,len[0],marker)==1,ctr) 24 rgr_free(out,512);rgr_free(len as *u8,8) 25 return rc 26} 27func main(argc:i64,argv:*i64)->i64 { 28 if argc>1 { 29 let mode:*u8=argv[1] as *u8 30 var fails:i64=0 31 if mode[0]==(97 as u8) {g_rg_receipt_failures=1} 32 if mode[0]==(99 as u8) {if mode[1]==(111 as u8) {fails=1}} 33 return rg_exit_verdict(fails) 34 } 35 36 let ctr:*i64=gv_ctr();gv_head("COMPARE-REGEN-EMITTER-INTEGRATION") 37 let root:*u8=rgr_alloc(128) 38 var o:i64=rgr_copy(root,0,"/tmp/nx_compare_regen_t138-" as *u8);rgr_decimal(root,o,sys_now_realtime_us()) 39 gv_check("isolated fixture root created",sys_mkdir(root,493)==0,ctr) 40 w(1,"fixture_root=" as *u8);w(1,root);w(1,"\n" as *u8) 41 let journal:*u8=it_path(root,"comparepub.jrnl" as *u8) 42 let target:*u8=it_path(root,"api.json" as *u8) 43 let emitter:*u8="_build/nx_compare_receipt_emitter_t138.sov.elf" 44 let out:*u8=rgr_alloc(4096) 45 let emitterfd:i64=sys_openat_rd(emitter) 46 gv_check("real private emitter binary exists",emitterfd>=0,ctr);if emitterfd>=0 {sys_close(emitterfd)} 47 let success:i64=rg_emit_receipted(emitter,0 as *u8,0 as *u8,123,17,target,out,4096,journal) 48 gv_check("actual subprocess emitter publishes and receipts",success==0 && it_exact(target,"{\"fixture\":true}\n" as *u8,17)==1 && g_rg_receipt_failures==0,ctr) 49 let refused:*u8=it_path(root,"refused.json" as *u8) 50 rg_write_atomic(refused,"prior\n" as *u8,6) 51 let missing:*u8=it_path(root,"absent/journal" as *u8) 52 let failure:i64=rg_emit_receipted(emitter,0 as *u8,0 as *u8,123,17,refused,out,4096,missing) 53 gv_check("intent failure prevents publish and increments run audit failure",failure==(0-6) && it_exact(refused,"prior\n" as *u8,6)==1 && g_rg_receipt_failures==1 && g_rg_published_incomplete==0,ctr) 54 let full:*u8=it_path(root,"full.jrnl" as *u8) 55 gv_check("isolated real ENOSPC journal fixture",sys_symlinkat("/dev/full" as *u8,full)==0,ctr) 56 let visible:*u8=it_path(root,"visible.json" as *u8) 57 rg_write_atomic(visible,"prior\n" as *u8,6) 58 let incomplete:i64=rg_emit_receipted(emitter,0 as *u8,0 as *u8,123,17,visible,out,4096,full) 59 gv_check("completion ENOSPC returns failure after actual rename",incomplete==(0-6) && it_exact(visible,"{\"fixture\":true}\n" as *u8,17)==1 && g_rg_receipt_failures==2 && g_rg_published_incomplete==1,ctr) 60 let scope:*u8=it_path(root,"domain" as *u8);sys_mkdir(scope,493) 61 let droot:*u8=it_path(root,"" as *u8) 62 gv_check("scope metadata writes with audit failure and actual published counts",rg_scope_receipt(droot,"domain" as *u8,rg_published_count(1),2)==0,ctr) 63 let sp:*u8=it_path(scope,"scope.json" as *u8) 64 let sl:*i64=rgr_alloc(8) as *i64 65 let sb:*u8=sys_read_file(sp,sl) 66 var scopeok:i64=0 67 if (sb as i64)>0 { 68 scopeok=tr_contains(sb,sl[0],"\"published\":2" as *u8)*tr_contains(sb,sl[0],"\"fails\":2" as *u8)*tr_contains(sb,sl[0],"\"audit_failures\":2" as *u8)*tr_contains(sb,sl[0],"\"published_evidence_incomplete\":1" as *u8) 69 w(1,"scope_readback=" as *u8);sys_write(1,sb,sl[0]) 70 } 71 gv_check("scope evidence distinguishes published from incomplete audit",scopeok==1,ctr) 72 gv_check("shared run count includes actual renamed incomplete artifact",rg_published_count(1)==2,ctr) 73 it_exit_probe("audit failure forces process exit1" as *u8,1,"verdict=RED" as *u8,ctr) 74 it_exit_probe("core failure forces process exit1" as *u8,1,"verdict=RED" as *u8,ctr) 75 it_exit_probe("clean finalizer permits process exit0" as *u8,0,"verdict=GREEN" as *u8,ctr) 76 return gv_verdict("COMPARE-REGEN-EMITTER-INTEGRATION",ctr,"Private emitter process + actual atomic publication + real ENOSPC. Canonical/scoped alias adoption and served outcomes not claimed.") 77}