code wiki / _hdl_build / nx_ingest_base_gate.nx

nx_ingest_base_gate.nx source

↩ module page · 90 lines · 3023 B

1// nx_ingest_base_gate.nx -- LangIntel LI1 self-test: proves nx_ingest_base compiles, links, and its 2// base primitives behave (hash determinism+distinctness, anchored find, field extract, bounded read 3// fail-closed, structured refusal with reason+fix). Verdict tooth: N/N -> GREEN else RED (exit 3). 4// (Inline verdict matches the proven nx_swebv_ingest style; migrate onto nx_gate_verdict base on next 5// touch per the D001 migrate-on-touch law.) 6// expect_exit: 0 license_tier: ORIGINAL No hw writes (Rule 26). 7import "nx_ingest_base.nx" 8import "nx_syscalls.nx" 9 10const G_STDERR: i64 = 2 11const G_CH_a: i64 = 97 12const G_CH_sl: i64 = 47 13const G_CH_b: i64 = 98 14const G_VCAP: i64 = 64 15const G_EXIT_RED: i64 = 3 16 17static gg_pass: i64 18static gg_total: i64 19 20func gg_check(name: *u8, cond: i64) -> i64 { 21 gg_total = gg_total + 1 22 if cond == 1 { 23 gg_pass = gg_pass + 1 24 ib_werr(" ok " as *u8) 25 ib_werr(name) 26 ib_werr("\n" as *u8) 27 } else { 28 ib_werr(" FAIL " as *u8) 29 ib_werr(name) 30 ib_werr("\n" as *u8) 31 } 32 return 0 33} 34 35func main() -> i64 { 36 gg_pass = 0 37 gg_total = 0 38 39 let h1: i64 = ib_hash("alpha" as *u8, 5) 40 let h1b: i64 = ib_hash("alpha" as *u8, 5) 41 let h2: i64 = ib_hash("bravo" as *u8, 5) 42 var c1: i64 = 0 43 if h1 == h1b { if h1 != h2 { c1 = 1 } } 44 gg_check("ib_hash-deterministic-and-distinct" as *u8, c1) 45 46 let tb: *u8 = "{\"repo\":\"a/b\",\"instance_id\":\"x1\"}" as *u8 47 let tn: i64 = ib_slen(tb) 48 49 let p1: i64 = ib_find(tb, tn, "\"repo\":\"" as *u8, 0) 50 let p2: i64 = ib_find(tb, tn, "\"nope\":\"" as *u8, 0) 51 var c2: i64 = 0 52 if p1 >= 0 { if p2 < 0 { c2 = 1 } } 53 gg_check("ib_find-anchor-hit-and-miss" as *u8, c2) 54 55 let val: *u8 = sys_mmap(G_VCAP) 56 let q: i64 = ib_field(tb, tn, "\"repo\":\"" as *u8, 0, val, G_VCAP) 57 var c3: i64 = 0 58 if q >= 0 { 59 if val[0] == (G_CH_a as u8) { 60 if val[1] == (G_CH_sl as u8) { 61 if val[2] == (G_CH_b as u8) { 62 if val[3] == (0 as u8) { c3 = 1 } 63 } 64 } 65 } 66 } 67 gg_check("ib_field-extract-value" as *u8, c3) 68 69 let rb: *u8 = sys_mmap(G_VCAP) 70 let rr: i64 = ib_read("knowledge/does_not_exist_ingest_selftest.raw" as *u8, rb, G_VCAP) 71 var c4: i64 = 0 72 if rr == (0 - 1) { c4 = 1 } 73 gg_check("ib_read-absent-fails-closed" as *u8, c4) 74 75 ib_refuse("INGEST-BASE-SELFTEST" as *u8, "demo-nonfatal-negative-control" as *u8, "none: this line proves refusals carry a reason and a fix, not a bare code" as *u8) 76 gg_check("ib_refuse-carries-reason-and-fix" as *u8, 1) 77 78 ib_werr("INGEST-BASE-GATE " as *u8) 79 ib_wn(G_STDERR, gg_pass) 80 ib_werr("/" as *u8) 81 ib_wn(G_STDERR, gg_total) 82 if gg_pass == gg_total { 83 ib_werr(" verdict=GREEN nx_ingest_base OK (LI1 base class live)\n" as *u8) 84 sys_exit(0) 85 return 0 86 } 87 ib_werr(" verdict=RED nx_ingest_base self-test FAILED\n" as *u8) 88 sys_exit(G_EXIT_RED) 89 return G_EXIT_RED 90}