code wiki / _hdl_build / nx_gateorder_gate.nx

nx_gateorder_gate.nx source

↩ module page · 93 lines · 5778 B

1// nx_gateorder_gate.nx -- teeth for the gate-integrity classifier. 2// 3// This gate exists because the classifier it guards ALREADY produced a false accusation once: an 4// ordering verdict derived from textual position flagged seven innocent gates, one of them a crown 5// jewel, and the debt was filed before the check. The teeth below now pin the CORRECTED contract, and 6// T4 is a REVERT-DETECTOR: if anyone re-adds an ordering verdict, it turns RED. 7// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 8import "nx_gateorder_lib.nx" 9 10func gog_t(name: *u8, cond: i64, ctr: *i64) { 11 if cond == 1 { 12 go_puts(" ok " as *u8) 13 ctr[0] = ctr[0] + 1 14 } else { 15 go_puts(" FAIL " as *u8) 16 } 17 go_puts(name) 18 go_puts("\n" as *u8) 19 ctr[1] = ctr[1] + 1 20} 21 22func main(argc: i64, argv: *i64) -> i64 { 23 var ctr: *i64 = sys_mmap(64) as *i64 24 ctr[0] = 0 25 ctr[1] = 0 26 go_puts("=== nx_gateorder_gate: the auditor submits to its own audit ===\n" as *u8) 27 28 let noemit: *u8 = " cg_t(zT1 az, c, ctr)\n cg_t(zT2 bz, c, ctr)\n" as *u8 29 gog_t("T1 a gate with teeth but NO emit token => NO-EMIT" as *u8, go_classify(noemit, go_strlen(noemit)) == GO_NOEMIT, ctr) 30 31 let withlog: *u8 = " cg_t(zT1 az, c, ctr)\n cg_gate_log(p, t, a, b)\n" as *u8 32 gog_t("T1b NEG-CONTROL: a gate_log call => emit PRESENT, not NO-EMIT" as *u8, go_classify(withlog, go_strlen(withlog)) == GO_LATE, ctr) 33 34 let raw: *u8 = " sys_openat_append(p, m)\n" as *u8 35 gog_t("T2 a RAW sys_openat_append also counts as an emit" as *u8, go_classify(raw, go_strlen(raw)) == GO_LATE, ctr) 36 37 // ---- THE REVERT-DETECTOR ---- 38 // Same two lines, opposite order. The OLD classifier called the first EMIT-EARLY and the second ok. 39 // The corrected one must call them IDENTICAL, because textual position cannot decide execution order. 40 let emitFirst: *u8 = " cg_gate_log(p)\n cg_t(zT1 az, c, ctr)\n" as *u8 41 let emitLast: *u8 = " cg_t(zT1 az, c, ctr)\n cg_gate_log(p)\n" as *u8 42 gog_t("T3 emit-first and emit-last classify THE SAME (order is not judged)" as *u8, go_classify(emitFirst, go_strlen(emitFirst)) == go_classify(emitLast, go_strlen(emitLast)), ctr) 43 gog_t("T4 REVERT-DETECTOR: emit-first must NOT be reported as a defect" as *u8, go_classify(emitFirst, go_strlen(emitFirst)) != GO_NOEMIT, ctr) 44 gog_t("T4b REVERT-DETECTOR: no GO_EARLY verdict may ever be returned" as *u8, go_classify(emitFirst, go_strlen(emitFirst)) != GO_EARLY, ctr) 45 46 // ---- the exact shapes that produced the seven false accusations ---- 47 let helperdef: *u8 = "func g_log(s: *u8) -> i64 {\n let fd: i64 = sys_openat_append(q, m)\n}\n cg_t(zT1 az, c, ctr)\n" as *u8 48 gog_t("T5 a HELPER DEFINITION containing the token is NOT a defect" as *u8, go_classify(helperdef, go_strlen(helperdef)) != GO_EARLY, ctr) 49 let fixture: *u8 = " let pfd: i64 = sys_openat_append(subs, 420)\n cg_t(zT9 zz, c, ctr)\n" as *u8 50 gog_t("T5b an append to a TEST FIXTURE is NOT a defect" as *u8, go_classify(fixture, go_strlen(fixture)) != GO_EARLY, ctr) 51 52 // ---- filename filter ---- 53 gog_t("T6 *_gate.nx is recognised" as *u8, go_ends_gate_nx("nx_foo_gate.nx" as *u8) == 1, ctr) 54 gog_t("T6b NEG-CONTROL: a non-gate source is NOT" as *u8, go_ends_gate_nx("nx_foo.nx" as *u8) == 0, ctr) 55 gog_t("T6c NEG-CONTROL: a short name does not over-read" as *u8, go_ends_gate_nx("a.nx" as *u8) == 0, ctr) 56 57 // ---- BEHAVIOURAL-VERIFICATION PARSERS (nx_gateverify depends entirely on these) ---- 58 let ratio: *i64 = sys_mmap(64) as *i64 59 let foot: *u8 = "\nCAPGRAPH-DERIVE-GATE 41/41 GREEN\n" as *u8 60 gog_t("T7 parses a gate footer ratio" as *u8, go_last_ratio(foot, go_strlen(foot), ratio) == 1, ctr) 61 gog_t("T7b passed side" as *u8, ratio[0] == 41, ctr) 62 gog_t("T7c total side" as *u8, ratio[1] == 41, ctr) 63 let red: *u8 = "GATE 40/41 RED\n" as *u8 64 go_last_ratio(red, go_strlen(red), ratio) 65 gog_t("T7d a RED footer parses its unequal counts" as *u8, ratio[0] == 40, ctr) 66 let multi: *u8 = "note 1/2 then final 7/9 GREEN\n" as *u8 67 go_last_ratio(multi, go_strlen(multi), ratio) 68 gog_t("T7e takes the LAST ratio, not an earlier one in banner text" as *u8, ratio[0] == 7, ctr) 69 let noratio: *u8 = "GATE all good\n" as *u8 70 gog_t("T7f NEG-CONTROL: no ratio => 0, never a fabricated number" as *u8, go_last_ratio(noratio, go_strlen(noratio), ratio) == 0, ctr) 71 72 let logline: *u8 = "CAPGRAPHDERIVEGATE verdict=GREEN passed=41 total=41\n" as *u8 73 gog_t("T8 reads passed= from a log line" as *u8, go_kv_num(logline, go_strlen(logline), "passed=" as *u8) == 41, ctr) 74 gog_t("T8b reads total=" as *u8, go_kv_num(logline, go_strlen(logline), "total=" as *u8) == 41, ctr) 75 gog_t("T8c NEG-CONTROL: an absent key returns -1, NOT 0" as *u8, go_kv_num(logline, go_strlen(logline), "nosuch=" as *u8) == (0 - 1), ctr) 76 let twolines: *u8 = "G verdict=RED passed=23 total=25\nG verdict=GREEN passed=41 total=41\n" as *u8 77 gog_t("T8d takes the LAST occurrence (newest recorded verdict)" as *u8, go_kv_num(twolines, go_strlen(twolines), "passed=" as *u8) == 41, ctr) 78 79 // ⚠LAST ACT BEFORE THE FOOTER. nx_gateverify reported this gate as NO-LOG the first time it was 80 // pointed at it -- my newest instrument caught a missing record in my newest gate. Anything appended 81 // to this gate later must go ABOVE this line, or the record will disagree with the run. 82 go_gate_log("knowledge/status/gateorder_gate.log" as *u8, "GATEORDERGATE" as *u8, ctr[0], ctr[1]) 83 go_puts("\nGATEORDER-GATE " as *u8) 84 go_puti(ctr[0]) 85 go_puts("/" as *u8) 86 go_puti(ctr[1]) 87 if ctr[0] == ctr[1] { 88 go_puts(" GREEN\n" as *u8) 89 return 0 90 } 91 go_puts(" RED\n" as *u8) 92 return 1 93}