code wiki / _hdl_build / nx_capgraph_edges_gate.nx

nx_capgraph_edges_gate.nx source

↩ module page · 107 lines · 5519 B

1// nx_capgraph_edges_gate.nx -- the gate for nx_capgraph_edges_lib (the MEASURING organ's core). 2// 3// WHY THIS EXISTS: the organ that measures capability LEVELS had no gate of its own, so by its own 4// ladder (L5) it could claim at most level 2 (WORKS), never 3 (GATED). An instrument that grades others 5// must submit to its own grading. Every tooth below is a MATCHED PAIR -- the rule fires, AND a control 6// where it must not -- so none can pass by a constant. 7// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 8import "nx_capgraph_edges_lib.nx" 9 10func ceg_t(name: *u8, cond: i64, ctr: *i64) { 11 if cond == 1 { 12 cax_puts(" ok " as *u8) 13 ctr[0] = ctr[0] + 1 14 } else { 15 cax_puts(" FAIL " as *u8) 16 } 17 cax_puts(name) 18 cax_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 cax_puts("=== nx_capgraph_edges_gate: the measuring organ submits to its own grading ===\n" as *u8) 27 ce_init() 28 29 // ---- source-vs-non-source classification (the "23 dead paths" retraction) ---- 30 ceg_t("T1 .nx source is recognised" as *u8, ce_is_nx("runtime/nx_foo.nx" as *u8) == 1, ctr) 31 ceg_t("T1b NEG-CONTROL: a .js evidence row is NOT a source (carries no imports)" as *u8, ce_is_nx("sites/app.v2.js" as *u8) == 0, ctr) 32 ceg_t("T1c NEG-CONTROL: a .tsv evidence row is NOT a source" as *u8, ce_is_nx("knowledge/x.tsv" as *u8) == 0, ctr) 33 34 // ---- basename + join (multi-root resolution depends on both) ---- 35 ce_basename("runtime/_hdl_build/nx_bar.nx" as *u8) 36 ceg_t("T2 basename strips every directory level" as *u8, cg_streq(ce_scr2, "nx_bar.nx" as *u8) == 1, ctr) 37 ce_basename("nx_bare.nx" as *u8) 38 ceg_t("T2b NEG-CONTROL: a bare name is unchanged" as *u8, cg_streq(ce_scr2, "nx_bare.nx" as *u8) == 1, ctr) 39 ce_join("buildroot/" as *u8, "runtime/nx_z.nx" as *u8) 40 ceg_t("T2c join builds the prefixed path" as *u8, cg_streq(ce_path, "buildroot/runtime/nx_z.nx" as *u8) == 1, ctr) 41 42 // ---- OWNERSHIP: the determinism fix. Shared must NOT be first-wins. ---- 43 let da: i64 = ce_dom_add("alpha" as *u8) 44 let db: i64 = ce_dom_add("beta" as *u8) 45 ce_own_add("nx_solo.nx" as *u8, da) 46 ceg_t("T3 a single claimant OWNS the module" as *u8, ce_own_find("nx_solo.nx" as *u8) == da, ctr) 47 ce_own_add("nx_solo.nx" as *u8, da) 48 ceg_t("T3b NEG-CONTROL: the SAME domain claiming twice does NOT make it shared" as *u8, ce_own_find("nx_solo.nx" as *u8) == da, ctr) 49 ce_own_add("nx_solo.nx" as *u8, db) 50 ceg_t("T3c a SECOND domain marks it SHARED, never first-wins (kills order-dependence)" as *u8, ce_own_find("nx_solo.nx" as *u8) == CE_SHARED, ctr) 51 ce_own_add("nx_solo.nx" as *u8, da) 52 ceg_t("T3d SHARED is STICKY -- a later claim cannot take ownership back" as *u8, ce_own_find("nx_solo.nx" as *u8) == CE_SHARED, ctr) 53 54 // ---- EDGES: self-edge refusal + dedup ---- 55 let e0: i64 = ce_ne 56 ce_edge_add(da, da) 57 ceg_t("T4 a self-edge is REFUSED (a domain is not its own prerequisite)" as *u8, ce_ne == e0, ctr) 58 ce_edge_add(da, db) 59 ceg_t("T4b NEG-CONTROL: a genuine cross-domain edge IS added" as *u8, ce_ne == e0 + 1, ctr) 60 ce_edge_add(da, db) 61 ceg_t("T4c the same edge twice is deduped" as *u8, ce_ne == e0 + 1, ctr) 62 ce_edge_add(db, da) 63 ceg_t("T4d NEG-CONTROL: the REVERSE edge is a different edge and IS added (cycles are real)" as *u8, ce_ne == e0 + 2, ctr) 64 65 // ---- INFRA edges dedup ---- 66 let i0: i64 = ce_nie 67 ce_infra_add(0, da) 68 ce_infra_add(0, da) 69 ceg_t("T5 infra edge deduped" as *u8, ce_nie == i0 + 1, ctr) 70 ce_infra_add(0, db) 71 ceg_t("T5b NEG-CONTROL: a different dependent IS a distinct infra edge" as *u8, ce_nie == i0 + 2, ctr) 72 73 // ---- SUBSTRATE detection: the round-7 correction. Raw frequency ranks the wrong thing. ---- 74 ce_enc_add("nx_onedomain.nx" as *u8, da) 75 ce_enc_add("nx_onedomain.nx" as *u8, da) 76 var idx1: i64 = 0 - 1 77 var z: i64 = 0 78 while z < ce_nenc { 79 if cg_streq(((ce_enc as i64) + z * CE_NAMEW) as *u8, "nx_onedomain.nx" as *u8) == 1 { idx1 = z } 80 z = z + 1 81 } 82 ceg_t("T6 a module imported by ONE domain stays attributable to that domain" as *u8, ce_encdom[idx1] == da, ctr) 83 ceg_t("T6b its hit count accumulates across encounters" as *u8, ce_enccnt[idx1] == 2, ctr) 84 ce_enc_add("nx_onedomain.nx" as *u8, db) 85 ceg_t("T6c a SECOND importing domain marks it SUBSTRATE -- never safe to claim" as *u8, ce_encdom[idx1] == CE_SHARED, ctr) 86 ceg_t("T6d SUBSTRATE is sticky under further hits (claiming it would fabricate edges to all)" as *u8, ce_encdom[idx1] == CE_SHARED, ctr) 87 88 // ---- ownership-coverage accounting ---- 89 let before_owned: i64 = ce_enc_owned() 90 ce_enc_add("nx_unowned_thing.nx" as *u8, da) 91 ceg_t("T7 an UNOWNED module does not raise the owned count" as *u8, ce_enc_owned() == before_owned, ctr) 92 ce_own_add("nx_now_owned.nx" as *u8, da) 93 ce_enc_add("nx_now_owned.nx" as *u8, da) 94 ceg_t("T7b NEG-CONTROL: an OWNED module DOES raise it" as *u8, ce_enc_owned() == before_owned + 1, ctr) 95 96 cg_gate_log("knowledge/status/capgraph_edges_gate.log" as *u8, "CAPGRAPHEDGESGATE" as *u8, ctr[0], ctr[1]) 97 cax_puts("\nCAPGRAPH-EDGES-GATE " as *u8) 98 cax_puti(ctr[0]) 99 cax_puts("/" as *u8) 100 cax_puti(ctr[1]) 101 if ctr[0] == ctr[1] { 102 cax_puts(" GREEN\n" as *u8) 103 return 0 104 } 105 cax_puts(" RED\n" as *u8) 106 return 1 107}