code wiki / (root) / nx_organ_ship_loss_canonical_integration_gate_t370.nx

nx_organ_ship_loss_canonical_integration_gate_t370.nx source

↩ module page · 36 lines · 3823 B

1import "nx_organ_ship.nx" 2static ok_count:i64 3static bad_count:i64 4func test(ok:i64,name:*u8)->i64{if ok==1{ok_count=ok_count+1;os_puts("PASS ")}else{bad_count=bad_count+1;os_puts("FAIL ")};os_puts(name);os_puts("\n");return 0} 5func copy_fixture(src:*u8,dst:*u8)->i64{ 6 let av:*i64=sys_mmap_try(4*__size_of(i64)) as *i64;if (av as i64)<=0{return -1} 7 let elf:*u8="/volume1/homes/elderwesto/nishihost/nx_filecopy.elf";av[0]=elf as i64;av[1]=src as i64;av[2]=dst as i64;av[3]=0 8 var b:NxBufOwned;b.buf=0 as *u8;b.len=0;b.cap=0;var r:NxRunEvidence 9 let rc:i64=tr_run_capture_owned_result(elf,av,&b,30000,0,0 as *u8,&r);sys_write(1,b.buf,b.len);nx_bo_release(&b);sys_munmap_direct(av as *u8,4*__size_of(i64));return rc 10} 11func main(argc:i64,argv:*i64)->i64{ 12 if argc!=2{return 2};let root:*u8=argv[1] as *u8 13 if sys_mkdir(root,493)!=0{return 2};if sys_chdir(root)!=0{return 2} 14 sys_mkdir("knowledge",493);sys_mkdir("knowledge/status",493);sys_mkdir("knowledge/status/harness",493) 15 if copy_fixture("/volume1/homes/elderwesto/nishihost/nx_filehash.elf","nx_filehash.elf")!=0{return 2} 16 if copy_fixture("/volume1/homes/elderwesto/nishihost/nx_contentdiff.elf","nx_contentdiff.elf")!=0{return 2} 17 if copy_fixture("/volume1/homes/elderwesto/nishihost/nx_wflow.elf.before-identity-result-t344","subject.elf")!=0{return 2} 18 if copy_fixture("/volume1/homes/elderwesto/nishihost/nx_wflow.elf","subject.sov.elf.new")!=0{return 2} 19 let lhs:*u8="7e28ced1fa36bd63d358293c7e2890ee97e92d06939425042c4ea46b7999529a" 20 let rhs:*u8="4c570b50b807d6bbb96f05cba273139443b0eb9c93d78ae7b39853d352ecf012" 21 let probe:*u8=sys_mmap_try(80);os_sha_of("subject.elf",probe);os_puts("PROBE live=");os_puts(probe);os_puts("\n");os_sha_of("subject.sov.elf.new",probe);os_puts("PROBE candidate=");os_puts(probe);os_puts("\n");sys_munmap_direct(probe,80) 22 test(os_loss_exact("subject","subject.elf",rhs,0 as *u8)==31,"actual ship count-only refuses after retaining complete evidence") 23 let av:*i64=sys_mmap_try(5*__size_of(i64)) as *i64;if (av as i64)<=0{return 2};av[0]="./nx_contentdiff.elf" as *u8 as i64;av[1]="subject.elf" as *u8 as i64;av[2]="subject.sov.elf.new" as *u8 as i64;av[3]="all" as *u8 as i64;av[4]=0 24 var out:NxBufOwned;out.buf=0 as *u8;out.len=0;out.cap=0;var observed:NxRunEvidence 25 let rc:i64=tr_run_capture_owned_result("./nx_contentdiff.elf",av,&out,30000,0,0 as *u8,&observed) 26 var set:OslLossSet;os_puts("PROBE content rc=");os_pn(rc);os_puts(" bytes=");os_pn(out.len);os_puts("\n");sys_write(1,out.buf,out.len);if rc!=1{return 2};if osls_build(lhs,rhs,out.buf,out.len,&set)!=0{return 2};nx_bo_release(&out);sys_munmap_direct(av as *u8,5*__size_of(i64)) 27 test(os_loss_exact("subject","subject.elf",rhs,set.digest)==0,"actual ship exact approval and retained-set reuse") 28 test(os_loss_exact("subject","subject.elf",lhs,set.digest)==31,"actual ship changed staged hash refuses") 29 test(os_loss_exact("subject","subject.elf",rhs,lhs)==31,"actual ship wrong same-length approval refuses") 30 var n:i64=0;let journal:*u8=sys_map_file("knowledge/status/organ_ship.jrnl",&n);var complete:i64=0 31 if (journal as i64)>0{if osls_find(journal,n,"ADOPT-LOSS-SET\tCOMPLETE")>=0{if osls_find(journal,n,set.digest)>=0{complete=1}};sys_write(1,journal,n);sys_munmap_direct(journal,n)} 32 test(complete,"actual journal references exact complete artifact-bound set") 33 let changedfd:i64=sys_openat_append("subject.sov.elf.new",493);if changedfd<0{return 2};let wrote:i64=sys_write(changedfd,"",1);let flushed:i64=sys_fsync(changedfd);sys_close(changedfd) 34 if wrote!=1||flushed!=0{return 2};test(os_loss_exact("subject","subject.elf",rhs,set.digest)==31,"actual candidate modified after approval refused") 35 osls_close(&set);os_puts("SHIP-LOSS-INTEGRATION pass=");os_pn(ok_count);os_puts(" fail=");os_pn(bad_count);os_puts("\n");if bad_count>0{return 1};return 0 36}