code wiki / _hdl_build / nx_presubmit_gate.nx

nx_presubmit_gate.nx source

↩ module page · 58 lines · 2670 B

1// nx_presubmit_gate.nx -- proves the pre-submit guard on hermetic /tmp fixtures (never the shared tree). 2// license_tier: ORIGINAL 3import "nx_presubmit_lib.nx" 4import "nx_gate_verdict.nx" 5const K_MAGIC_1024: i64 = 1024 6 7func psg_wfile(path: *u8, s: *u8) -> i64 { 8 let fd: i64 = sys_openat_wr(path, 0x1a4) 9 if fd < 0 { return 0 - 1 } 10 sys_write(fd, s, es_len(s)) 11 sys_close(fd) 12 return 0 13} 14 15func main() -> i64 { 16 let ctr: *i64 = gv_ctr() 17 gv_head("nx_presubmit -- PRE-SUBMIT name/collision guard (catch before a build cycle is spent)" as *u8) 18 // hermetic fixtures: A=hdl-like has adopt.nx + dual.nx ; B=runtime-like has dual.nx + twin.nx 19 sys_mkdir("/tmp/psA\x00" as *u8, 0x1ed) 20 sys_mkdir("/tmp/psB\x00" as *u8, 0x1ed) 21 psg_wfile("/tmp/psA/adopt.nx\x00" as *u8, "x\n\x00" as *u8) 22 psg_wfile("/tmp/psA/dual.nx\x00" as *u8, "x\n\x00" as *u8) 23 psg_wfile("/tmp/psB/dual.nx\x00" as *u8, "x\n\x00" as *u8) 24 psg_wfile("/tmp/psB/twin.nx\x00" as *u8, "x\n\x00" as *u8) 25 let out: *u8 = sys_mmap(K_MAGIC_1024) 26 27 // T1 FREE: a name in neither dir 28 let r1: i64 = ps_check("zzfree" as *u8, "/tmp/psA" as *u8, "/tmp/psB" as *u8, out) 29 var t1: i64 = 0 30 if r1 == 0 { t1 = 1 } 31 gv_check("T1 unused name -> FREE (exit 0): create it" as *u8, t1, ctr) 32 33 // T2 EXISTS-in-hdl: adopt is in A only 34 let r2: i64 = ps_check("adopt" as *u8, "/tmp/psA" as *u8, "/tmp/psB" as *u8, out) 35 var t2: i64 = 0 36 if r2 == 4 { t2 = 1 } 37 gv_check("T2 name already in the primary dir -> EXISTS-in-hdl_build (exit 4): edit, don't create" as *u8, t2, ctr) 38 39 // T3 SHADOW-RISK: twin is in B (runtime) only -- creating in hdl makes a dual-copy (the nx_emit landmine) 40 let r3: i64 = ps_check("twin" as *u8, "/tmp/psA" as *u8, "/tmp/psB" as *u8, out) 41 var t3: i64 = 0 42 if r3 == 3 { t3 = 1 } 43 gv_check("T3 name has a runtime twin -> SHADOW-RISK (exit 3): the nx_emit dual-copy landmine, caught PRE-build" as *u8, t3, ctr) 44 45 // T4 DUAL: dual is in both 46 let r4: i64 = ps_check("dual" as *u8, "/tmp/psA" as *u8, "/tmp/psB" as *u8, out) 47 var t4: i64 = 0 48 if r4 == 3 { t4 = 1 } 49 gv_check("T4 name in BOTH dirs -> DUAL-COPY-ALREADY (exit 3)" as *u8, t4, ctr) 50 51 // T5 anti-vacuity: FREE must really mean absent -- a present name can never read FREE 52 var t5: i64 = 0 53 if r1 == 0 { if r2 != 0 { if r3 != 0 { if r4 != 0 { t5 = 1 } } } } 54 gv_check("T5 anti-vacuity: only the truly-absent name is FREE; every present name denies" as *u8, t5, ctr) 55 56 let rc: i64 = gv_verdict("NX-PRESUBMIT-GATE" as *u8, ctr, "pre-submit name/collision guard proven -- stage 1 of the 3-stage lifecycle" as *u8) 57 return rc 58}