code wiki / (root) / nx_gate_green_test.nx

nx_gate_green_test.nx source

↩ module page · 82 lines · 4716 B

1// nx_gate_green_test.nx -- KATs for the shared last-verdict-line judge (GATE). 2// T3 is the construction that caught the scorecard's false-green bug: the LAST anchor line says 3// rc=1, a LATER unrelated line says rc=0 -- the judge must say RED (the buggy whole-tail window 4// said GREEN). 5// 6// seq585 (2026-07-23): THIS KAT USED TO CERTIFY THE BUG. Its case 4 read 7// // 4: anchor absent = ABSENT = red 8// and asserted 0 -- pinning as INTENDED the exact conflation that made 953 runnable, genuinely 9// PASSING gates machine-read as NOT-GREEN. The 1/0 cases are KEPT (they prove the wrapper 10// contract is unbroken for all 14 live call sites, rule 19); T7-T13 are the discriminating 11// teeth: an absent anchor must read UNJUDGEABLE, a missing file UNREADABLE, and neither may 12// equal RED. MIGRATE-ON-TOUCH (D001): this gate now emits via nx_gate_verdict, so the judge's 13// own test is no longer one of the unjudgeable gates it exists to protect against. 14// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 15import "nx_str.nx" 16import "nx_syscalls.nx" 17import "nx_gate_verdict.nx" 18import "nx_gate_green.nx" 19 20// The contract values, restated FROM THE TEST SIDE on purpose: a KAT that imported the lib's 21// own constants could only ever agree with itself. 22const GT_GREEN: i64 = 1 23const GT_RED: i64 = 0 24const GT_UNJUDGEABLE: i64 = 0 - 1 25const GT_UNREADABLE: i64 = 0 - 2 26const GT_NOSUCH: *u8 = "knowledge/status/nx_gate_green_no_such_file.log" 27 28func gt_green_is(log: *u8, anchor: *u8, pat: *u8, want: i64) -> i64 { 29 var t: i64 = 0 30 if gg_line_green(log, nx_str_len(log), anchor, pat) == want { t = 1 } 31 return t 32} 33func gt_judge(log: *u8, anchor: *u8, pat: *u8) -> i64 { 34 return gg_line_judge(log, nx_str_len(log), anchor, pat) 35} 36func gt_judge_is(log: *u8, anchor: *u8, pat: *u8, want: i64) -> i64 { 37 var t: i64 = 0 38 if gt_judge(log, anchor, pat) == want { t = 1 } 39 return t 40} 41 42func main() -> i64 { 43 let ctr: *i64 = gv_ctr() 44 gv_head("nx_gate_green KAT -- last-verdict-line judging + tri-state absence (seq585)") 45 46 // ---- 1/0 wrapper contract: MUST BE UNCHANGED (rule 19; 14 live call sites) 47 gv_check("T1 last-line-green", gt_green_is("STEP a rc=1\nGATE x rc=0\n", "GATE", "rc=0", 1), ctr) 48 gv_check("T2 last-line-red", gt_green_is("GATE x rc=0\nGATE x rc=1\n", "GATE", "rc=0", 0), ctr) 49 gv_check("T3 no-tail-bleed (the original false-green)", gt_green_is("GATE x rc=1\nOTHER y rc=0\n", "GATE", "rc=0", 0), ctr) 50 gv_check("T4 absent still clamps to 0 for legacy callers", gt_green_is("OTHER y rc=0\n", "GATE", "rc=0", 0), ctr) 51 gv_check("T5 eof-line judged", gt_green_is("GATE x rc=1\nGATE x rc=0", "GATE", "rc=0", 1), ctr) 52 gv_check("T6 last-wins", gt_green_is("GATE x rc=0\nnoise\nGATE x rc=7\n", "GATE", "rc=0", 0), ctr) 53 54 // ---- tri-state: the seq585 teeth 55 gv_check("T7 judge GREEN", gt_judge_is("GATE x rc=0\n", "GATE", "rc=0", GT_GREEN), ctr) 56 gv_check("T8 judge RED on a real failure", gt_judge_is("GATE x rc=1\n", "GATE", "rc=0", GT_RED), ctr) 57 gv_check("T9 judge UNJUDGEABLE on absent anchor (was RED)", gt_judge_is("OTHER y rc=0\n", "GATE", "rc=0", GT_UNJUDGEABLE), ctr) 58 59 // T10 = THE DISCRIMINATING TOOTH, behavioural not a const tautology: the value returned for 60 // an ABSENT anchor must DIFFER from the value returned for a REAL failure. Against the old 61 // 2-valued judge both were 0 and this tooth FAILS -- that is what makes it a neg-control. 62 var t10: i64 = 0 63 if gt_judge("OTHER y rc=0\n", "GATE", "rc=0") != gt_judge("GATE x rc=1\n", "GATE", "rc=0") { t10 = 1 } 64 gv_check("T10 absent != failure (the seq585 conflation cannot return)", t10, ctr) 65 66 // T11 = a real 953-shaped gate: it PASSES, exits 0, prints its own GREEN, but no verdict=. 67 gv_check("T11 passing anchor-free gate reads UNJUDGEABLE, not RED", gt_judge_is(" T1 thing: PASS\n T2 other: PASS\n AA-GATE 2/2 GREEN\n", "verdict=", "GREEN", GT_UNJUDGEABLE), ctr) 68 69 // T12 = a missing file is its own state, distinct from present-but-silent. 70 var t12: i64 = 0 71 if gg_gate_judge(GT_NOSUCH, "verdict=" as *u8, "GREEN" as *u8) == GT_UNREADABLE { t12 = 1 } 72 gv_check("T12 missing file = UNREADABLE, distinct from UNJUDGEABLE", t12, ctr) 73 74 // T13 = NEG-CONTROL for rule 19: the file wrapper must still fold every non-green state to 75 // 0, or the comms censuses' missing-log controls would silently change meaning. 76 var t13: i64 = 0 77 if gg_gate_green(GT_NOSUCH, "verdict=" as *u8, "GREEN" as *u8) == 0 { t13 = 1 } 78 gv_check("T13 NEG-CONTROL wrapper folds UNREADABLE to 0 (rule 19 held)", t13, ctr) 79 80 sys_exit(gv_verdict("GATE-GREEN-KAT", ctr, "tri-state: absence is named, never silently RED")) 81 return 0 82}