code wiki / _hdl_build / nx_wiki_walk_gate.nx

nx_wiki_walk_gate.nx source

↩ module page · 206 lines · 10204 B

1// nx_wiki_walk_gate.nx -- REFEREE for the walkability metrics (modeled on 2// nx_wiki_exceed_gate). Proves nx_wiki_walk_metrics MEASURES honestly + can SEE 3// every case (no fabricated greens), via 3 hand-built framed-corpus fixtures: 4// 5// HEALTHY (3 pages, all reciprocally cross-linked, start reachable): 6// reciprocity==100, orphans==0, dead-ends==0, reachability==100. 7// SPARSE (3 pages, NO internal links at all): 8// orphans high (>=66%), dead-ends==100%, reachability==33% (start only) 9// -- proves full SENSITIVITY (it does NOT always report healthy). 10// ONE-AXIS (HEALTHY but one page's outbound link removed -> exactly ONE dead-end 11// and the reciprocity drops): dead-ends moves 0 -> >0 while orphans STAY 12// 0 -- proves per-axis SPECIFICITY (greens can't be fabricated; moving 13// one structural fact moves exactly the axes it should, not all-or-none). 14// LIVE (the real live corpus): metrics RUN and assert the spine MEETS S-class 15// structure -- orphans==0 AND dead-ends==0 AND reachability==100. 16// 17// GREEN iff all checks hold. Evidence -> knowledge/status/wiki_walk_gate.log. 18// Sovereign: imports the organ + nx_framed_append + nx_syscalls. license_tier: ORIGINAL 19import "nx_wiki_walk_metrics.nx" 20import "nx_framed_append.nx" 21import "nx_syscalls.nx" 22 23const WG_LOG: *u8 = "knowledge/status/wiki_walk_gate.log" 24const WG_LIVE_CORPUS: *u8 = "knowledge/status/ims_live_corpus.txt" 25const WG_LINKS: *u8 = "knowledge/registry/wiki_links.tsv" 26const WG_RECCAP: i64 = 512 27 28func wg_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != 0 as u8 { dst[off + i] = s[i]; i = i + 1 } return off + i } 29func wg_catn(dst: *u8, off: i64, v: i64) -> i64 { 30 var m: i64 = v; var o: i64 = off 31 if m < 0 { m = 0 - m } 32 let t: *u8 = sys_mmap(28); var k: i64 = 0 33 if m == 0 { t[0] = 48 as u8; k = 1 } 34 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 35 var i: i64 = 0 36 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 37 return o + k 38} 39func wg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != 0 as u8 { n = n + 1 } return n } 40 41// write a NUL-terminated string to a fresh file. returns 0/-1. 42func wg_write_file(path: *u8, content: *u8, clen: i64) -> i64 { 43 let fd: i64 = sys_openat_wr(path, 0x1a4) 44 if fd < 0 { return 0 - 1 } 45 sys_write(fd, content, clen) 46 sys_close(fd) 47 return 0 48} 49func wg_tmppath(out: *u8, stem: *u8, epoch: i64, pid: i64) -> i64 { 50 var o: i64 = 0 51 o = wg_cat(out, o, stem); o = wg_catn(out, o, epoch); o = wg_cat(out, o, "." as *u8) 52 o = wg_catn(out, o, pid); o = wg_cat(out, o, ".txt" as *u8) 53 out[o] = 0 as u8 54 return o 55} 56 57// emit ONE framed page: "###PAGE <url> <blen>\n<body>" into dst at off. returns new off. 58func wg_emit_page(dst: *u8, off: i64, url: *u8, body: *u8) -> i64 { 59 let blen: i64 = wg_slen(body) 60 var o: i64 = off 61 o = wg_cat(dst, o, "###PAGE " as *u8) 62 o = wg_cat(dst, o, url) 63 o = wg_cat(dst, o, " " as *u8) 64 o = wg_catn(dst, o, blen) 65 dst[o] = 0x0A as u8; o = o + 1 // '\n' 66 o = wg_cat(dst, o, body) 67 return o 68} 69 70func wg_row(name: *u8, pass: i64) -> i64 { 71 let buf: *u8 = sys_mmap(WG_RECCAP + 16) 72 var o: i64 = 0 73 o = wg_cat(buf, o, "WGATE row=\x00" as *u8); o = wg_cat(buf, o, name) 74 if pass == 1 { o = wg_cat(buf, o, " verdict=PASS\x00" as *u8) } else { o = wg_cat(buf, o, " verdict=FAIL\x00" as *u8) } 75 buf[o] = 0 as u8 76 fa_appendz(WG_LOG, buf, WG_RECCAP) 77 sys_write(1, " \x00" as *u8, 2) 78 var n: i64 = 0; while name[n] != 0 as u8 { n = n + 1 } sys_write(1, name, n) 79 if pass == 1 { sys_write(1, " PASS\n\x00" as *u8, 6) } else { sys_write(1, " FAIL\n\x00" as *u8, 6) } 80 return 0 81} 82 83func main() -> i64 { 84 let epoch: i64 = sys_now_realtime_sec() 85 let pid: i64 = __syscall(39, 0, 0, 0, 0, 0, 0) 86 let outs: *i64 = sys_mmap(256) as *i64 87 88 // ---- build 3 framed-corpus fixtures ---- 89 let pf: *u8 = sys_mmap(256); wg_tmppath(pf, "/tmp/wg_healthy." as *u8, epoch, pid) 90 let ps: *u8 = sys_mmap(256); wg_tmppath(ps, "/tmp/wg_sparse." as *u8, epoch, pid) 91 let po: *u8 = sys_mmap(256); wg_tmppath(po, "/tmp/wg_oneaxis." as *u8, epoch, pid) 92 93 // HEALTHY: start <-> charter <-> nist_stem, fully reciprocal triangle, all reachable. 94 let hbuf: *u8 = sys_mmap(8192) 95 var ho: i64 = 0 96 ho = wg_emit_page(hbuf, ho, "/wiki/start.html" as *u8, "<p>see [[charter]] and [[nist_stem]]</p>" as *u8) 97 ho = wg_emit_page(hbuf, ho, "/wiki/charter.html" as *u8, "<p>see [[start]] and [[nist_stem]]</p>" as *u8) 98 ho = wg_emit_page(hbuf, ho, "/wiki/nist_stem.html" as *u8, "<p>see [[start]] and [[charter]]</p>" as *u8) 99 hbuf[ho] = 0 as u8 100 wg_write_file(pf, hbuf, ho) 101 102 // SPARSE: 3 pages, ZERO internal links. 103 let sbuf: *u8 = sys_mmap(8192) 104 var so: i64 = 0 105 so = wg_emit_page(sbuf, so, "/wiki/start.html" as *u8, "<p>nothing links anywhere</p>" as *u8) 106 so = wg_emit_page(sbuf, so, "/wiki/charter.html" as *u8, "<p>also nothing here</p>" as *u8) 107 so = wg_emit_page(sbuf, so, "/wiki/nist_stem.html" as *u8, "<p>still nothing</p>" as *u8) 108 sbuf[so] = 0 as u8 109 wg_write_file(ps, sbuf, so) 110 111 // ONE-AXIS: HEALTHY but nist_stem's outbound links removed -> nist_stem is a 112 // dead-end (out==0) yet still has inbound (start+charter link to it) so it is 113 // NOT an orphan. Exactly the dead-end axis moves; orphans stay 0. 114 let obuf: *u8 = sys_mmap(8192) 115 var oo: i64 = 0 116 oo = wg_emit_page(obuf, oo, "/wiki/start.html" as *u8, "<p>see [[charter]] and [[nist_stem]]</p>" as *u8) 117 oo = wg_emit_page(obuf, oo, "/wiki/charter.html" as *u8, "<p>see [[start]] and [[nist_stem]]</p>" as *u8) 118 oo = wg_emit_page(obuf, oo, "/wiki/nist_stem.html" as *u8, "<p>a leaf page with no outbound links</p>" as *u8) 119 obuf[oo] = 0 as u8 120 wg_write_file(po, obuf, oo) 121 122 // ---- measure each ---- 123 var hh: i64 = 0 124 if wm_measure(pf, WG_LINKS, outs) == WM_OK { 125 // healthy: N==3, reciprocity==100, orphans==0, dead-ends==0, reachability==100 126 if outs[0] == 3 { if outs[2] == 100 { if outs[11] == 0 { if outs[12] == 0 { if outs[7] == 100 { hh = 1 } } } } } 127 } 128 let h_recip: i64 = outs[2]; let h_orph: i64 = outs[11]; let h_dead: i64 = outs[12]; let h_reach: i64 = outs[7] 129 130 var ss: i64 = 0 131 if wm_measure(ps, WG_LINKS, outs) == WM_OK { 132 // sparse: dead-ends==100% (all 3 out==0), reachability==33% (start only), orphans>=2 133 if outs[4] == 100 { if outs[7] < 50 { if outs[11] >= 2 { ss = 1 } } } 134 } 135 let s_dead: i64 = outs[4]; let s_reach: i64 = outs[7]; let s_orph: i64 = outs[11] 136 137 var aa: i64 = 0 138 if wm_measure(po, WG_LINKS, outs) == WM_OK { 139 // one-axis: dead-ends moved 0 -> exactly 1 (>0) while orphans STAY 0. 140 if outs[12] == 1 { if outs[11] == 0 { aa = 1 } } 141 } 142 let a_dead: i64 = outs[12]; let a_orph: i64 = outs[11] 143 144 var ll: i64 = 0 145 if wm_measure(WG_LIVE_CORPUS, WG_LINKS, outs) == WM_OK { 146 // live: MEETS S-class structure -- orphans==0 AND dead-ends==0 AND reachability==100. 147 // (was "honestly behind"; the walkable spine is now complete, so this GUARDS that it 148 // STAYS walkable -- if the autonomous publisher ever strands a page, this flips RED.) 149 if outs[11] == 0 { if outs[12] == 0 { if outs[7] == 100 { ll = 1 } } } 150 } 151 let l_orph: i64 = outs[11]; let l_dead: i64 = outs[12]; let l_n: i64 = outs[0] 152 153 var passes: i64 = 0 154 if hh == 1 { passes = passes + 1 } 155 if ss == 1 { passes = passes + 1 } 156 if aa == 1 { passes = passes + 1 } 157 if ll == 1 { passes = passes + 1 } 158 var green: i64 = 0 159 if passes == 4 { green = 1 } 160 161 sys_write(1, "wiki-walk metrics gate (measured walkability; 3 neg-control fixtures + live)\n\x00" as *u8, 75) 162 wg_row("HEALTHY-full-corpus-passes \x00" as *u8, hh) 163 wg_row("SPARSE-orphaned-fails \x00" as *u8, ss) 164 wg_row("ONEAXIS-moves-one-axis \x00" as *u8, aa) 165 wg_row("LIVE-meets-sclass \x00" as *u8, ll) 166 167 // evidence detail line 168 let eb: *u8 = sys_mmap(WG_RECCAP + 64) 169 var eo: i64 = 0 170 eo = wg_cat(eb, eo, "WGATE detail healthy[recip=\x00" as *u8); eo = wg_catn(eb, eo, h_recip) 171 eo = wg_cat(eb, eo, " orph=\x00" as *u8); eo = wg_catn(eb, eo, h_orph) 172 eo = wg_cat(eb, eo, " dead=\x00" as *u8); eo = wg_catn(eb, eo, h_dead) 173 eo = wg_cat(eb, eo, " reach=\x00" as *u8); eo = wg_catn(eb, eo, h_reach) 174 eo = wg_cat(eb, eo, "] sparse[dead=\x00" as *u8); eo = wg_catn(eb, eo, s_dead) 175 eo = wg_cat(eb, eo, " reach=\x00" as *u8); eo = wg_catn(eb, eo, s_reach) 176 eo = wg_cat(eb, eo, " orph=\x00" as *u8); eo = wg_catn(eb, eo, s_orph) 177 eo = wg_cat(eb, eo, "] oneaxis[dead=\x00" as *u8); eo = wg_catn(eb, eo, a_dead) 178 eo = wg_cat(eb, eo, " orph=\x00" as *u8); eo = wg_catn(eb, eo, a_orph) 179 eo = wg_cat(eb, eo, "] live[n=\x00" as *u8); eo = wg_catn(eb, eo, l_n) 180 eo = wg_cat(eb, eo, " orph=\x00" as *u8); eo = wg_catn(eb, eo, l_orph) 181 eo = wg_cat(eb, eo, " dead=\x00" as *u8); eo = wg_catn(eb, eo, l_dead) 182 eo = wg_cat(eb, eo, "]\x00" as *u8) 183 eb[eo] = 0 as u8 184 fa_appendz(WG_LOG, eb, WG_RECCAP) 185 sys_write(1, eb, eo); sys_write(1, "\n\x00" as *u8, 1) 186 187 let vb: *u8 = sys_mmap(WG_RECCAP + 16) 188 var o: i64 = 0 189 o = wg_cat(vb, o, "WIKI-WALK verdict=\x00" as *u8) 190 if green == 1 { o = wg_cat(vb, o, "GREEN\x00" as *u8) } else { o = wg_cat(vb, o, "RED\x00" as *u8) } 191 o = wg_cat(vb, o, " passes=\x00" as *u8); o = wg_catn(vb, o, passes); o = wg_cat(vb, o, "/4\x00" as *u8) 192 if green == 0 { 193 o = wg_cat(vb, o, " reason=\x00" as *u8) 194 if hh == 0 { o = wg_cat(vb, o, "healthy-not-perfect \x00" as *u8) } 195 if ss == 0 { o = wg_cat(vb, o, "sparse-not-sensitive \x00" as *u8) } 196 if aa == 0 { o = wg_cat(vb, o, "oneaxis-not-specific \x00" as *u8) } 197 if ll == 0 { o = wg_cat(vb, o, "live-not-sclass \x00" as *u8) } 198 } 199 o = wg_cat(vb, o, " END\x00" as *u8) 200 vb[o] = 0 as u8 201 fa_appendz(WG_LOG, vb, WG_RECCAP) 202 sys_write(1, vb, o); sys_write(1, "\n\x00" as *u8, 1) 203 204 if green == 1 { return 0 } 205 return 1 206}