code wiki / (root) / nx_lbclimb_gate.nx

nx_lbclimb_gate.nx source

↩ module page · 176 lines · 12202 B

1// nx_lbclimb_gate.nx -- GATE for the climb ruler (nx_lbclimb_lib), driven IN-PROCESS on a planted leaderboard (four 2// rivals and the estate's own row) and planted plans: a ladder whose best gate stops short of the leader, one whose 3// gate clears it, a gate spelled with the word leader, a board with contenders and no gates, a board whose only gate 4// is declared unmeasured, a leaderboard that holds no row for the board, a climbboard naming no declared target, gates 5// planted where they must not vote (a substrate rung, a rung that does not exist, a contender toward another target), 6// a floor that is not a score, a rung gated twice, a gate belonging to another board, and the same rows CRLF-terminated. 7// Every fixture asserts that it reached its own condition before the outcome is judged. 8// license_tier: ORIGINAL No hw writes (Rule 26). 9import "nx_syscalls.nx" 10import "nx_barfresh_lib.nx" 11import "nx_ladder_lib.nx" 12import "nx_leaderboard_lib.nx" 13import "nx_lbclimb_lib.nx" 14import "nx_gate_verdict.nx" 15 16const G_I64: i64 = 8 17const G_KMAX: i64 = 16 18const G_BCAP: i64 = 4 19const G_NOROW: i64 = 0 - 9 20const G_CH_LF: i64 = 10 21const G_CH_CR: i64 = 13 22const G_LB: *u8 = "head|bright|https://example.invalid/|m|hpin|2026-09-14|average score\nlb|bright|1|Alpha|OrgA|66.9|2026-04-22|u\nlb|bright|2|Beta|OrgB|63.4|2025-12-20|u\nlb|bright|3|Gamma|OrgC|52.4|2026-03-20|u\nlb|bright|4|Delta|OrgD|39.6|2026-04-01|u\nlb|bright|5|nishi-search|Nishi|15.5|2026-09-16|u\n" 23const G_LB_OTHER: *u8 = "head|mteb|https://example.invalid/|m|hpin|2026-09-14|average score\nlb|mteb|1|Alpha|OrgA|70.1|2026-04-22|u\n" 24const G_LEADER_X10: i64 = 669 25const G_ESTATE_X10: i64 = 155 26const G_ESTATE_RANK: i64 = 5 27const G_RIVALS: i64 = 4 28const G_P0: *u8 = "sotabar|SB|2026-04|s|says|k|n\nsotatarget|T-FR|frontier|SB|be the leader|k\nsotatarget|T-BIC|best-in-class|SB|other|k\nrung|R1|rewriter|s1|d|Organ|1|-\nrung|R2|retriever|s2|d|Organ|1|R1\nrung|R3|aligned|s3|d|Organ|1|R2\nrung|R4|engine|s4|d|Organ|1|-\nrung|R5|other target|s5|d|Organ|1|-\nrungrole|R1|contender|T-FR|w\nrungrole|R2|contender|T-FR|w\nrungrole|R3|contender|T-FR|w\nrungrole|R4|substrate|T-FR|w\nrungrole|R5|contender|T-BIC|w\nclimbboard|bright|T-FR|the public board\n" 29const G_P0_BADTARGET: *u8 = "sotabar|SB|2026-04|s|says|k|n\nsotatarget|T-FR|frontier|SB|be the leader|k\nrung|R1|rewriter|s1|d|Organ|1|-\nrungrole|R1|contender|T-FR|w\nclimbboard|bright|T-NOWHERE|names no declared target\nclimbgate|R1|bright|70.0|would reach\n" 30const G_CONTENDERS: i64 = 3 31const G_V_SHORT: *u8 = "climbgate|R1|bright|22.9|the replay\nclimbgate|R2|bright|39.6|ties the fourth rival\nclimbgate|R3|bright|-|unmeasured\n" 32const G_SHORT_BEST: i64 = 396 33const G_SHORT_REACH: i64 = 4 34const G_V_REACH: *u8 = "climbgate|R1|bright|22.9|the replay\nclimbgate|R3|bright|67.0|one tenth above the leader\n" 35const G_V_DYNAMIC: *u8 = "climbgate|R3|bright|leader|strictly above the leader of the day\n" 36const G_DYNAMIC_FLOOR: i64 = 670 37const G_V_UNGATED: *u8 = "climbgate|R1|bright|-|unmeasured\n" 38const G_V_STRAY: *u8 = "climbgate|R4|bright|99.9|planted on a substrate rung\nclimbgate|Z9|bright|99.9|planted on no rung\nclimbgate|R5|bright|99.9|a contender toward another target\nclimbgate|R1|bright|22.9|the real gate\n" 39const G_STRAYS: i64 = 3 40const G_V_BADFLOOR: *u8 = "climbgate|R1|bright|abc|not a score\nclimbgate|R2|bright|39.6|ties the fourth rival\n" 41const G_V_DUP: *u8 = "climbgate|R1|bright|22.9|the first row decides\nclimbgate|R1|bright|70.0|a second row that would reach\n" 42const G_V_OTHERBOARD: *u8 = "climbgate|R3|mteb|99.9|a gate that belongs to another board\nclimbgate|R1|bright|22.9|the real gate\n" 43 44func g_cat2(a: *u8, b: *u8) -> *u8 { 45 let na: i64 = bf_slen(a) 46 let nb: i64 = bf_slen(b) 47 let d: *u8 = sys_mmap(na + nb + 1) 48 var i: i64 = 0 49 while i < na { d[i] = a[i]; i = i + 1 } 50 var j: i64 = 0 51 while j < nb { d[na + j] = b[j]; j = j + 1 } 52 d[na + nb] = 0 as u8 53 return d 54} 55 56// the same rows CRLF-terminated, built at run time (a CR before every LF) 57func g_crlf(src: *u8) -> *u8 { 58 let n: i64 = bf_slen(src) 59 let d: *u8 = sys_mmap(n * 2 + 1) 60 var i: i64 = 0 61 var o: i64 = 0 62 while i < n { 63 if src[i] == (G_CH_LF as u8) { d[o] = G_CH_CR as u8; o = o + 1 } 64 d[o] = src[i] 65 o = o + 1 66 i = i + 1 67 } 68 d[o] = 0 as u8 69 return d 70} 71 72// run the first climbboard of a plan against a leaderboard; G_NOROW when the plan declares no board 73func g_run(plan: *u8, lb: *u8, k: *i64, c: *i64) -> i64 { 74 let pn: i64 = bf_slen(plan) 75 let ln: i64 = bf_slen(lb) 76 let b: *i64 = sys_mmap(G_BCAP * LBC_BF * G_I64) as *i64 77 let nb: i64 = lbc_boards(plan, pn, b, G_BCAP) 78 if nb <= 0 { return G_NOROW } 79 let board: *u8 = sys_mmap(LBC_NAME_CAP) 80 lbc_span_z(plan, b[LBC_B_NAMEOFF], b[LBC_B_NAMELEN], board) 81 return lbc_climb(plan, pn, lb, ln, board, b[LBC_B_TGTOFF], b[LBC_B_TGTLEN], k, c) 82} 83 84func main(argc: i64, argv: *i64) -> i64 { 85 gv_head("NX-LBCLIMB-GATE: the climb ruler -- does a declared ladder reach the leaderboard's leader, judged on planted plans" as *u8) 86 let ctr: *i64 = gv_ctr() 87 let k: *i64 = sys_mmap(G_KMAX * LBC_KF * G_I64) as *i64 88 let c: *i64 = sys_mmap(LBC_N_COUNT * G_I64) as *i64 89 90 // T1 the board enumerator 91 let b: *i64 = sys_mmap(G_BCAP * LBC_BF * G_I64) as *i64 92 let p0n: i64 = bf_slen(G_P0) 93 gv_check_eq("T1 one climbboard row is enumerated" as *u8, lbc_boards(G_P0, p0n, b, G_BCAP), 1, ctr) 94 gv_check("T1 the board name and its target id are the row's own fields" as *u8, ld_span_is(G_P0, b[LBC_B_NAMEOFF], b[LBC_B_NAMELEN], "bright" as *u8) * ld_span_is(G_P0, b[LBC_B_TGTOFF], b[LBC_B_TGTLEN], "T-FR" as *u8), ctr) 95 96 // T2 SHORT: numeric gates exist and none clears the leader 97 let vs: i64 = g_run(g_cat2(G_P0, G_V_SHORT), G_LB, k, c) 98 gv_check_eq("T2 fixture-reached: three contenders toward the board's target (the substrate rung and the other target's contender stay out)" as *u8, c[LBC_N_CONTENDERS], G_CONTENDERS, ctr) 99 gv_check_eq("T2 the leader is read from the rival rows" as *u8, c[LBC_N_LEADER_X10], G_LEADER_X10, ctr) 100 gv_check_eq("T2 the estate's own latest row is read" as *u8, c[LBC_N_ESTATE_X10], G_ESTATE_X10, ctr) 101 gv_check_eq("T2 the estate's rank is one plus the rivals strictly above it" as *u8, c[LBC_N_ESTATE_RANK], G_ESTATE_RANK, ctr) 102 gv_check_eq("T2 two numeric gates" as *u8, c[LBC_N_GATED], 2, ctr) 103 gv_check_eq("T2 one gate declared unmeasured" as *u8, c[LBC_N_UNGATED], 1, ctr) 104 gv_check_eq("T2 the partition sums to the contender population" as *u8, lbc_partition_sum(c), c[LBC_N_CONTENDERS], ctr) 105 gv_check_eq("T2 the best declared floor" as *u8, c[LBC_N_BEST_FLOOR_X10], G_SHORT_BEST, ctr) 106 gv_check_eq("T2 a floor that ties a rival ranks with the tied (three strictly above it)" as *u8, c[LBC_N_BEST_REACH], G_SHORT_REACH, ctr) 107 gv_check_eq("T2 one gate moves the estate's rank, the lower one does not" as *u8, c[LBC_N_MOVERS], 1, ctr) 108 gv_check_eq("T2 no gate clears the leader" as *u8, c[LBC_N_REACHERS], 0, ctr) 109 gv_check_eq("T2 verdict SHORT" as *u8, vs, LBC_V_SHORT, ctr) 110 gv_check_eq("T2 SHORT exits 1" as *u8, lbc_exit_of(vs), LBC_EXIT_SHORT, ctr) 111 let short_best: i64 = c[LBC_N_BEST_FLOOR_X10] 112 let short_reach: i64 = c[LBC_N_BEST_REACH] 113 114 // T3 REACHES: one gate one tenth above the leader 115 let vr: i64 = g_run(g_cat2(G_P0, G_V_REACH), G_LB, k, c) 116 gv_check_eq("T3 fixture-reached: one gate is strictly above the leader" as *u8, c[LBC_N_REACHERS], 1, ctr) 117 gv_check_eq("T3 that gate reaches rank 1" as *u8, c[LBC_N_BEST_REACH], 1, ctr) 118 gv_check_eq("T3 the ungated third contender is counted as having no gate" as *u8, c[LBC_N_NOGATE], 1, ctr) 119 gv_check_eq("T3 verdict REACHES" as *u8, vr, LBC_V_REACHES, ctr) 120 gv_check_eq("T3 REACHES exits 0" as *u8, lbc_exit_of(vr), LBC_EXIT_REACHES, ctr) 121 122 // T4 a gate spelled with the word leader tracks the public board 123 let vd: i64 = g_run(g_cat2(G_P0, G_V_DYNAMIC), G_LB, k, c) 124 gv_check_eq("T4 fixture-reached: the dynamic gate is counted" as *u8, c[LBC_N_DYNAMIC], 1, ctr) 125 gv_check_eq("T4 its floor is the leader plus one tenth" as *u8, c[LBC_N_BEST_FLOOR_X10], G_DYNAMIC_FLOOR, ctr) 126 gv_check_eq("T4 verdict REACHES" as *u8, vd, LBC_V_REACHES, ctr) 127 let dyn_floor: i64 = c[LBC_N_BEST_FLOOR_X10] 128 129 // T5 contenders and no gate at all; T6 only an unmeasured gate: the ruler abstains, it never acquits 130 let vn: i64 = g_run(G_P0, G_LB, k, c) 131 gv_check_eq("T5 fixture-reached: every contender reads NOGATE" as *u8, c[LBC_N_NOGATE], G_CONTENDERS, ctr) 132 gv_check_eq("T5 verdict NOGATES" as *u8, vn, LBC_V_NOGATES, ctr) 133 gv_check_eq("T5 NOGATES abstains (exit 3)" as *u8, lbc_exit_of(vn), LBC_EXIT_ABSTAIN, ctr) 134 let vu: i64 = g_run(g_cat2(G_P0, G_V_UNGATED), G_LB, k, c) 135 gv_check_eq("T6 fixture-reached: the only gate is declared unmeasured" as *u8, c[LBC_N_UNGATED], 1, ctr) 136 gv_check_eq("T6 an unmeasured gate is not a numeric gate: verdict NOGATES" as *u8, vu, LBC_V_NOGATES, ctr) 137 138 // T7 the leaderboard holds no row for the board; T8 the climbboard names no declared target 139 let vb: i64 = g_run(g_cat2(G_P0, G_V_REACH), G_LB_OTHER, k, c) 140 gv_check_eq("T7 fixture-reached: zero rival rows for the board" as *u8, c[LBC_N_RIVALS], 0, ctr) 141 gv_check_eq("T7 verdict NOBOARD even though the plan carries a reaching gate" as *u8, vb, LBC_V_NOBOARD, ctr) 142 let vt: i64 = g_run(G_P0_BADTARGET, G_LB, k, c) 143 gv_check_eq("T8 verdict BADTARGET, and a reaching gate under it does not vote" as *u8, vt, LBC_V_BADTARGET, ctr) 144 gv_check_eq("T8 BADTARGET is a hard fail (exit 1)" as *u8, lbc_exit_of(vt), LBC_EXIT_SHORT, ctr) 145 146 // neg-controls: gates planted where they must never vote 147 let vx: i64 = g_run(g_cat2(G_P0, G_V_STRAY), G_LB, k, c) 148 gv_check_eq("neg-control-T9 fixture-reached: three stray gates at 99.9 are counted (substrate rung, no rung, another target's contender)" as *u8, c[LBC_N_STRAY], G_STRAYS, ctr) 149 gv_check_eq("neg-control-T9 the strays add no numeric gate" as *u8, c[LBC_N_GATED], 1, ctr) 150 gv_check_eq("neg-control-T9 three planted 99.9 gates do not make the ladder reach: verdict stays SHORT" as *u8, vx, LBC_V_SHORT, ctr) 151 let vf: i64 = g_run(g_cat2(G_P0, G_V_BADFLOOR), G_LB, k, c) 152 gv_check_eq("neg-control-T10 a floor that is not a score is BADFLOOR, never a gate" as *u8, c[LBC_N_BADFLOOR], 1, ctr) 153 gv_check_eq("neg-control-T10 the partition still sums with a bad floor in it" as *u8, lbc_partition_sum(c), c[LBC_N_CONTENDERS], ctr) 154 gv_check_eq("neg-control-T10 verdict SHORT on the one real gate" as *u8, vf, LBC_V_SHORT, ctr) 155 let vdup: i64 = g_run(g_cat2(G_P0, G_V_DUP), G_LB, k, c) 156 gv_check_eq("neg-control-T11 fixture-reached: the second row for one rung is counted as a duplicate" as *u8, c[LBC_N_DUPGATE], 1, ctr) 157 gv_check_eq("neg-control-T11 the FIRST row decides: a later reaching row cannot flip the verdict" as *u8, vdup, LBC_V_SHORT, ctr) 158 let vo: i64 = g_run(g_cat2(G_P0, G_V_OTHERBOARD), G_LB, k, c) 159 gv_check_eq("neg-control-T12 a gate for another board is neither a gate nor a stray here" as *u8, c[LBC_N_GATED] + c[LBC_N_STRAY], 1, ctr) 160 gv_check_eq("neg-control-T12 verdict SHORT" as *u8, vo, LBC_V_SHORT, ctr) 161 162 // T13 the same SHORT rows CRLF-terminated parse to the same census (the floor is never the last field) 163 let vc: i64 = g_run(g_crlf(g_cat2(G_P0, G_V_SHORT)), G_LB, k, c) 164 gv_check_eq("T13 CRLF rows: the same verdict" as *u8, vc, LBC_V_SHORT, ctr) 165 gv_check_eq("T13 CRLF rows: the same best floor" as *u8, c[LBC_N_BEST_FLOOR_X10], G_SHORT_BEST, ctr) 166 gv_check_eq("T13 CRLF rows: the same numeric gate count" as *u8, c[LBC_N_GATED], 2, ctr) 167 168 gv_values_head() 169 gv_kv("leader_x10" as *u8, G_LEADER_X10) 170 gv_kv("estate_x10" as *u8, G_ESTATE_X10) 171 gv_kv("estate_rank" as *u8, G_ESTATE_RANK) 172 gv_kv("short_best_floor_x10" as *u8, short_best) 173 gv_kv("short_best_reach_rank" as *u8, short_reach) 174 gv_kv("dynamic_floor_x10" as *u8, dyn_floor) 175 return gv_verdict("nx_lbclimb_gate" as *u8, ctr, "the climb ruler judged in-process on a planted leaderboard and planted plans" as *u8) 176}