code wiki / (root) / nx_fileop_gate.nx

nx_fileop_gate.nx source

↩ module page · 40 lines · 1916 B

1// nx_fileop_gate.nx -- proves sovereign file ops on a real scratch file: create -> exists, mv (old gone + new 2// exists), rm (gone). Composes the canonical nx_fio + nx_syscalls. No shell. license_tier: ORIGINAL 3import "nx_fio.nx" 4import "nx_gate.nx" 5import "nx_gate_verdict.nx" 6 7func main() -> i64 { 8 gw("=== nx_fileop_gate: sovereign file ops (create/exists/mv/rm) ===\n" as *u8) 9 let p1: *u8 = "/tmp/nx_fileop_t1" as *u8 10 let p2: *u8 = "/tmp/nx_fileop_t2" as *u8 11 fio_unlink(p1); fio_unlink(p2) // clean any leftovers from a prior run 12 13 var pass: i64=0; var tot: i64=0 14 15 let fd: i64 = sys_openat_wr(p1, 0x1ed) 16 if fd >= 0 { sys_write(fd, "hi" as *u8, 2); sys_close(fd) } 17 tot=tot+1; if fio_exists(p1)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 18 gw("T1 created file exists\n" as *u8) 19 20 sys_renameat(p1, p2) 21 tot=tot+1; var t2: i64=0 22 if fio_exists(p1)==0 { if fio_exists(p2)==1 { t2=1 } } 23 if t2==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 24 gw("T2 mv: old path gone + new path exists (atomic rename)\n" as *u8) 25 26 fio_unlink(p2) 27 tot=tot+1; if fio_exists(p2)==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 28 gw("T3 rm: file gone (retires Remove-Item)\n" as *u8) 29 30 gw("\n=== nx_fileop_gate " as *u8); gn(pass); gw("/" as *u8); gn(tot); gw(" ===\n" as *u8) 31 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 32 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 33 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 34 let ctr__dry: *i64 = gv_ctr() 35 ctr__dry[0] = pass 36 ctr__dry[1] = tot 37 let rc__dry: i64 = gv_verdict("FILEOP-GATE" as *u8, ctr__dry, "sovereign rm/mv/exists, no shell" as *u8) 38 sys_exit(rc__dry) 39 return rc__dry 40}