code wiki / (root) / nx_research_flow_gate.nx

nx_research_flow_gate.nx source

↩ module page · 155 lines · 6483 B

1// nx_research_flow_gate.nx -- TEETH for the rivers-to-ocean research surface. 2// 3// THE DEFECT CLASS IT EXISTS TO CATCH: an index and the pages it indexes drifting apart. A brief gets 4// published but never registered (invisible to the ocean and to every miner), or a row is registered 5// pointing at a page that was never written (the ocean advertises a 404). Both read as success from 6// one side. This is the "artifacts never placed where consumers look" class, made mechanical. 7// 8// THE PARTITION CLAIM: for every non-STUB row in the `resbrief-` plane there must be a served page at 9// sites/nishifamily/<area>/<slug>.html, derived from the SAME two columns the ocean derives its links 10// from -- so a row that renders a link here is a row whose target is proven to exist. 11// STUB rows are corpus-only by declaration and are correctly NOT expected on disk. 12// 13// T4 is a BITE tooth: the presence detector must FIRE on a path that does not exist and stay SILENT on 14// one that does. Without it, a gate that always returns "present" would pass this file green forever -- 15// a green-before-the-defect-exists gate proves nothing (nx_gate_bite doctrine). 16// 17// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 18import "nx_gate_verdict.nx" 19import "nx_store_seed_lib.nx" 20import "nx_seg_store.nx" 21import "nx_syscalls.nx" 22 23const RF_PLANE: *u8 = "knowledge/store/resbrief-" 24const RF_OCEAN: *u8 = "sites/nishifamily/wiki/research.html" 25const RF_ROOT: *u8 = "sites/nishifamily/" 26const RF_RCAP: i64 = 262144 27const RF_PATHCAP: i64 = 1024 28const RF_FLAGB: i64 = 64 29const RF_SPB: i64 = 256 30const RF_NL: i64 = 10 31const RF_TAB: i64 = 9 32const RF_MAXCOL: i64 = 16 33const RF_PAIR: i64 = 2 34const RF_C_AREA: i64 = 1 35const RF_C_SLUG: i64 = 2 36const RF_C_STATUS: i64 = 5 37const RF_NCOL: i64 = 8 38 39func rf_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 40func rf_slice_eqs(q: *u8, a: i64, b: i64, s: *u8) -> i64 { 41 let sn: i64 = rf_slen(s) 42 if b - a != sn { return 0 } 43 var i: i64 = 0 44 while i < sn { if q[a+i] != s[i] { return 0 } i = i + 1 } 45 return 1 46} 47func rf_cols(q: *u8, ls: i64, le: i64, sp: *i64) -> i64 { 48 var c: i64 = 0 49 var p: i64 = ls 50 while c < RF_MAXCOL { 51 var e: i64 = p 52 var s: i64 = 1 53 while s == 1 { if e >= le { s = 0 } else { if q[e] == (RF_TAB as u8) { s = 0 } else { e = e + 1 } } } 54 sp[c*RF_PAIR] = p 55 sp[c*RF_PAIR+1] = e 56 c = c + 1 57 if e >= le { return c } 58 p = e + 1 59 } 60 return c 61} 62func rf_cat_slice(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64 { 63 var oo: i64 = o 64 var i: i64 = a 65 while i < b { d[oo] = q[i]; oo = oo + 1; i = i + 1 } 66 return oo 67} 68// 1 = the file exists and is readable. THE DETECTOR UNDER TEST (T4 bites it). 69func rf_exists(path: *u8) -> i64 { 70 let fd: i64 = sys_openat_rd(path) 71 if fd < 0 { return 0 } 72 sys_close(fd) 73 return 1 74} 75 76func main() -> i64 { 77 let ctr: *i64 = gv_ctr() 78 gv_head("nx_research_flow_gate -- every registered brief must have a served page, and the ocean must be complete" as *u8) 79 80 let buf: *u8 = sts_mm(RF_RCAP) 81 let flags: *i64 = sts_mm(RF_FLAGB) as *i64 82 let n: i64 = sts_load_honest(RF_PLANE, buf, RF_RCAP, flags) 83 84 gv_check("T1 resbrief- plane is seeded and readable" as *u8, (n > 0) as i64, ctr) 85 86 // A plane that declares more rows than it can return is silently under-reporting the library. 87 var t2: i64 = 0 88 if flags[0] == flags[1] { if flags[2] == 0 { t2 = 1 } } 89 gv_check("T2 declared == loaded and nothing reachable past the count (no silent truncation)" as *u8, t2, ctr) 90 91 // T3: the partition -- every non-STUB row resolves to a served page. 92 let sp: *i64 = sts_mm(RF_SPB) as *i64 93 let path: *u8 = sts_mm(RF_PATHCAP) 94 var checked: i64 = 0 95 var missing: i64 = 0 96 var i: i64 = 0 97 while i < n { 98 var le: i64 = i 99 var s: i64 = 1 100 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (RF_NL as u8) { s = 0 } else { le = le + 1 } } } 101 if le > i { 102 let nc: i64 = rf_cols(buf, i, le, sp) 103 if nc >= RF_NCOL { 104 let sa: i64 = sp[RF_C_STATUS*RF_PAIR] 105 let sb: i64 = sp[RF_C_STATUS*RF_PAIR+1] 106 if rf_slice_eqs(buf, sa, sb, "STUB" as *u8) == 0 { 107 var o: i64 = ss_cat(path, 0, RF_ROOT) 108 o = rf_cat_slice(path, o, buf, sp[RF_C_AREA*RF_PAIR], sp[RF_C_AREA*RF_PAIR+1]) 109 path[o] = 47 as u8 110 o = o + 1 111 o = rf_cat_slice(path, o, buf, sp[RF_C_SLUG*RF_PAIR], sp[RF_C_SLUG*RF_PAIR+1]) 112 o = ss_cat(path, o, ".html" as *u8) 113 path[o] = 0 as u8 114 checked = checked + 1 115 if rf_exists(path) == 0 { 116 missing = missing + 1 117 gv_puts(" MISSING PAGE for a registered brief: " as *u8) 118 gv_puts(path) 119 gv_puts("\n" as *u8) 120 } 121 } 122 } 123 } 124 i = le + 1 125 } 126 gv_check("T3 every non-STUB registered brief has a served page on disk" as *u8, (missing == 0) as i64, ctr) 127 128 // T4 BITE: the presence detector must be able to FAIL. A detector that always says "present" 129 // would make T3 vacuous and green forever. 130 let bad: i64 = rf_exists("sites/nishifamily/product/__nx_flow_gate_absent_probe__.html" as *u8) 131 let good: i64 = rf_exists(RF_OCEAN) 132 // bite contract: fires on bad (absent -> 0 -> flagged=1), silent on good (present -> 1 -> flagged=0) 133 var fired_bad: i64 = 0 134 if bad == 0 { fired_bad = 1 } 135 var fired_good: i64 = 0 136 if good == 0 { fired_good = 1 } 137 gv_bite("T4 presence detector fires on an absent page and is silent on a present one" as *u8, fired_bad, fired_good, ctr) 138 139 // T5: the ocean itself is on disk -- an index nobody can read is not an index. 140 gv_check("T5 the ocean page exists at sites/nishifamily/wiki/research.html" as *u8, rf_exists(RF_OCEAN), ctr) 141 142 gv_puts("\n rows_checked=" as *u8) 143 gv_num(checked) 144 gv_puts(" missing=" as *u8) 145 gv_num(missing) 146 gv_puts(" declared=" as *u8) 147 gv_num(flags[0]) 148 gv_puts(" loaded=" as *u8) 149 gv_num(flags[1]) 150 gv_puts("\n" as *u8) 151 152 let rc: i64 = gv_verdict("RESEARCH-FLOW" as *u8, ctr, "rivers and ocean agree: every registered brief resolves to a served page" as *u8) 153 sys_exit(rc) 154 return rc 155}