code wiki / _hdl_build / nx_search_ship_gate.nx

nx_search_ship_gate.nx source

↩ module page · 113 lines · 10782 B

1// nx_search_ship_gate.nx -- THE PARSERS OF THE SEARCH SHIP LOOP, DRIVEN ON PLANTED FIXTURES (2026-09-14). The loop 2// reads every decision out of a receipt or a probe body; a parser that reads the wrong field turns a REFUSED build 3// into a shipped one or a 12 s probe into a pass. Each tooth plants the exact shape the live organs emit (a 4// /api/build receipt, a nx_qrels_bench arm, a nx_https_get first line plus a phase_us block, a uat_journeys row, 5// a probes conf) and every positive tooth has a neg-control that must NOT parse. No fork, no file, no socket. 6// license_tier: ORIGINAL expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_gate_verdict.nx" 9import "nx_search_ship_lib.nx" 10 11const SG_CAP: i64 = 4096 12const SG_BAR_DFLT: i64 = 4242 13 14func main() -> i64 { 15 gv_puts("nx_search_ship_gate -- the search ship loop's parsers on planted fixtures\n" as *u8) 16 let ctr: *i64 = gv_ctr() 17 // T1 decimal after a needle, the fetcher's first line 18 let l1: *u8 = "Anishi-xfer recv=1234ms dec=1ms cl-stop" as *u8 19 gv_check("T1 recv= parses 1234" as *u8, (sx_int_after(l1, sx_slen(l1), "recv=" as *u8) == 1234) as i64, ctr) 20 gv_check("T1b neg-control-absent-needle reads -1" as *u8, (sx_int_after(l1, sx_slen(l1), "nope=" as *u8) == (0 - 1)) as i64, ctr) 21 let l1c: *u8 = "x=-5 y=" as *u8 22 gv_check("T1c a leading minus is honoured" as *u8, (sx_int_after(l1c, sx_slen(l1c), "x=" as *u8) == (0 - 5)) as i64, ctr) 23 gv_check("T1d neg-control-needle-with-no-digit reads -1" as *u8, (sx_int_after(l1c, sx_slen(l1c), "y=" as *u8) == (0 - 1)) as i64, ctr) 24 // T2 the quoted string after a JSON key, by key never by first hex run 25 let j: *u8 = "{\"action\":\"BUILT\",\"bytes\":1650936,\"sha256\":\"58a23da5eaca\",\"src_path\":\"/x/nx_docportal_admin_daemon.nx\"}" as *u8 26 let d: *u8 = sys_mmap(128) 27 let n2: i64 = sx_json_str(j, sx_slen(j), "\"sha256\":" as *u8, d, 128) 28 gv_check("T2 sha256 read by key" as *u8, (sx_streq(d, "58a23da5eaca" as *u8) == 1) as i64, ctr) 29 gv_check("T2b its length is returned" as *u8, (n2 == 12) as i64, ctr) 30 let n2c: i64 = sx_json_str(j, sx_slen(j), "\"nosuch\":" as *u8, d, 128) 31 gv_check("T2c neg-control-missing-key reads empty" as *u8, (n2c == 0) as i64, ctr) 32 gv_check("T2d neg-control-missing-key leaves dst empty" as *u8, (d[0] == (0 as u8)) as i64, ctr) 33 // T3 per-query lines of two referee arms 34 let arm_a: *u8 = " web-shard-opened: PASS\n q=ice cream n=30 ndcg=65536 mrr=65536 p@k=13107 g1=2\n q=red wine n=30 ndcg=43087 mrr=65536 p@k=32768 g1=2\n corpus_docs=375624\n" as *u8 35 let arm_b: *u8 = " web-shard-opened: PASS\n q=ice cream n=30 ndcg=65536 mrr=65536 p@k=13107 g1=2\n q=red wine n=30 ndcg=43087 mrr=65536 p@k=32768 g1=2\n corpus_docs=375630\n" as *u8 36 let arm_c: *u8 = " web-shard-opened: PASS\n q=ice cream n=30 ndcg=65536 mrr=65536 p@k=13107 g1=2\n q=red wine n=30 ndcg=43000 mrr=65536 p@k=32768 g1=2\n corpus_docs=375624\n" as *u8 37 let qa: *u8 = sys_mmap(SG_CAP) 38 let qb: *u8 = sys_mmap(SG_CAP) 39 let qc: *u8 = sys_mmap(SG_CAP) 40 let la: *i64 = sys_mmap(16) as *i64 41 let lb: *i64 = sys_mmap(16) as *i64 42 let lc: *i64 = sys_mmap(16) as *i64 43 let na: i64 = sx_lines_with(arm_a, sx_slen(arm_a), " q=" as *u8, qa, SG_CAP, la) 44 let nb: i64 = sx_lines_with(arm_b, sx_slen(arm_b), " q=" as *u8, qb, SG_CAP, lb) 45 let nc: i64 = sx_lines_with(arm_c, sx_slen(arm_c), " q=" as *u8, qc, SG_CAP, lc) 46 gv_check("T3 two query lines counted per arm" as *u8, (na == 2) as i64, ctr) 47 gv_check("T3b fixture-reached-condition the third arm also has two" as *u8, (nc == 2) as i64, ctr) 48 gv_check("T3c identical rankings compare IDENTICAL even when corpus_docs differs" as *u8, (sx_bytes_eq(qa, la[0], qb, lb[0]) == 1) as i64, ctr) 49 gv_check("T3d neg-control-a-changed-second-line is NOT identical" as *u8, (sx_bytes_eq(qa, la[0], qc, lc[0]) == 0) as i64, ctr) 50 gv_check("T3e the first differing line is named as 2" as *u8, (sx_first_diff_line(qa, la[0], qc, lc[0]) == 2) as i64, ctr) 51 gv_check("T3f identical buffers name line 0" as *u8, (sx_first_diff_line(qa, la[0], qb, lb[0]) == 0) as i64, ctr) 52 gv_check("T3g corpus_docs read out of each arm" as *u8, (sx_int_after(arm_b, sx_slen(arm_b), "corpus_docs=" as *u8) == 375630) as i64, ctr) 53 // T4 the phase timers out of a probe body 54 let body: *u8 = "Anishi-xfer recv=664ms dec=1ms cl-stop\nHTTP/1.1 200 OK\n\n{\"v\":1,\"l0\":{\"covered\":2016,\"walked\":0,\"nopos\":0},\"phase_us\":{\"prep\":326053,\"s1\":104441,\"filt\":3061,\"short\":6,\"l0loc\":12445,\"l0dec\":60865,\"walk\":5007,\"score\":1642,\"auth\":69203,\"div\":25278,\"sel\":1014,\"total\":609015,\"cand\":2048,\"memo\":0}}" as *u8 55 let ph: *i64 = sys_mmap(8 * SX_PHASE_SLOTS) as *i64 56 let r4: i64 = sx_phase(body, sx_slen(body), ph) 57 gv_check("T4 phase block found" as *u8, (r4 == 1) as i64, ctr) 58 gv_check("T4a recv 664" as *u8, (ph[0] == 664) as i64, ctr) 59 gv_check("T4b prep 326053" as *u8, (ph[1] == 326053) as i64, ctr) 60 gv_check("T4c s1 104441" as *u8, (ph[2] == 104441) as i64, ctr) 61 gv_check("T4d l0dec 60865" as *u8, (ph[3] == 60865) as i64, ctr) 62 gv_check("T4e auth 69203" as *u8, (ph[4] == 69203) as i64, ctr) 63 gv_check("T4f total 609015" as *u8, (ph[6] == 609015) as i64, ctr) 64 gv_check("T4g cand 2048" as *u8, (ph[7] == 2048) as i64, ctr) 65 let body503: *u8 = "Anishi-xfer recv=39ms dec=0ms cl-stop\nHTTP/1.1 503 Service Unavailable\n\n<h1>503 backend unavailable</h1>" as *u8 66 let r4n: i64 = sx_phase(body503, sx_slen(body503), ph) 67 gv_check("T4h neg-control-a-503-body has no phase block" as *u8, (r4n == 0) as i64, ctr) 68 gv_check("T4i neg-control-a-503-body still reports its recv" as *u8, (ph[0] == 39) as i64, ctr) 69 gv_check("T4j neg-control-a-503-body leaves total ABSENT (-1), never a number" as *u8, (ph[6] == (0 - 1)) as i64, ctr) 70 // T5 the consumer bar out of a journeys conf 71 let jc: *u8 = "# rows\nsearch-landing|https://x/search|127.0.0.1:8443|2000|Nishi Search\nsearch-query|https://x/search?q=a+b|127.0.0.1:8443|3000|result(s) for\n" as *u8 72 gv_check("T5 search-query bar reads 3000" as *u8, (sx_journey_bar(jc, sx_slen(jc), "search-query" as *u8, SG_BAR_DFLT) == 3000) as i64, ctr) 73 gv_check("T5b search-landing bar reads 2000 (the id selects the row)" as *u8, (sx_journey_bar(jc, sx_slen(jc), "search-landing" as *u8, SG_BAR_DFLT) == 2000) as i64, ctr) 74 gv_check("T5c neg-control-unknown-id falls back to the default" as *u8, (sx_journey_bar(jc, sx_slen(jc), "nosuch" as *u8, SG_BAR_DFLT) == SG_BAR_DFLT) as i64, ctr) 75 // T6 url encoding of a probe query 76 let u: *u8 = sys_mmap(256) 77 sx_urlenc(u, 0, "family photos" as *u8) 78 gv_check("T6 space becomes %20" as *u8, (sx_streq(u, "family%20photos" as *u8) == 1) as i64, ctr) 79 sx_urlenc(u, 0, "kyoka" as *u8) 80 gv_check("T6b neg-control-no-space is unchanged" as *u8, (sx_streq(u, "kyoka" as *u8) == 1) as i64, ctr) 81 // T7 probes out of a conf: comments and blank lines skipped, CR stripped 82 let pc: *u8 = "# probes\nfamily photos\n\ncity parks\r\n# end\n" as *u8 83 let pr: *u8 = sys_mmap(96 * 4) 84 let npr: i64 = sx_probes(pc, sx_slen(pc), pr, 96, 4) 85 gv_check("T7 two probes" as *u8, (npr == 2) as i64, ctr) 86 gv_check("T7b first is family photos" as *u8, (sx_streq(pr, "family photos" as *u8) == 1) as i64, ctr) 87 gv_check("T7c second is city parks with its CR stripped" as *u8, (sx_streq((pr as i64 + 96) as *u8, "city parks" as *u8) == 1) as i64, ctr) 88 let pc0: *u8 = "# only comments\n\n" as *u8 89 gv_check("T7d neg-control-a-conf-of-comments yields zero probes" as *u8, (sx_probes(pc0, sx_slen(pc0), pr, 96, 4) == 0) as i64, ctr) 90 // T8 the agent decision: adopt only the mechanically safe class, hold everything else for the root 91 gv_check("T8 same bytes as live is NOCHANGE" as *u8, (sx_agent_decide(1, 1, 0) == SX_AGENT_NOCHANGE) as i64, ctr) 92 gv_check("T8b same bytes as live is NOCHANGE even if the referee moved (nothing to adopt)" as *u8, (sx_agent_decide(1, 0, 0) == SX_AGENT_NOCHANGE) as i64, ctr) 93 gv_check("T8c a differing candidate with referee IDENTICAL and lost 0 is ADOPT" as *u8, (sx_agent_decide(0, 1, 0) == SX_AGENT_ADOPT) as i64, ctr) 94 gv_check("T8d neg-control-a-moved-ranking is HELD for the root, never adopted" as *u8, (sx_agent_decide(0, 0, 0) == SX_AGENT_HOLD) as i64, ctr) 95 gv_check("T8e neg-control-a-lost-printable-run is HELD even with referee IDENTICAL" as *u8, (sx_agent_decide(0, 1, 1) == SX_AGENT_HOLD) as i64, ctr) 96 gv_check("T8f neg-control-moved-and-lost is HELD" as *u8, (sx_agent_decide(0, 0, 3) == SX_AGENT_HOLD) as i64, ctr) 97 // T9 the HTML SERP witness: both the status line and the journey marker, never one alone 98 let hg: *u8 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<title>family photos - Nishi Search</title><p class=meta>1,204 result(s) for family photos</p>" as *u8 99 gv_check("T9 status line plus marker is OK" as *u8, (sx_html_ok(hg, sx_slen(hg), "result(s) for" as *u8) == 1) as i64, ctr) 100 let hg2: *u8 = "HTTP/1.1 200 OK\r\n\r\n<title>Nishi Search</title>" as *u8 101 gv_check("T9b neg-control-a-200-shell-without-the-marker is not OK" as *u8, (sx_html_ok(hg2, sx_slen(hg2), "result(s) for" as *u8) == 0) as i64, ctr) 102 let hg3: *u8 = "HTTP/1.1 503 Service Unavailable\r\n\r\n<p>result(s) for</p>" as *u8 103 gv_check("T9c neg-control-a-marker-under-a-503 is not OK" as *u8, (sx_html_ok(hg3, sx_slen(hg3), "result(s) for" as *u8) == 0) as i64, ctr) 104 // T10 the journey field reader: url and must_contain columns of a row, CR stripped, the id bounded by its pipe 105 let jc: *u8 = "search-landing|https://x/search|127.0.0.1:8443|2000|Nishi Search\r\nsearch-query|https://x/search?q=family+photos|127.0.0.1:8443|3000|result(s) for\n" as *u8 106 let jf: *u8 = sys_mmap(256) 107 gv_check("T10 url column of search-query copies bytes" as *u8, (sx_journey_field(jc, sx_slen(jc), "search-query" as *u8, SX_JF_URL, jf, 256) > 0) as i64, ctr) 108 gv_check("T10b url value exact" as *u8, (sx_streq(jf, "https://x/search?q=family+photos" as *u8) == 1) as i64, ctr) 109 gv_check("T10c must_contain of a CRLF row copies bytes" as *u8, (sx_journey_field(jc, sx_slen(jc), "search-landing" as *u8, SX_JF_MUST, jf, 256) > 0) as i64, ctr) 110 gv_check("T10d must_contain value has its CR stripped" as *u8, (sx_streq(jf, "Nishi Search" as *u8) == 1) as i64, ctr) 111 gv_check("T10e neg-control-an-id-that-is-a-prefix-of-a-row-id yields 0" as *u8, (sx_journey_field(jc, sx_slen(jc), "search" as *u8, SX_JF_URL, jf, 256) == 0) as i64, ctr) 112 return gv_verdict("NX-SEARCH-SHIP-GATE" as *u8, ctr, "every receipt and probe field the search ship loop decides on parses exactly on its planted shape, and every planted wrong shape refuses" as *u8) 113}