code wiki / (root) / nx_writer_bound_gate_t190.nx

nx_writer_bound_gate_t190.nx source

↩ module page · 64 lines · 4297 B

1import "nx_apistack_idempotency_candidate_t190.nx" 2import "nx_gate_verdict.nx" 3func wg_write(p:*u8,b:*u8,n:i64)->i64{ 4 let fd:i64=sys_openat_wr(p,MODE_0600);if fd<0{return fd} 5 let w:i64=sys_write(fd,b,n);let c:i64=sys_close(fd);if w!=n||c!=0{return FIO_EIO};return 0 6} 7func wg_has(p:*u8,s:*u8,n:i64)->i64{ 8 let size:*i64=sys_mmap(8) as *i64;let b:*u8=sys_read_file(p,size) 9 if size[0]!=n{return 0};var i:i64=0;while i<n{if b[i]!=s[i]{return 0};i=i+1};return 1 10} 11func wg_run(av:*i64)->i64{ 12 let fd:i64=sys_openat_wr("last-output.log",MODE_0600);if fd<0{return fd} 13 let status:*i64=sys_mmap(8) as *i64;let env:*i64=sys_mmap(8) as *i64;env[0]=0 14 let pid:i64=sys_fork() 15 if pid==0{if sys_dup3(fd,1,0)<0||sys_dup3(fd,2,0)<0{sys_exit(125)};sys_execve(av[0] as *u8,av,env);sys_exit(127)} 16 var waited:i64=0-1;if pid>0{waited=sys_wait4(pid,status,0)};sys_close(fd) 17 if pid<=0||waited!=pid{return 0-1};return wait_status_rc(status[0]) 18} 19func main()->i64{ 20 let c:*i64=gv_ctr() 21 let root:*u8="knowledge/gates/writer-bound-fixture-t190" 22 gv_check("fresh isolated writer root",sys_mkdir(root,0x1c0)==0&&sys_chdir(root)==0,c) 23 gv_check("isolated ledger directories",sys_mkdir("knowledge",0x1c0)==0&&sys_mkdir("knowledge/status",0x1c0)==0,c) 24 gv_check("explicit isolated ledger bootstrap",wg_write("knowledge/status/fswrite_idem.jrnl","",0)==0,c) 25 let av:*i64=sys_mmap(9*8) as *i64 26 av[0]="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_fsops_write_candidate_t190.sov.elf" as i64 27 av[1]="write" as i64;av[2]="first" as i64;av[3]="alpha" as i64;av[4]="key=write-A" as i64;av[5]=0 28 gv_check("first normalized write applies",wg_run(av)==0&&wg_has("first","alpha",5)==1,c) 29 gv_check("identical keyed request replays",wg_run(av)==0&&wg_has("first","alpha",5)==1,c) 30 av[3]="bravo" as i64 31 gv_check("same key changed payload conflicts",wg_run(av)==9&&wg_has("first","alpha",5)==1,c) 32 av[3]="alpha" as i64;av[2]="second" as i64 33 gv_check("same key changed destination conflicts",wg_run(av)==9,c) 34 let st:*u8=sys_mmap(NX_STAT_X64_BYTES) 35 gv_check("conflict created no destination",sys_fstatat("second",st)==0-2,c) 36 av[2]="first" as i64;av[1]="write-file" as i64;av[3]="source.txt" as i64 37 wg_write("source.txt","alpha",5) 38 gv_check("artifact and inline normalize identically",wg_run(av)==0&&wg_has("first","alpha",5)==1,c) 39 wg_write("source.txt","bravo",5) 40 gv_check("changed loaded artifact conflicts",wg_run(av)==9&&wg_has("first","alpha",5)==1,c) 41 av[1]="write" as i64;av[2]="ordered" as i64;av[3]="data" as i64;av[4]="expect=0" as i64;av[5]="key=order-A" as i64;av[6]=0 42 gv_check("explicit condition request applies",wg_run(av)==0,c) 43 av[4]="key=order-A" as i64;av[5]="expect=0" as i64 44 gv_check("option order preserves fingerprint",wg_run(av)==0,c) 45 av[5]=0 46 gv_check("omitted condition differs from explicit",wg_run(av)==9,c) 47 av[1]="append" as i64;av[2]="journal" as i64;av[3]="row\n" as i64;av[4]="key=append-A" as i64 48 gv_check("append first applies",wg_run(av)==0,c) 49 gv_check("same append replays without second row",wg_run(av)==0&&wg_has("journal","row\n",4)==1,c) 50 av[1]="edit" as i64;av[2]="first" as i64;av[3]="alpha" as i64;av[4]="new" as i64;av[5]="key=edit-A" as i64;av[6]=0 51 gv_check("edit first applies",wg_run(av)==0,c) 52 gv_check("edit replay does not require old anchor",wg_run(av)==0&&wg_has("first","new",3)==1,c) 53 av[4]="other" as i64 54 gv_check("edit replacement differs",wg_run(av)==9&&wg_has("first","new",3)==1,c) 55 id_record("knowledge/status/fswrite_idem.jrnl","legacy",6,"rc=0 verb=write path=first",26) 56 av[1]="write" as i64;av[2]="first" as i64;av[3]="junk" as i64;av[4]="key=legacy" as i64;av[5]="expect=any" as i64;av[6]=0 57 gv_check("legacy unbound receipt requires reconciliation",wg_run(av)==9&&wg_has("first","new",3)==1,c) 58 av[2]="knowledge/status/fswrite_idem.jrnl" as i64;av[4]="key=receipt-fail" as i64 59 let partial:i64=wg_run(av) 60 gv_check("mutation followed by receipt failure is explicit",partial==10&&wg_has("knowledge/status/fswrite_idem.jrnl","junk",4)==1,c) 61 av[2]="after-corrupt" as i64;av[4]="key=after-corrupt" as i64 62 gv_check("corrupt evidence prevents next mutation",wg_run(av)==9&&sys_fstatat("after-corrupt",st)==0-2,c) 63 return gv_verdict("writer-bound-request",c,"Actual writer executable and isolated retained ledger; no exactly-once crash guarantee") 64}