nx_writer_payload_gate_t293.nx source
↩ module page · 67 lines · 5010 B
1import "nx_fsops_write.nx"
2import "nx_writer_bound_canonical_gate_t190.nx"
3func pg_case(path:*u8,mode:i64)->i64{
4 let r:*NxFileReadRegion=sys_mmap_try(__size_of(NxFileReadRegion)) as *NxFileReadRegion
5 fio_region_init(r)
6 if fio_region_open(path,r)!=0{return 0}
7 if mode==1{wg_write(path,"grow-more",9)}
8 if mode==2{wg_write(path,"x",1)}
9 if mode==3{sys_close(r.fd)}
10 let status:*i64=sys_mmap_try(8) as *i64
11 let p:*u8=fsw_load_region_text(path,r,status)
12 let result:i64=((p as i64)==0&&status[0]==FSX_RC_IO) as i64
13 if (p as i64)>0{sys_munmap_direct(p,vw_slen(p)+1)}
14 sys_munmap_direct(status as *u8,8);return result
15}
16func main()->i64{
17 let c:*i64=gv_ctr();gv_head("WRITER ARTIFACT EXTENT AND CONTRACT")
18 let path:*u8=sys_mmap(160);var at:i64=fsw_cat(path,0,"knowledge/gates/writer-payload-t293-")
19 at=fsw_catn(path,at,osp_selfpid())
20 gv_check("fresh retained isolated root",sys_mkdir(path,0x1c0)==0&&sys_chdir(path)==0,c)
21 gv_check("isolated ledger",sys_mkdir("knowledge",0x1c0)==0&&sys_mkdir("knowledge/status",0x1c0)==0&&wg_write("knowledge/status/fswrite_idem.jrnl","",0)==0,c)
22 let source:*u8="/volume1/homes/elderwesto/nishihost/buildroot/knowledge/gates/beach-canonical-owner-t293.html"
23 let status:*i64=sys_mmap(8) as *i64
24 let actual:*u8=fsw_load_text(source,status)
25 if (actual as i64)<=0{gv_check("actual retained HTML load",0,c);return 1}
26 gv_check("actual retained HTML exceeds prior display limit and loads whole",status[0]==0&&vw_slen(actual)==1415858,c)
27 let av:*i64=sys_mmap(10*8) as *i64
28 av[0]="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_fsops_write.sov.elf" as i64
29 av[1]="write-file" as i64;av[2]="html" as i64;av[3]=source as i64;av[4]="key=html" as i64;av[5]=0
30 gv_check("actual large artifact writes and exact bytes match",wg_run(av)==0&&wg_has("html",actual,1415858)==1,c)
31 gv_check("identical keyed artifact replays",wg_run(av)==0&&wg_has("html",actual,1415858)==1,c)
32 av[4]=0
33 gv_check("existing destination without condition refused",wg_run(av)==FSW_RC_CLOBBER,c)
34 av[4]="expect=1" as i64
35 gv_check("stale size condition refused",wg_run(av)==FSW_RC_CLOBBER,c)
36 let token:*u8=sys_mmap(32);fsw_cat(token,0,"expect=h");fsw_hex_of(fsw_content_hash("html"),token+8)
37 av[4]=token as i64
38 gv_check("exact content hash condition accepts large file",wg_run(av)==0&&wg_has("html",actual,1415858)==1,c)
39 wg_write("different","other",5);av[3]="different" as i64;av[4]="key=html" as i64
40 gv_check("same key changed loaded bytes conflicts",wg_run(av)==FSW_RECONCILE_RC&&wg_has("html",actual,1415858)==1,c)
41 wg_write("empty","",0);av[2]="empty-result" as i64;av[3]="empty" as i64;av[4]=0
42 gv_check("empty text payload preserves existing zero-byte semantics",wg_run(av)==0&&fsw_cur_size("empty-result")==0,c)
43 let nul:*u8=sys_mmap(3);nul[0]=97 as u8;nul[1]=0 as u8;nul[2]=98 as u8;wg_write("nul",nul,3)
44 av[2]="nul-result" as i64;av[3]="nul" as i64
45 gv_check("embedded NUL refuses before destination",wg_run(av)==FSW_USAGE_RC&&fsw_cur_size("nul-result")<0,c)
46 av[3]="absent" as i64
47 gv_check("missing source refuses before destination",wg_run(av)==FSX_RC_IO&&fsw_cur_size("nul-result")<0,c)
48 wg_write("mutating","base",4);gv_check("growth after measured open refuses",pg_case("mutating",1)==1,c)
49 wg_write("mutating","base",4);gv_check("shrink after measured open refuses",pg_case("mutating",2)==1,c)
50 wg_write("mutating","base",4);gv_check("actual closed descriptor read error refuses",pg_case("mutating",3)==1,c)
51 wg_write("edit-target","old",3);wg_write("needle","old",3);wg_write("replacement","new",3)
52 av[1]="edit-files" as i64;av[2]="edit-target" as i64;av[3]="needle" as i64;av[4]="replacement" as i64;av[5]="key=edit" as i64;av[6]=0
53 gv_check("artifact edit preserves semantic dispatch",wg_run(av)==0&&wg_has("edit-target","new",3)==1,c)
54 gv_check("artifact edit idempotent replay",wg_run(av)==0&&wg_has("edit-target","new",3)==1,c)
55 av[4]="nul" as i64;av[5]=0
56 gv_check("second artifact NUL refuses without edit",wg_run(av)==FSW_USAGE_RC&&wg_has("edit-target","new",3)==1,c)
57 id_record("knowledge/status/fswrite_idem.jrnl","legacy-key",10,"rc=0 verb=write path=old",24)
58 av[1]="write" as i64;av[2]="after-legacy" as i64;av[3]="new" as i64;av[4]="key=fresh-after-legacy" as i64;av[5]=0
59 gv_check("valid legacy row does not block unrelated fresh key",wg_run(av)==0&&wg_has("after-legacy","new",3)==1,c)
60 av[2]="legacy-attempt" as i64;av[4]="key=legacy-key" as i64
61 gv_check("matching unbound legacy key refuses",wg_run(av)==FSW_RECONCILE_RC&&fsw_cur_size("legacy-attempt")<0,c)
62 fsx_append("knowledge/status/fswrite_idem.jrnl","combined\t\trc=0\n",15)
63 av[2]="after-malformed" as i64;av[4]="key=fresh-after-malformed" as i64
64 gv_check("malformed history blocks unrelated key pending explicit namespace recovery",wg_run(av)==FSW_RECONCILE_RC&&fsw_cur_size("after-malformed")<0,c)
65 if (actual as i64)>0{sys_munmap_direct(actual,1415859)}
66 return gv_verdict("writer-payload",c,"Native actual artifact and writer executable; no forced memory failure or atomic snapshot claim")
67}