code wiki / _hdl_build / nx_langintel_trustfence_gate.nx
nx_langintel_trustfence_gate.nx source
↩ module page · 60 lines · 4398 B
1// nx_langintel_trustfence_gate.nx -- LangIntel LI9 WARDEN CI fixture: re-proves the trust fence each run.
2// Self-contained inline fixtures, each carrying its EXPECTED sealed verdict (per the ecosystem law: a neg
3// control must assert the synthesized OUTCOME, never call 'the old code' which rots when fixed). Runs the
4// SHARED ltg_classify_code from nx_trustfence_lib -- so this gate proves the exact classifier the CLI uses.
5// Fixture A permanently guards the master->main rename regression I found on rust-lang/rust#50000.
6// exit 0 = all GREEN, 1 = any FAIL. Read-only, NO exec (Rule 26). license_tier: ORIGINAL
7import "nx_trustfence_lib.nx"
8import "nx_ingest_base.nx"
9import "nx_syscalls.nx"
10import "nx_gate_verdict.nx"
11
12const LTGATE_EXPECT: *u8 = "rust-lang/rust"
13
14static ltg_ctr: *i64
15
16func ltgate_case(js: *u8, expect_code: i64, label: *u8, counters: *i64) -> i64 {
17 let n: i64 = ib_slen(js)
18 let msha: *u8 = sys_mmap(LTG_VCAP)
19 let bfull: *u8 = sys_mmap(LTG_VCAP)
20 let bref: *u8 = sys_mmap(LTG_VCAP)
21 let bdef: *u8 = sys_mmap(LTG_VCAP)
22 let got: i64 = ltg_classify_code(js, n, LTGATE_EXPECT, msha, bfull, bref, bdef)
23 // D001 ANCHOR RUNG 2026-08-06: this gate PASSED and emitted NO verdict= token at all
24 // (probe: run_exit=0 emits_verdict=0), so nx_gate_green could never judge it -- a green gate that
25 // nothing can read is indistinguishable from a gate nobody runs. It already had a proper pass/fail
26 // counter and a per-case helper, so the idiom-H transform applies: convert the HELPER, and the
27 // counter gv_verdict needs is built from the cases that already exist. counters[] stays maintained.
28 // The expected/got detail is PRESERVED on failure -- it is the whole diagnostic value of this gate.
29 var ok: i64 = 0
30 if got == expect_code { ok = 1 }
31 if (ltg_ctr as i64) == 0 { ltg_ctr = gv_ctr() }
32 gv_check(label, ok, ltg_ctr)
33 if ok == 1 {
34 counters[0] = counters[0] + 1
35 ib_wr(1, " (code=" as *u8); ib_wn(1, got); ib_wr(1, ")\n" as *u8)
36 }
37 if ok == 0 {
38 counters[1] = counters[1] + 1
39 ib_wr(1, " expected=" as *u8); ib_wn(1, expect_code); ib_wr(1, " got=" as *u8); ib_wn(1, got); ib_wr(1, "\n" as *u8)
40 }
41 return 0
42}
43
44func main() -> i64 {
45 let c: *i64 = sys_mmap(16) as *i64
46 c[0] = 0
47 c[1] = 0
48 ib_wr(1, "TRUSTFENCE-GATE LI9 adversarial fixtures (inline, self-contained, synthesized outcomes):\n" as *u8)
49 ltgate_case("{\"merged\":true,\"merge_commit_sha\":\"abc123\",\"base\":{\"ref\":\"master\",\"repo\":{\"full_name\":\"rust-lang/rust\",\"default_branch\":\"main\",\"fork\":false}}}" as *u8, LTG_ACCEPT, "accept-canonical-MASTER-with-MAIN-default (rename regression guard)" as *u8, c)
50 ltgate_case("{\"merged\":true,\"merge_commit_sha\":\"def456\",\"base\":{\"ref\":\"main\",\"repo\":{\"full_name\":\"rust-lang/rust\",\"default_branch\":\"main\",\"fork\":false}}}" as *u8, LTG_ACCEPT, "accept-canonical-main" as *u8, c)
51 ltgate_case("{\"merged\":false,\"merge_commit_sha\":null,\"base\":{\"ref\":\"main\",\"repo\":{\"full_name\":\"rust-lang/rust\",\"default_branch\":\"main\",\"fork\":false}}}" as *u8, LTG_REJ_NOT_MERGED, "reject-trojan-unmerged" as *u8, c)
52 ltgate_case("{\"merged\":true,\"merge_commit_sha\":\"deadbeef\",\"base\":{\"ref\":\"main\",\"repo\":{\"full_name\":\"evilcorp-fork/rust\",\"default_branch\":\"main\",\"fork\":true}}}" as *u8, LTG_REJ_NOT_CANONICAL, "reject-trojan-attacker-fork" as *u8, c)
53 ltgate_case("{\"merged\":true,\"merge_commit_sha\":null,\"base\":{\"ref\":\"main\",\"repo\":{\"full_name\":\"rust-lang/rust\",\"default_branch\":\"main\",\"fork\":false}}}" as *u8, LTG_REJ_NO_MERGE_SHA, "reject-trojan-null-merge-sha" as *u8, c)
54 // THE ANCHOR. The old tail printed "TRUSTFENCE-GATE 5/5 GREEN" with NO verdict= token, so every
55 // judge in the estate skipped it. gv_verdict emits the canonical anchored line and is GREEN iff
56 // pass==total -- the same condition as the old c[1]==0.
57 if (ltg_ctr as i64) == 0 { ltg_ctr = gv_ctr() }
58 let rc__g: i64 = gv_verdict("TRUSTFENCE-GATE" as *u8, ltg_ctr, "LI9 adversarial fixtures, inline and self-contained, each asserting its SYNTHESIZED outcome rather than calling the old code; runs the SHARED ltg_classify_code the CLI uses; fixture A permanently guards the master->main rename regression found on rust-lang/rust#50000" as *u8)
59 return rc__g
60}