code wiki / (root) / nx_prop_pass_gate.nx

nx_prop_pass_gate.nx source

↩ module page · 168 lines · 11730 B

1// nx_prop_pass_gate.nx -- GATE for prop_pass (intelmine IM26): the ONE renderer of knowledge/compare/<dom>.proposed in the 2// compare base lib (nx_swcompare_lib), driven IN-PROCESS on a planted fixture tree under /tmp/nx_prop_pass_gate. The gate 3// chdirs into the fixture root so the lib's CWD-relative knowledge/compare/<dom>.proposed resolves INSIDE the fixture and 4// never reads or renders a real board. Controls: an ABSENT domain must emit NOTHING in both modes (no section, no key); a 5// MALFORMED row must be COUNTED and never rendered; a file AT the read cap must announce READ-CAPPED while a small one must 6// not; an appid-named row must read its BANKED title at render time and say name_src=banked, and one with no banked 7// title must print its appid and say so. Every fixture asserts it reached its condition before any outcome is judged. 8// No network. license_tier: ORIGINAL 9import "nx_syscalls.nx" 10import "nx_gatekit_lib.nx" 11import "nx_swcompare_lib.nx" 12import "nx_gate_verdict.nx" 13 14const G_ROOT: *u8 = "/tmp/nx_prop_pass_gate" 15const G_KDIR: *u8 = "/tmp/nx_prop_pass_gate/knowledge" 16const G_CDIR: *u8 = "/tmp/nx_prop_pass_gate/knowledge/compare" 17const G_PLANTED: *u8 = "/tmp/nx_prop_pass_gate/knowledge/compare/planted.proposed" 18const G_BIG: *u8 = "/tmp/nx_prop_pass_gate/knowledge/compare/big.proposed" 19const G_ABSENT: *u8 = "/tmp/nx_prop_pass_gate/knowledge/compare/absent.proposed" 20const G_HTML: *u8 = "/tmp/nx_prop_pass_gate/planted.html" 21const G_JSON: *u8 = "/tmp/nx_prop_pass_gate/planted.json" 22const G_ABS_HTML: *u8 = "/tmp/nx_prop_pass_gate/absent.html" 23const G_ABS_JSON: *u8 = "/tmp/nx_prop_pass_gate/absent.json" 24const G_BIG_HTML: *u8 = "/tmp/nx_prop_pass_gate/big.html" 25const G_BIG_JSON: *u8 = "/tmp/nx_prop_pass_gate/big.json" 26const G_MODE_RW: i64 = 420 // 0644: the capture files are read back by this gate only 27const G_PLANTED_LINES: i64 = 6 // one comment, three proposals, one short row, one row with the wrong tag 28const G_ROWS_EXPECTED: i64 = 3 29const G_MALFORMED_EXPECTED: i64 = 2 30const G_I64_BYTES: i64 = 8 31// the banked platform name the renderer must read at render time (fixture root, knowledge/reviews/steam/<appid>.name) 32const G_RDIR: *u8 = "/tmp/nx_prop_pass_gate/knowledge/reviews" 33const G_SDIR: *u8 = "/tmp/nx_prop_pass_gate/knowledge/reviews/steam" 34const G_NAME_620: *u8 = "/tmp/nx_prop_pass_gate/knowledge/reviews/steam/620.name" 35const G_NAME_999: *u8 = "/tmp/nx_prop_pass_gate/knowledge/reviews/steam/999.name" 36 37// the planted rows: a title named by the row, an appid-named row whose title IS banked (620 -> Portal 2), an appid-named 38// row with NO banked title (999), a SHORT row (seven fields) and a ten-field row whose tag is not prop -- the two 39// malformed shapes the renderer must count 40const G_ROWS: *u8 = "# planted by nx_prop_pass_gate\nprop|1788630000|777|Planted Title|DEFECT|defect|stutter|planted|Frame pacing: Planted Title reviewers flag stutter|does_not_meet=3 praised=0\nprop|1788630001|620|620|THEY-DO-WELL|feature|coop|planted|Co-op: 620 -- drop-in co-op door with a gate|praised=3 complained=0 mixed=0 demanded=0\nprop|1788630004|999|999|DEMANDED|feature|controls|planted|Control mapping: 999|praised=0 complained=2 mixed=0 demanded=1\nprop|1788630002|777|Planted Title|DEMANDED|feature|customization\nbogus|row|that|is|not|a|proposal|at|all|ten\n" 41const G_BIG_ROW: *u8 = "prop|1788630003|777|Planted Title|SHIPS|engine|Unity|big|Engine parity: Planted Title ships Unity|fingerprint=installed-tree\n" 42 43func g_lines(path: *u8) -> i64 { 44 let lp: *i64 = sys_mmap(G_I64_BYTES) as *i64 45 lp[0] = 0 46 let b: *u8 = sys_read_file(path, lp) 47 if (b as i64) == 0 { return 0 } 48 var n: i64 = 0 49 var i: i64 = 0 50 while i < lp[0] { if b[i] == (PR_CH_LF as u8) { n = n + 1 } i = i + 1 } 51 return n 52} 53// render <dom> into out_path in the given mode; the rows count prop_pass returned, or -1 when the capture cannot open 54func g_render(dom: *u8, out_path: *u8, mode: i64) -> i64 { 55 gk_rm(out_path) 56 let fd: i64 = sys_openat_wr(out_path, G_MODE_RW) 57 if fd < 0 { return 0 - 1 } 58 let r: i64 = prop_pass(dom, fd, mode) 59 sys_close(fd) 60 return r 61} 62func g_has(path: *u8, needle: *u8) -> i64 { 63 let lp: *i64 = sys_mmap(G_I64_BYTES) as *i64 64 lp[0] = 0 65 let b: *u8 = sys_read_file(path, lp) 66 if (b as i64) == 0 { return 0 } 67 return gk_out_has(b, lp[0], needle) 68} 69func g_starts(path: *u8, needle: *u8) -> i64 { 70 let lp: *i64 = sys_mmap(G_I64_BYTES) as *i64 71 lp[0] = 0 72 let b: *u8 = sys_read_file(path, lp) 73 if (b as i64) == 0 { return 0 } 74 if gk_out_pos(b, lp[0], needle) == 0 { return 1 } 75 return 0 76} 77// a file of EXACTLY PR_READ_CAP bytes made of valid rows (the last one cut at the boundary), so the renderer's own 78// cap is the fixture's size -- derived from the lib's constant, never a second number that could drift from it 79func g_big() -> i64 { 80 let b: *u8 = sys_mmap(PR_READ_CAP + 1) 81 let rl: i64 = gk_len(G_BIG_ROW) 82 var o: i64 = 0 83 while o < PR_READ_CAP { 84 var i: i64 = 0 85 while i < rl { if o < PR_READ_CAP { b[o] = G_BIG_ROW[i]; o = o + 1 } i = i + 1 } 86 } 87 b[PR_READ_CAP] = 0 as u8 88 gk_write(G_BIG, b) 89 return 0 90} 91 92func main() -> i64 { 93 gv_head("=== nx_prop_pass_gate -- the one renderer of <dom>.proposed, in-process on a planted fixture tree (intelmine IM26) ===" as *u8) 94 let c: *i64 = gv_ctr() 95 gk_mkdir(G_ROOT); gk_mkdir(G_KDIR); gk_mkdir(G_CDIR); gk_mkdir(G_RDIR); gk_mkdir(G_SDIR) 96 gk_rm(G_ABSENT) 97 gk_rm(G_NAME_999) 98 gk_write(G_NAME_620, "Portal 2\n" as *u8) 99 gk_write(G_PLANTED, G_ROWS) 100 g_big() 101 gv_need("fixture-root-created" as *u8, gk_exists(G_CDIR), c) 102 gv_check_eq("fixture-reached-the-condition: planted file has six lines" as *u8, g_lines(G_PLANTED), G_PLANTED_LINES, c) 103 gv_check("fixture-reached-the-condition: 620.name banked and 999.name absent" as *u8, gk_exists(G_NAME_620) * ((gk_exists(G_NAME_999) == 0) as i64), c) 104 gv_check_eq("fixture-reached-the-condition: big file is exactly the read cap in bytes" as *u8, gk_size(G_BIG), PR_READ_CAP, c) 105 gv_check("fixture-reached-the-condition: absent domain has no file" as *u8, (gk_exists(G_ABSENT) == 0) as i64, c) 106 // the lib resolves knowledge/compare/<dom>.proposed from CWD: enter the fixture so no real board is ever read 107 gv_need("chdir-into-fixture" as *u8, (sys_chdir(G_ROOT) == 0) as i64, c) 108 109 // ---- HTML band ---- 110 let rh: i64 = g_render("planted" as *u8, G_HTML, 1) 111 gv_check_eq("html-returns-the-rendered-row-count" as *u8, rh, G_ROWS_EXPECTED, c) 112 gv_check("html-carries-the-band-heading" as *u8, g_has(G_HTML, "Mined from the field" as *u8), c) 113 gv_check("html-defect-signal-chip" as *u8, g_has(G_HTML, "<span class='ex'>DEFECT</span>" as *u8), c) 114 gv_check("html-they-do-well-signal-chip" as *u8, g_has(G_HTML, "<span class='ex'>THEY-DO-WELL</span>" as *u8), c) 115 gv_check("html-row-named-title-beside-its-appid" as *u8, g_has(G_HTML, "Planted Title <span class='ct'>777</span>" as *u8), c) 116 gv_check("html-banked-title-read-at-render-time-for-an-appid-named-row" as *u8, g_has(G_HTML, "Portal 2 <span class='ct'>620</span>" as *u8), c) 117 gv_check("neg-control-banked-row-no-longer-reads-unresolved" as *u8, (g_has(G_HTML, "appid <span class='ct'>620</span>" as *u8) == 0) as i64, c) 118 gv_check("html-unresolved-title-says-so-instead-of-a-number-as-a-name" as *u8, g_has(G_HTML, "appid <span class='ct'>999</span> (title unresolved: no census row and no banked name)" as *u8), c) 119 gv_check("html-proposed-rung-title-rendered" as *u8, g_has(G_HTML, "<b>Frame pacing: Planted Title reviewers flag stutter</b>" as *u8), c) 120 gv_check("html-evidence-rendered" as *u8, g_has(G_HTML, "praised=3 complained=0 mixed=0 demanded=0" as *u8), c) 121 gv_check("html-proposals-count-printed" as *u8, g_has(G_HTML, "proposals <b>3</b>" as *u8), c) 122 gv_check("html-malformed-rows-counted-two" as *u8, g_has(G_HTML, "malformed rows <b>2</b>" as *u8), c) 123 gv_check("neg-control-malformed-wrong-tag-row-never-rendered" as *u8, (g_has(G_HTML, "bogus" as *u8) == 0) as i64, c) 124 gv_check("neg-control-malformed-short-row-never-rendered" as *u8, (g_has(G_HTML, "customization" as *u8) == 0) as i64, c) 125 gv_check("neg-control-under-cap-file-not-announced-as-capped" as *u8, (g_has(G_HTML, "READ-CAPPED" as *u8) == 0) as i64, c) 126 gv_check("html-says-a-proposal-is-a-lead-never-a-rung" as *u8, g_has(G_HTML, "A proposal is a lead, never a rung" as *u8), c) 127 128 // ---- JSON key ---- 129 let rj: i64 = g_render("planted" as *u8, G_JSON, 2) 130 gv_check_eq("json-returns-the-rendered-row-count" as *u8, rj, G_ROWS_EXPECTED, c) 131 gv_check("json-leads-with-a-comma-so-it-appends-to-an-open-object" as *u8, g_starts(G_JSON, ",\"proposed\":{" as *u8), c) 132 gv_check("json-count-three" as *u8, g_has(G_JSON, "\"count\":3" as *u8), c) 133 gv_check("json-malformed-two" as *u8, g_has(G_JSON, "\"malformed\":2" as *u8), c) 134 gv_check("json-read-capped-zero" as *u8, g_has(G_JSON, "\"read_capped\":0" as *u8), c) 135 gv_check("json-row-signal-field" as *u8, g_has(G_JSON, "\"signal\":\"DEFECT\"" as *u8), c) 136 gv_check("json-row-name-field" as *u8, g_has(G_JSON, "\"name\":\"Planted Title\",\"name_src\":\"row\"" as *u8), c) 137 gv_check("json-banked-name-and-its-source" as *u8, g_has(G_JSON, "\"name\":\"Portal 2\",\"name_src\":\"banked\"" as *u8), c) 138 gv_check("json-unresolved-name-is-the-appid-and-says-so" as *u8, g_has(G_JSON, "\"name\":\"999\",\"name_src\":\"appid\"" as *u8), c) 139 gv_check("neg-control-json-never-prints-620-as-a-name" as *u8, (g_has(G_JSON, "\"name\":\"620\"" as *u8) == 0) as i64, c) 140 gv_check("json-row-domain-field" as *u8, g_has(G_JSON, "\"domain\":\"planted\"" as *u8), c) 141 gv_check("json-names-its-writer" as *u8, g_has(G_JSON, "\"writer\":\"nx_intelmine_propose\"" as *u8), c) 142 gv_check("neg-control-json-never-carries-the-wrong-tag-row" as *u8, (g_has(G_JSON, "bogus" as *u8) == 0) as i64, c) 143 144 // ---- absent domain: nothing, in both modes ---- 145 let ah: i64 = g_render("absent" as *u8, G_ABS_HTML, 1) 146 gv_check_eq("neg-control-absent-domain-html-returns-zero" as *u8, ah, 0, c) 147 gv_check_eq("neg-control-absent-domain-html-emits-no-bytes" as *u8, gk_size(G_ABS_HTML), 0, c) 148 let aj: i64 = g_render("absent" as *u8, G_ABS_JSON, 2) 149 gv_check_eq("neg-control-absent-domain-json-returns-zero" as *u8, aj, 0, c) 150 gv_check_eq("neg-control-absent-domain-json-emits-no-key" as *u8, gk_size(G_ABS_JSON), 0, c) 151 152 // ---- read cap: announced, counted, and the prefix still renders ---- 153 let bh: i64 = g_render("big" as *u8, G_BIG_HTML, 1) 154 gv_check("read-cap-announced-on-a-file-at-the-cap" as *u8, g_has(G_BIG_HTML, "READ-CAPPED" as *u8), c) 155 gv_check("read-cap-prefix-still-renders-rows" as *u8, (bh > 0) as i64, c) 156 let bj: i64 = g_render("big" as *u8, G_BIG_JSON, 2) 157 gv_check("json-read-capped-one-on-a-file-at-the-cap" as *u8, g_has(G_BIG_JSON, "\"read_capped\":1" as *u8), c) 158 gv_check_eq("json-and-html-agree-on-the-capped-row-count" as *u8, bj, bh, c) 159 160 gv_values_head() 161 gv_kv("rows_html" as *u8, rh) 162 gv_kv("rows_json" as *u8, rj) 163 gv_kv("html_bytes" as *u8, gk_size(G_HTML)) 164 gv_kv("json_bytes" as *u8, gk_size(G_JSON)) 165 gv_kv("big_rows" as *u8, bh) 166 gv_kv("read_cap_bytes" as *u8, PR_READ_CAP) 167 return gv_verdict("nx_prop_pass_gate" as *u8, c, "prop_pass driven in-process on a planted fixture tree under /tmp: both modes on three proposals beside two malformed rows, a banked title read at render time beside an unresolved one, the absent-domain and the malformed-row controls, and a file at the read cap; every fixture asserts its own condition first; no real board is read" as *u8) 168}