code wiki / _hdl_build / nx_artifact_root_gate.nx

nx_artifact_root_gate.nx source

↩ module page · 95 lines · 5958 B

1// nx_artifact_root_gate.nx -- proves the shared resolver finds an artifact that IS there under a different 2// root, and does NOT invent one that is not. Both halves matter: the defect it exists to kill was a false 3// NEGATIVE (real files reported missing), and the obvious over-correction is a false POSITIVE (a resolver 4// so eager it "finds" something for any input, which would ground claims against the wrong file). 5// 6// The gate builds its own fixture tree and its own roots conf, so it never depends on -- or perturbs -- 7// production config. license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_artifact_root.nx" 10 11func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func wn(v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let b: *u8=sys_mmap(28); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 13func ck(pass: i64, label: *u8, fails: *i64) -> i64 { 14 w(" " as *u8); w(label); w(": " as *u8) 15 if pass==1 { w("PASS\n" as *u8) } else { w("FAIL\n" as *u8); fails[0]=fails[0]+1 } 16 return 0 17} 18func wfile(path: *u8, body: *u8) -> i64 { 19 let fd: i64 = sys_openat_wr(path, 0x1a4) 20 if fd < 0 { return 0 - 1 } 21 var n: i64 = 0 22 while body[n] != (0 as u8) { n = n + 1 } 23 sys_write(fd, body, n) 24 sys_close(fd) 25 return n 26} 27func streq(a: *u8, b: *u8) -> i64 { 28 var i: i64 = 0 29 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 30 if b[i] != (0 as u8) { return 0 } 31 return 1 32} 33 34func main() -> i64 { 35 let fails: *i64 = sys_mmap(16) as *i64 36 fails[0]=0 37 w("=== nx_artifact_root_gate -- finds what IS there under another root, invents nothing ===\n" as *u8) 38 39 // fixtures: one file at the CWD root (the "promote installs flat" shape) and one nested under 40 // knowledge/status/ (the "sources keep their directory" shape). 41 wfile("ar_fix_flat.tmp\x00" as *u8, "flat\n\x00" as *u8) 42 wfile("knowledge/status/ar_fix_nested.tmp\x00" as *u8, "nested\n\x00" as *u8) 43 wfile("knowledge/status/ar_gate_roots.conf\x00" as *u8, "# gate fixture roots\nroot=\nroot=knowledge/\nroot=knowledge/status/\n\x00" as *u8) 44 let conf: *u8 = "knowledge/status/ar_gate_roots.conf\x00" as *u8 45 let out: *u8 = sys_mmap(512) 46 47 // T1: a path that exists EXACTLY as written is returned unchanged. Nothing that works today changes. 48 var t1: i64=0 49 if ar_resolve_with("ar_fix_flat.tmp\x00" as *u8, out, conf)==1 { if streq(out, "ar_fix_flat.tmp\x00" as *u8)==1 { t1=1 } } 50 ck(t1, "T1 path exact as written -> resolved unchanged (no behaviour change for working paths)" as *u8, fails) 51 52 // T2: BASENAME join -- the binary shape. `_offc/x.elf` on a host where promote installed it flat. 53 var t2: i64=0 54 if ar_resolve_with("_offc/ar_fix_flat.tmp\x00" as *u8, out, conf)==1 { if streq(out, "ar_fix_flat.tmp\x00" as *u8)==1 { t2=1 } } 55 ck(t2, "T2 _offc/x -> found flat at the serving root (the promoted-binary shape)" as *u8, fails) 56 57 // T3: FULL-PATH join -- the source shape. The directory part carries real information here. 58 var t3: i64=0 59 if ar_resolve_with("status/ar_fix_nested.tmp\x00" as *u8, out, conf)==1 { if streq(out, "knowledge/status/ar_fix_nested.tmp\x00" as *u8)==1 { t3=1 } } 60 ck(t3, "T3 status/x -> knowledge/status/x via full-path join (the source-tree shape)" as *u8, fails) 61 62 // T4: THE FALSE-NEGATIVE THIS LIBRARY EXISTS TO KILL, in miniature: same basename, wrong directory, 63 // and it still must be found rather than reported absent. 64 // The first cut of this test asserted the wrong thing (it required only that the answer NOT equal one 65 // particular wrong path, which a plain miss also satisfies) AND its fixture sat one level below any 66 // configured root. The gate failed and the LIBRARY was correct -- kept as a note because a test that 67 // passes for the wrong reason is the same defect class this whole workstream is about. 68 var t4: i64=0 69 if ar_resolve_with("totally/wrong/dir/ar_fix_nested.tmp\x00" as *u8, out, conf)==1 { if streq(out, "knowledge/status/ar_fix_nested.tmp\x00" as *u8)==1 { t4=1 } } 70 ck(t4, "T4 wrong directory, real basename -> resolved to the REAL file (the 9-of-9-UNGROUNDED class)" as *u8, fails) 71 72 // T5: NEG-CONTROL -- a file that exists nowhere must return 0, and `out` must still read back as the 73 // INPUT so the caller's error names what it actually wanted. An eager resolver is a worse bug than a 74 // blind one: it would ground a claim against whatever file it happened to land on. 75 var t5: i64=0 76 if ar_resolve_with("nosuch/ZZ_NOT_A_REAL_FILE_QQ.tmp\x00" as *u8, out, conf)==0 { if streq(out, "nosuch/ZZ_NOT_A_REAL_FILE_QQ.tmp\x00" as *u8)==1 { t5=1 } } 77 ck(t5, "T5 NEG-CONTROL: unresolvable -> 0 and out==input (invents nothing, error stays truthful)" as *u8, fails) 78 79 // T6: a missing roots conf must not resolve-by-accident; absent config fails CLOSED. 80 var t6: i64=0 81 if ar_resolve_with("_offc/ar_fix_flat.tmp\x00" as *u8, out, "knowledge/status/ZZ_NO_SUCH_CONF.conf\x00" as *u8)==0 { t6=1 } 82 ck(t6, "T6 no roots conf -> 0 (absent config fails closed, does not guess)" as *u8, fails) 83 84 // T7: comment rows in the conf are not roots. A '#' line must never be joined as a prefix. 85 wfile("knowledge/status/ar_gate_roots2.conf\x00" as *u8, "#root=knowledge/\n\x00" as *u8) 86 var t7: i64=0 87 if ar_resolve_with("status/ar_fix_nested.tmp\x00" as *u8, out, "knowledge/status/ar_gate_roots2.conf\x00" as *u8)==0 { t7=1 } 88 ck(t7, "T7 a commented-out root is not a root" as *u8, fails) 89 90 w(" fails=" as *u8); wn(fails[0]); w("\n" as *u8) 91 if fails[0]==0 { w("VERDICT: verdict=GREEN (shared artifact-root resolver: finds the real file, invents nothing, fails closed)\n" as *u8); sys_exit(0) } 92 w("VERDICT: verdict=RED\n" as *u8) 93 sys_exit(1) 94 return 1 95}