code wiki / (root) / nx_build_firsttry_gate.nx

nx_build_firsttry_gate.nx source

↩ module page · 186 lines · 14232 B

1// nx_build_firsttry_gate.nx -- CE2 (codeeffectiveness ce_build_firsttry): the build pillar's two rates read from a 2// ship journal, PROVEN on planted journals with hand-computed answers. In-process over nx_build_firsttry_lib (the ONE 3// ruler nx_organ_ship's firsttry verb calls), with a FIXED now so every expected count was decided before the run. 4// Neg-controls the rung demands: a known revert raises rework AND reverts by EXACTLY ONE over the single-ship 5// control; a window with nothing in it reads UNOBSERVABLE and writes NO spine row; the production spine is unchanged 6// by any fixture run; an unreadable journal is UNREADABLE, never a zero rate. Rows are written with real TAB bytes 7// by a row writer, never by a string literal, so the fixture is the wire shape the loop writes. 8// exit: 0 GREEN . 1 RED . 3 SKIP license_tier: ORIGINAL No hw writes. 9import "nx_syscalls.nx" 10import "nx_gate_verdict.nx" 11import "nx_build_firsttry_lib.nx" 12 13const BFG_ROOT: *u8 = "/tmp/nx_build_firsttry_gate" 14const BFG_F0: *u8 = "/tmp/nx_build_firsttry_gate/f0.jrnl" 15const BFG_F1: *u8 = "/tmp/nx_build_firsttry_gate/f1.jrnl" 16const BFG_F2: *u8 = "/tmp/nx_build_firsttry_gate/f2.jrnl" 17const BFG_F3: *u8 = "/tmp/nx_build_firsttry_gate/f3.jrnl" 18const BFG_F4: *u8 = "/tmp/nx_build_firsttry_gate/f4.jrnl" 19const BFG_F5: *u8 = "/tmp/nx_build_firsttry_gate/f5.jrnl" 20const BFG_F1_SPINE: *u8 = "/tmp/nx_build_firsttry_gate/f1.jrnl.firsttry.spine" 21const BFG_F5_SPINE: *u8 = "/tmp/nx_build_firsttry_gate/f5.jrnl.firsttry.spine" 22const BFG_MISSING: *u8 = "/tmp/nx_build_firsttry_gate/does-not-exist.jrnl" 23const BFG_F6: *u8 = "/tmp/nx_build_firsttry_gate/f6.jrnl" 24const BFG_NOW: i64 = 1788656000 25const BFG_WINDOW: i64 = 14 26const BFG_MODE_RWX: i64 = 493 27const BFG_MODE_RW: i64 = 420 28const BFG_LINE: i64 = 512 29const BFG_MIN: i64 = 60 30// fixture arithmetic, decided before the run 31const BFG_B_FIRST: i64 = 1000 32const BFG_B_REVERT: i64 = 900 33const BFG_B_GROW: i64 = 1100 34const BFG_F4_ROWS: i64 = 10 35const BFG_F4_ROWS_IN: i64 = 8 36const BFG_F4_EPISODES: i64 = 3 37const BFG_F4_FIRST_PERMIL: i64 = 500 // first_pass 1 of (first_pass 1 + code_fail 1); the box refusal is outside the denominator 38const BFG_F4_SHIPPED: i64 = 3 39const BFG_F4_TARGETS: i64 = 3 40 41func bfg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 42func bfg_w(fd: i64, s: *u8) -> i64 { return sys_write(fd, s, bfg_slen(s)) } 43func bfg_tab(fd: i64) -> i64 { let b: *u8 = sys_mmap(4); b[0] = BFT_TAB as u8; return sys_write(fd, b, 1) } 44func bfg_nl(fd: i64) -> i64 { let b: *u8 = sys_mmap(4); b[0] = BFT_NL as u8; return sys_write(fd, b, 1) } 45func bfg_n(fd: i64, v: i64) -> i64 { let b: *u8 = sys_mmap(BFG_LINE); let o: i64 = bft_catn(b, 0, v); return sys_write(fd, b, o) } 46// one journal row in the wire shape: epoch<TAB>target<TAB>stage<TAB>verdict<TAB>detail\n 47func bfg_row(fd: i64, epoch: i64, target: *u8, stage: *u8, verdict: *u8, detail: *u8) -> i64 { 48 bfg_n(fd, epoch); bfg_tab(fd); bfg_w(fd, target); bfg_tab(fd); bfg_w(fd, stage); bfg_tab(fd); bfg_w(fd, verdict); bfg_tab(fd); bfg_w(fd, detail); bfg_nl(fd) 49 return 0 50} 51func bfg_open(path: *u8) -> i64 { sys_unlinkat(path); return sys_openat_wr(path, BFG_MODE_RW) } 52// a ship pair: BUILD BUILT then SHIPPED GREEN a minute later, detail carrying bytes= when b > 0 53func bfg_ship(fd: i64, at: i64, target: *u8, b: i64) -> i64 { 54 bfg_row(fd, at, target, "BUILD" as *u8, "BUILT" as *u8, "sha" as *u8) 55 if b > 0 { 56 let d: *u8 = sys_mmap(BFG_LINE) 57 var o: i64 = 0 58 var i: i64 = 0 59 let pre: *u8 = "sha bytes=" as *u8 60 while pre[i] != (0 as u8) { d[o] = pre[i]; o = o + 1; i = i + 1 } 61 o = bft_catn(d, o, b) 62 bfg_row(fd, at + BFG_MIN, target, "SHIPPED" as *u8, "GREEN" as *u8, d) 63 } else { bfg_row(fd, at + BFG_MIN, target, "SHIPPED" as *u8, "GREEN" as *u8, "sha" as *u8) } 64 return 0 65} 66func bfg_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 67func bfg_size(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } let s: i64 = sys_lseek(fd, 0, 2); sys_close(fd); return s } 68// newline count, -1 when absent; the buffer is not released (a few hundred bytes, the process exits at the verdict) 69func bfg_lines(path: *u8) -> i64 { 70 let ln: *i64 = sys_mmap(16) as *i64 71 let b: *u8 = sys_read_file(path, ln) 72 if (b as i64) == 0 { return 0 - 1 } 73 var c: i64 = 0 74 var i: i64 = 0 75 while i < ln[0] { if b[i] == (BFT_NL as u8) { c = c + 1 } i = i + 1 } 76 return c 77} 78 79func main(argc: i64, argv: *i64) -> i64 { 80 let ctr: *i64 = gv_ctr() 81 gv_head("NX-BUILD-FIRSTTRY-GATE: first-try build rate and 14-day rework/revert rate from the ship journal, on planted journals with hand-computed answers" as *u8) 82 sys_mkdir(BFG_ROOT, BFG_MODE_RWX) 83 let d: i64 = BFT_DAY_S 84 // F0: one ship, three days ago -- the control every delta is measured against 85 var fd: i64 = bfg_open(BFG_F0); bfg_ship(fd, BFG_NOW - 3 * d, "t1" as *u8, BFG_B_FIRST); sys_close(fd) 86 // F1: F0 plus a re-ship one day ago that SHRANK -- the known revert 87 fd = bfg_open(BFG_F1); bfg_ship(fd, BFG_NOW - 3 * d, "t1" as *u8, BFG_B_FIRST); bfg_ship(fd, BFG_NOW - 1 * d, "t1" as *u8, BFG_B_REVERT); sys_close(fd) 88 // F2: the same re-ship that GREW -- rework without a revert 89 fd = bfg_open(BFG_F2); bfg_ship(fd, BFG_NOW - 3 * d, "t1" as *u8, BFG_B_FIRST); bfg_ship(fd, BFG_NOW - 1 * d, "t1" as *u8, BFG_B_GROW); sys_close(fd) 90 // F3: the re-ship carries no bytes= -- revert UNOBSERVABLE, counted, never guessed 91 fd = bfg_open(BFG_F3); bfg_ship(fd, BFG_NOW - 3 * d, "t1" as *u8, BFG_B_FIRST); bfg_ship(fd, BFG_NOW - 1 * d, "t1" as *u8, 0); sys_close(fd) 92 // F4: three targets -- a compile failure then a pass (code_fail episode, one retry), a box refusal then a pass 93 // (box_refused episode, one retry), a clean pass whose previous ship is 30 days old (state only, no rework) 94 fd = bfg_open(BFG_F4) 95 bfg_row(fd, BFG_NOW - 2 * d, "t2" as *u8, "BUILD" as *u8, "COMPILE-FAIL" as *u8, "error: unresolved identifier" as *u8) 96 bfg_ship(fd, BFG_NOW - 2 * d + 2 * BFG_MIN, "t2" as *u8, 500) 97 bfg_row(fd, BFG_NOW - 2 * d + 5 * BFG_MIN, "t3" as *u8, "BUILD" as *u8, "REFUSED-ADMIT" as *u8, "BUILD-ADMIT VERDICT=QUEUE" as *u8) 98 bfg_ship(fd, BFG_NOW - 2 * d + 7 * BFG_MIN, "t3" as *u8, 600) 99 bfg_ship(fd, BFG_NOW - 30 * d, "t4" as *u8, 700) 100 bfg_ship(fd, BFG_NOW - 1 * d, "t4" as *u8, 650) 101 sys_close(fd) 102 // F5: everything 40 days ago -- rows exist, none in the window 103 fd = bfg_open(BFG_F5); bfg_ship(fd, BFG_NOW - 40 * d, "t1" as *u8, BFG_B_FIRST); sys_close(fd) 104 // F6: a retry inside the episode with NO failure row -- the pre-fix journal shape (BUILT rows only): the rate must abstain 105 fd = bfg_open(BFG_F6); bfg_row(fd, BFG_NOW - 2 * d, "t5" as *u8, "BUILD" as *u8, "BUILT" as *u8, "sha" as *u8); bfg_ship(fd, BFG_NOW - 2 * d + BFG_MIN, "t5" as *u8, 800); sys_close(fd) 106 sys_unlinkat(BFG_F1_SPINE); sys_unlinkat(BFG_F5_SPINE); sys_unlinkat(BFG_MISSING) 107 if gv_need("fixture journals written under /tmp" as *u8, bfg_exists(BFG_F4), ctr) == 0 { return gv_verdict("nx_build_firsttry_gate" as *u8, ctr, "fixture tree unwritable" as *u8) } 108 let r0: *i64 = sys_mmap(BFT_R_SLOTS * BFT_WORD) as *i64 109 let r1: *i64 = sys_mmap(BFT_R_SLOTS * BFT_WORD) as *i64 110 let r2: *i64 = sys_mmap(BFT_R_SLOTS * BFT_WORD) as *i64 111 let r3: *i64 = sys_mmap(BFT_R_SLOTS * BFT_WORD) as *i64 112 let r4: *i64 = sys_mmap(BFT_R_SLOTS * BFT_WORD) as *i64 113 let r5: *i64 = sys_mmap(BFT_R_SLOTS * BFT_WORD) as *i64 114 let r6: *i64 = sys_mmap(BFT_R_SLOTS * BFT_WORD) as *i64 115 let c0: i64 = bft_measure(BFG_F0, BFG_WINDOW, BFG_NOW, r0) 116 let c1: i64 = bft_measure(BFG_F1, BFG_WINDOW, BFG_NOW, r1) 117 let c2: i64 = bft_measure(BFG_F2, BFG_WINDOW, BFG_NOW, r2) 118 let c3: i64 = bft_measure(BFG_F3, BFG_WINDOW, BFG_NOW, r3) 119 let c4: i64 = bft_measure(BFG_F4, BFG_WINDOW, BFG_NOW, r4) 120 let c5: i64 = bft_measure(BFG_F5, BFG_WINDOW, BFG_NOW, r5) 121 let c6: i64 = bft_measure(BFG_MISSING, BFG_WINDOW, BFG_NOW, r6) 122 // ---- F0 control ---- 123 gv_check_eq("f0-single-ship-reads-MEASURED" as *u8, c0, BFT_VERDICT_MEASURED, ctr) 124 gv_check_eq("f0-one-episode" as *u8, r0[BFT_R_EPISODES], 1, ctr) 125 gv_check_eq("f0-first-pass-one" as *u8, r0[BFT_R_FIRST_PASS], 1, ctr) 126 gv_check_eq("f0-first-try-permil-1000" as *u8, r0[BFT_R_FIRST_PERMIL], BFT_PERMIL, ctr) 127 gv_check_eq("f0-shipped-one-rework-zero" as *u8, r0[BFT_R_SHIPPED] * 10 + r0[BFT_R_REWORK], 10, ctr) 128 gv_check_eq("f0-rework-permil-zero-not-unobservable" as *u8, r0[BFT_R_REWORK_PERMIL], 0, ctr) 129 // ---- F1 the known revert: exactly one more rework AND exactly one more revert than the control ---- 130 gv_check_eq("f1-known-revert-reads-MEASURED" as *u8, c1, BFT_VERDICT_MEASURED, ctr) 131 gv_check_eq("neg-control-known-revert-raises-rework-by-exactly-one" as *u8, r1[BFT_R_REWORK] - r0[BFT_R_REWORK], 1, ctr) 132 gv_check_eq("neg-control-known-revert-raises-reverts-by-exactly-one" as *u8, r1[BFT_R_REVERT] - r0[BFT_R_REVERT], 1, ctr) 133 gv_check_eq("f1-rework-permil-500-of-two-ships" as *u8, r1[BFT_R_REWORK_PERMIL], 500, ctr) 134 gv_check_eq("f1-episodes-two-both-first-pass" as *u8, r1[BFT_R_EPISODES] * 10 + r1[BFT_R_FIRST_PASS], 22, ctr) 135 // ---- F2 growth: rework yes, revert no ---- 136 gv_check_eq("f2-growth-is-rework-not-revert" as *u8, r2[BFT_R_REWORK] * 100 + r2[BFT_R_REVERT] * 10 + r2[BFT_R_NON_REVERT], 101, ctr) 137 // ---- F3 no bytes: revert UNOBSERVABLE, counted ---- 138 gv_check_eq("f3-missing-bytes-is-revert-unobservable-never-a-revert" as *u8, r3[BFT_R_REWORK] * 100 + r3[BFT_R_REVERT] * 10 + r3[BFT_R_REVERT_UNOBS], 101, ctr) 139 // ---- F4 the mixed journal ---- 140 gv_check_eq("f4-rows-counted-whole-file" as *u8, r4[BFT_R_ROWS], BFG_F4_ROWS, ctr) 141 gv_check_eq("f4-rows-in-window-excludes-the-30-day-old-pair" as *u8, r4[BFT_R_ROWS_IN], BFG_F4_ROWS_IN, ctr) 142 gv_check_eq("f4-three-episodes" as *u8, r4[BFT_R_EPISODES], BFG_F4_EPISODES, ctr) 143 gv_check_eq("f4-episode-partition-first-pass-1-code-fail-1-box-refused-1" as *u8, r4[BFT_R_FIRST_PASS] * 100 + r4[BFT_R_CODE_FAIL] * 10 + r4[BFT_R_BOX_REFUSED], 111, ctr) 144 gv_check_eq("f4-two-retries-inside-episodes" as *u8, r4[BFT_R_RETRIES], 2, ctr) 145 gv_check_eq("f4-first-try-permil-500-box-refusal-outside-the-denominator" as *u8, r4[BFT_R_FIRST_PERMIL], BFG_F4_FIRST_PERMIL, ctr) 146 gv_check_eq("f4-shipped-three-in-window" as *u8, r4[BFT_R_SHIPPED], BFG_F4_SHIPPED, ctr) 147 gv_check_eq("f4-no-rework-a-30-day-old-predecessor-is-outside-the-window" as *u8, r4[BFT_R_REWORK], 0, ctr) 148 gv_check_eq("f4-three-targets" as *u8, r4[BFT_R_TARGETS], BFG_F4_TARGETS, ctr) 149 gv_check_eq("f4-reads-MEASURED" as *u8, c4, BFT_VERDICT_MEASURED, ctr) 150 // ---- F5 nothing in the window ---- 151 gv_check_eq("f5-empty-window-reads-UNOBSERVABLE-not-a-zero-rate" as *u8, c5, BFT_VERDICT_UNOBSERVABLE, ctr) 152 gv_check_eq("f5-rows-exist-but-none-in-window" as *u8, r5[BFT_R_ROWS] * 10 + r5[BFT_R_ROWS_IN], 20, ctr) 153 gv_check_eq("f5-both-permils-UNOBSERVABLE" as *u8, r5[BFT_R_FIRST_PERMIL] + r5[BFT_R_REWORK_PERMIL], 2 * BFT_UNOBSERVABLE, ctr) 154 // ---- missing journal ---- 155 gv_check_eq("missing-journal-reads-UNREADABLE" as *u8, c6, BFT_VERDICT_UNREADABLE, ctr) 156 // ---- F6 the pre-fix journal shape: a retry with no failure class recorded -> the first-try rate ABSTAINS by name ---- 157 let r7: *i64 = sys_mmap(BFT_R_SLOTS * BFT_WORD) as *i64 158 let c7: i64 = bft_measure(BFG_F6, BFG_WINDOW, BFG_NOW, r7) 159 gv_check_eq("f6-retry-without-a-failure-class-reads-one-retry" as *u8, r7[BFT_R_RETRIES], 1, ctr) 160 gv_check_eq("f6-first-try-UNOBSERVABLE-never-a-bare-1000" as *u8, r7[BFT_R_FIRST_PERMIL], BFT_UNOBSERVABLE, ctr) 161 gv_check_eq("f6-neg-class-absent-flagged-by-name" as *u8, r7[BFT_R_NEG_CLASS_ABSENT], 1, ctr) 162 gv_check_eq("f6-still-MEASURED-because-the-rework-rate-is-observable" as *u8, c7, BFT_VERDICT_MEASURED, ctr) 163 gv_check_eq("f4-failures-recorded-so-the-negative-class-is-present" as *u8, r4[BFT_R_NEG_CLASS_ABSENT], 0, ctr) 164 gv_bite("bare-1000-permil-refused-when-the-journal-lacks-the-negative-class" as *u8, (r7[BFT_R_FIRST_PERMIL] == BFT_UNOBSERVABLE) as i64, (r4[BFT_R_FIRST_PERMIL] == BFT_UNOBSERVABLE) as i64, ctr) 165 // ---- the spine: two MEASURED reports leave two sidecar rows; an UNOBSERVABLE report leaves none; production untouched ---- 166 let prod_before: i64 = bfg_size(BFT_SPINE_PROD) 167 let rc1: i64 = bft_report(BFG_F1, BFG_WINDOW, BFG_NOW) 168 let rc1b: i64 = bft_report(BFG_F1, BFG_WINDOW, BFG_NOW) 169 let rc5: i64 = bft_report(BFG_F5, BFG_WINDOW, BFG_NOW) 170 let prod_after: i64 = bfg_size(BFT_SPINE_PROD) 171 gv_check_eq("report-returns-the-measure-code" as *u8, rc1 * 100 + rc1b * 10 + rc5, BFT_VERDICT_UNOBSERVABLE, ctr) 172 gv_check_eq("two-measured-reports-leave-two-sidecar-rows-a-trajectory" as *u8, bfg_lines(BFG_F1_SPINE), 2, ctr) 173 gv_check_eq("unobservable-report-writes-no-trend-point" as *u8, bfg_exists(BFG_F5_SPINE), 0, ctr) 174 gv_check("neg-control-production-spine-unchanged-by-fixture-runs" as *u8, (prod_before == prod_after) as i64, ctr) 175 gv_bite("revert-detector-fires-on-the-shrink-and-is-silent-on-the-growth" as *u8, (r1[BFT_R_REVERT] == 1) as i64, (r2[BFT_R_REVERT] != 0) as i64, ctr) 176 gv_bite("spine-written-for-a-measured-run-and-not-for-an-unobservable-one" as *u8, bfg_exists(BFG_F1_SPINE), bfg_exists(BFG_F5_SPINE), ctr) 177 gv_values_head() 178 gv_kv("f4_first_try_permil" as *u8, r4[BFT_R_FIRST_PERMIL]) 179 gv_kv("f1_rework_permil" as *u8, r1[BFT_R_REWORK_PERMIL]) 180 gv_kv("f1_reverts" as *u8, r1[BFT_R_REVERT]) 181 gv_kv("f4_rows" as *u8, r4[BFT_R_ROWS]) 182 gv_kv("f4_rows_in_window" as *u8, r4[BFT_R_ROWS_IN]) 183 gv_kv("prod_spine_size_before" as *u8, prod_before) 184 gv_kv("prod_spine_size_after" as *u8, prod_after) 185 return gv_verdict("nx_build_firsttry_gate" as *u8, ctr, "both rates reproduce hand-computed answers on six planted journals; a known revert moves rework and reverts by exactly one; an empty window and a missing journal abstain by name; the trend is written only for a measured run and never into production" as *u8) 186}