code wiki / _hdl_build / nx_search_census_gate.nx

nx_search_census_gate.nx source

↩ module page · 168 lines · 11148 B

1// nx_search_census_gate.nx -- teeth for the G1 census's OUTCOME PARTITION and its window envelope. 2// 3// WHY IT EXISTS. nx_search_census shipped with prove=NO-GATE-FOUND UNPROVEN, and within an hour its own 4// output nearly misled its author: it reported hostcap_defer_permil=927 over a window that turned out to 5// span about 27 HOURS, while hand-sampled post-fix windows read ZERO. Both were right about their own 6// span. A census whose numbers can be read as current when they are a day-long average needs its 7// envelope PINNED, not just printed. 8// 9// SUBJECT: wc_throughput_census, one of the two contract symbols /compare/search watches. It takes a 10// BUFFER, so these teeth drive it on a synthetic log built here -- no shard, no /tmp fixture, no fork, 11// and nothing that touches the live index or the 129 MB outcome log. 12// license_tier: ORIGINAL expect_exit: 0 13import "nx_search_census.nx" 14import "nx_gate_verdict.nx" 15 16const GSC_BUF: i64 = 4096 17const GSC_SLOTS: i64 = 1024 18// S1 fixture values, NAMED because the build ratchet counts inline literals: a two-term NXQ1 blob whose runs carry 19// npos 3, 1 and 2, so the walk must sum 6 tokens over 3 runs; every offset and length is DERIVED from these. 20const GSC_FXBUF: i64 = 64 21const GSC_POBUF: i64 = 32 22const GSC_VBUF: i64 = 128 23const GSC_MAGIC_LEN: i64 = 4 24const GSC_U32: i64 = 4 25const GSC_NP_HDR: i64 = 1 26const GSC_FX_TERMS: i64 = 2 27const GSC_FX_RUNS: i64 = 3 28const GSC_RUNA_NP: i64 = 3 29const GSC_RUNB_NP: i64 = 1 30const GSC_RUNC_NP: i64 = 2 31const GSC_DELTA_ONE: i64 = 1 32const GSC_RUNB_DELTA: i64 = 5 33const GSC_FX_BADMAGIC: i64 = 77 34const GSC_CONF_CROSS: i64 = 10000000 35func gsc_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 36// one outcome row: <epoch> TAB <class> TAB <status> TAB <textlen> TAB <url> NEWLINE 37func gsc_row(b: *u8, o: i64, epoch: *u8, cls: *u8, url: *u8) -> i64 { 38 var p: i64 = sc_cat(b, o, epoch); b[p] = SC_TAB as u8; p = p + 1 39 p = sc_cat(b, p, cls); b[p] = SC_TAB as u8; p = p + 1 40 p = sc_cat(b, p, "200" as *u8); b[p] = SC_TAB as u8; p = p + 1 41 p = sc_cat(b, p, "1234" as *u8); b[p] = SC_TAB as u8; p = p + 1 42 p = sc_cat(b, p, url); b[p] = SC_NL as u8; p = p + 1 43 return p 44} 45 46func main(argc: i64, argv: *i64) -> i64 { 47 let ctr: *i64 = gv_ctr() 48 49 let b: *u8 = sys_mmap(GSC_BUF) 50 var n: i64 = 0 51 // Nine rows, seven classes, three hosts repeated. Epochs 1000..1080 so the span is exactly 80. 52 n = gsc_row(b, n, "1000" as *u8, "hostcap" as *u8, "https://en.wikipedia.org/a" as *u8) 53 n = gsc_row(b, n, "1010" as *u8, "hostcap" as *u8, "https://en.wikipedia.org/b" as *u8) 54 n = gsc_row(b, n, "1020" as *u8, "ok" as *u8, "https://who.int/x" as *u8) 55 n = gsc_row(b, n, "1030" as *u8, "robots-cd" as *u8, "https://id.loc.gov/r" as *u8) 56 n = gsc_row(b, n, "1040" as *u8, "robots" as *u8, "https://id.loc.gov/s" as *u8) 57 n = gsc_row(b, n, "1050" as *u8, "thin" as *u8, "https://who.int/y" as *u8) 58 n = gsc_row(b, n, "1060" as *u8, "dup" as *u8, "https://arxiv.org/z" as *u8) 59 n = gsc_row(b, n, "1070" as *u8, "http" as *u8, "https://ftc.gov/q" as *u8) 60 n = gsc_row(b, n, "1080" as *u8, "weirdclass" as *u8, "https://esa.int/w" as *u8) 61 62 let out: *i64 = sys_mmap(128) as *i64 63 let tbl: *i64 = sys_mmap(GSC_SLOTS * 8) as *i64 64 let hb: *u8 = sys_mmap(SC_HOSTBUF) 65 let ub: *u8 = sys_mmap(SC_URLBUF) 66 // GSC_SLOTS is deliberately SMALL (1024, not the census's own 65536) and is PASSED IN. That is a 67 // tooth in itself: on the first run of this gate the callee ignored the caller's sizing and indexed 68 // a hardcoded 65536 into this 1024-slot table, and it SIGSEGV'd -- the ship refused to promote it, 69 // which is the whole point. If slots ever stops being honoured, this fixture crashes again. 70 let rows: i64 = wc_throughput_census(b, n, out, tbl, GSC_SLOTS, hb, ub) 71 72 gv_check("T1 fixture-reached: all nine synthetic rows were PARSED, so every tooth below is asked about a buffer the function actually read" as *u8, 73 (rows == 9) as i64, ctr) 74 gv_check("T2 the class partition SUMS to the rows parsed -- an unexplained residual is a leak and this is the check that would find one" as *u8, 75 (out[0] + out[1] + out[2] + out[3] + out[4] + out[5] + out[6] == rows) as i64, ctr) 76 gv_check("T3 hostcap is counted exactly, and it is the class rung G0 is graded on" as *u8, 77 (out[0] == 2) as i64, ctr) 78 gv_check("T4 robots-cd FOLDS INTO robots by prefix -- one class, not two, which is the whole reason the match is a prefix and not an equality" as *u8, 79 (out[4] == 2) as i64, ctr) 80 gv_check("T5 ok, thin, dup and http are each counted once, so the classes are genuinely DISTINGUISHED" as *u8, 81 ((out[1] == 1) as i64) * ((out[2] == 1) as i64) * ((out[3] == 1) as i64) * ((out[5] == 1) as i64), ctr) 82 gv_check("T6 ANTI-VACUITY: an unrecognised class lands in OTHER rather than being silently dropped or folded into a known bucket -- the bucket it lands in becomes the number somebody plans against" as *u8, 83 (out[6] == 1) as i64, ctr) 84 gv_check("T7 distinct hosts DEDUPE: nine rows across six hosts, with who.int and id.loc.gov each appearing twice, must count 6 and not 9" as *u8, 85 (out[7] == 6) as i64, ctr) 86 87 // ---- THE WINDOW ENVELOPE. These are the teeth the 927-versus-zero incident bought. 88 gv_check("T8 the window's FIRST epoch is captured, not the last-seen value overwriting it" as *u8, 89 (out[8] == 1000) as i64, ctr) 90 gv_check("T9 the window's LAST epoch is captured" as *u8, 91 (out[9] == 1080) as i64, ctr) 92 gv_check("T10 the SPAN is therefore derivable, and it is the envelope a permil is meaningless without: a byte window is not a time window, and only these two numbers say which hours a rate covers" as *u8, 93 (out[9] - out[8] == 80) as i64, ctr) 94 95 // ---- NEG-CONTROLS. Both must NOT report, or the function is one that always answers. 96 let e: *i64 = sys_mmap(128) as *i64 97 let etbl: *i64 = sys_mmap(GSC_SLOTS * 8) as *i64 98 let erows: i64 = wc_throughput_census(b, 0, e, etbl, GSC_SLOTS, hb, ub) 99 gv_check("T11 NEG-CONTROL-empty: a zero-length buffer parses ZERO rows -- a census that reports on the empty set is the vacuous-test defect arriving through the front door" as *u8, 100 (erows == 0) as i64, ctr) 101 gv_check("T12 NEG-CONTROL-empty: and it claims no hosts and no classes either, so nothing is carried over from a previous call" as *u8, 102 ((e[7] == 0) as i64) * ((e[0] == 0) as i64) * ((e[8] == 0) as i64), ctr) 103 104 let m: *u8 = sys_mmap(GSC_BUF) 105 var mn: i64 = sc_cat(m, 0, "this row has no tabs at all" as *u8) 106 m[mn] = SC_NL as u8; mn = mn + 1 107 let mo: *i64 = sys_mmap(128) as *i64 108 let mtbl: *i64 = sys_mmap(GSC_SLOTS * 8) as *i64 109 let mrows: i64 = wc_throughput_census(m, mn, mo, mtbl, GSC_SLOTS, hb, ub) 110 gv_check("T13 NEG-CONTROL-malformed: a row with no tab fields is NOT counted -- it cannot be classified, so counting it would inflate the denominator every permil is divided by" as *u8, 111 (mrows == 0) as i64, ctr) 112 113 // T20 S1: the NXQ1 positions-sidecar token walk on a planted blob (2 terms, 3 runs, npos 3+1+2), then the 114 // crossover side from that sum against a planted crossover on EACH side, and the two refusals. 115 // The fixture is assembled from NAMED values and every length is DERIVED from them: a hand-typed byte 116 // offset beside a run table is a second copy of the table's shape, and the two drift silently. 117 let fx: *u8 = sys_mmap(GSC_FXBUF) 118 let mg: *u8 = "NXQ1" as *u8 119 var mi: i64 = 0 120 while mi < GSC_MAGIC_LEN { fx[mi] = mg[mi]; mi = mi + 1 } 121 let hdr: i64 = GSC_MAGIC_LEN + GSC_U32 + GSC_U32 * GSC_FX_TERMS 122 let off1: i64 = GSC_NP_HDR + GSC_RUNA_NP + GSC_NP_HDR + GSC_RUNB_NP 123 ss_w32(fx, GSC_MAGIC_LEN, GSC_FX_TERMS) 124 ss_w32(fx, GSC_MAGIC_LEN + GSC_U32, 0) 125 ss_w32(fx, GSC_MAGIC_LEN + GSC_U32 + GSC_U32, off1) 126 var fo: i64 = hdr 127 fx[fo] = GSC_RUNA_NP as u8; fo = fo + 1 128 var d: i64 = 0 129 while d < GSC_RUNA_NP { fx[fo] = GSC_DELTA_ONE as u8; fo = fo + 1; d = d + 1 } 130 fx[fo] = GSC_RUNB_NP as u8; fo = fo + 1 131 fx[fo] = GSC_RUNB_DELTA as u8; fo = fo + 1 132 fx[fo] = GSC_RUNC_NP as u8; fo = fo + 1 133 d = 0 134 while d < GSC_RUNC_NP { fx[fo] = GSC_DELTA_ONE as u8; fo = fo + 1; d = d + 1 } 135 let fxn: i64 = fo 136 let fxtok: i64 = GSC_RUNA_NP + GSC_RUNB_NP + GSC_RUNC_NP 137 let po: *i64 = sys_mmap(GSC_POBUF) as *i64 138 gv_check("T20 a planted NXQ1 blob walks clean" as *u8, (cs_pos_tokens(fx, fxn, po) == 0) as i64, ctr) 139 var t20b: i64 = 0 140 if po[0] == fxtok { if po[1] == GSC_FX_RUNS { if po[2] == GSC_FX_TERMS { t20b = 1 } } } 141 gv_check("T20b the walk sums every run's npos (tokens 3+1+2, three runs, two terms)" as *u8, t20b, ctr) 142 gv_check("T20c a planted crossover under the sum reads ABOVE" as *u8, (cs_crossover(po[0], fxtok - GSC_DELTA_ONE) == CS_SIDE_ABOVE) as i64, ctr) 143 gv_check("T20d neg-control-a-planted-crossover-over-the-sum reads the other side, BELOW" as *u8, (cs_crossover(po[0], fxtok + GSC_DELTA_ONE) == CS_SIDE_BELOW) as i64, ctr) 144 fx[0] = GSC_FX_BADMAGIC as u8 145 gv_check("T20e neg-control-a-wrong-magic is refused, not summed" as *u8, (cs_pos_tokens(fx, fxn, po) == 0 - 1) as i64, ctr) 146 fx[0] = mg[0] 147 let cut: i64 = hdr + GSC_NP_HDR + GSC_RUNA_NP 148 gv_check("T20f neg-control-a-truncated-blob is refused, never a partial sum trusted" as *u8, (cs_pos_tokens(fx, cut, po) == 0 - 2) as i64, ctr) 149 // T21 the crossover conf reader: int, string and a CRLF line, unknown key reads empty 150 let cf: *u8 = "crossover_tokens 10000000\r\nref bm25scale26\ncaveat two words here\n" as *u8 151 let cfn: i64 = gsc_len(cf) 152 gv_check("T21 crossover_tokens reads its value through a CRLF line" as *u8, (sc_conf_int(cf, cfn, "crossover_tokens" as *u8) == GSC_CONF_CROSS) as i64, ctr) 153 let vb: *u8 = sys_mmap(GSC_VBUF) 154 let refw: *u8 = "bm25scale26" as *u8 155 let rl: i64 = sc_conf_val(cf, cfn, "ref" as *u8, vb, GSC_VBUF) 156 var t21b: i64 = 0 157 if rl == gsc_len(refw) { if sc_lit_at(vb, rl, refw) == 1 { t21b = 1 } } 158 gv_check("T21b ref value exact" as *u8, t21b, ctr) 159 let cavw: *u8 = "two words here" as *u8 160 let cl: i64 = sc_conf_val(cf, cfn, "caveat" as *u8, vb, GSC_VBUF) 161 var t21c: i64 = 0 162 if cl == gsc_len(cavw) { if sc_lit_at(vb, cl, cavw) == 1 { t21c = 1 } } 163 gv_check("T21c caveat value keeps its spaces and stops at the line" as *u8, t21c, ctr) 164 gv_check("T21d neg-control-an-unknown-key reads empty" as *u8, (sc_conf_val(cf, cfn, "nope" as *u8, vb, GSC_VBUF) == 0) as i64, ctr) 165 gv_check("T21e neg-control-a-key-prefix (cross) does not match crossover_tokens" as *u8, (sc_conf_int(cf, cfn, "cross" as *u8) == 0) as i64, ctr) 166 167 return gv_verdict("SEARCH-CENSUS-GATE" as *u8, ctr, "the outcome partition, the host dedup and the window epoch envelope of wc_throughput_census; the shard-walking half idx_corpus_census needs a fixture shard and stays unproven here" as *u8) 168}