code wiki / _hdl_build / nx_search_snip_focus_20260912.nx

nx_search_snip_focus_20260912.nx source

↩ module page · 109 lines · 8183 B

1// nx_docportal_search_serve_gate.nx -- GATE for R2 (dss_serve). Writes a test PUBLIC shard, then feeds crafted 2// GET /search requests to dss_serve and asserts the rendered branded page: 200 + Content-Length, result count, 3// the hit's text present, empty-query prompt, no-match=0, and XSS-escaping of the echoed query (defensive at the 4// boundary). All over the REAL sovereign seg_store path, no tsv. license_tier: ORIGINAL 5import "nx_docportal_search_serve_snip_20260912.nx" 6import "nx_g_puts_lib.nx" 7// MIGRATED TO THE SHARED VERDICT MACHINERY 2026-08-15, same reason as nx_editdist_gate: this gate 8// hand-rolled pass/total and printed `=== dss_serve gate: 49/49 GREEN`, which nx_swcompare_evidence 9// cannot parse -- once wired it reported [GREEN] pass=0/0, so the verdict travelled on the exit code 10// while the EVIDENCE did not. ★A GATE WHOSE COUNT THE ROLLUP CANNOT READ IS HALF-WIRED, and a partial 11// regression in 49 teeth would have surfaced only as a binary flip. gv_ctr/gv_check make 12// declared-equals-executed BY CONSTRUCTION -- with 49 teeth a hand-maintained denominator is exactly 13// the thing that silently drifts when a tooth stops running. 14import "nx_gate_verdict.nx" 15 16func g_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 17func g_num(v: i64) -> i64 { 18 let bb: *u8 = sys_mmap(28); var m: i64 = v 19 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 20 let t: *u8 = sys_mmap(28); var k: i64 = 0 21 if m == 0 { t[0] = 48 as u8; k = 1 } 22 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 23 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 24 sys_write(1, bb, k); return 0 25} 26// does hay[0..hn) contain the null-terminated needle? 27func g_contains(hay: *u8, hn: i64, needle: *u8) -> i64 { 28 let nl: i64 = g_strlen(needle) 29 if nl == 0 { return 1 } 30 var i: i64 = 0 31 while i + nl <= hn { 32 var m: i64 = 1 33 var j: i64 = 0 34 while j < nl { if hay[i + j] != needle[j] { m = 0 } j = j + 1 } 35 if m == 1 { return 1 } 36 i = i + 1 37 } 38 return 0 39} 40func g_streq(a: *u8, b: *u8) -> i64 { 41 var i: i64 = 0 42 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 43 if b[i] != (0 as u8) { return 0 } 44 return 1 45} 46// Thin delegate so all 49 call sites read unchanged while the COUNTING is the shared one. 47func g_check(name: *u8, cond: i64, ctr: *i64) -> i64 { return gv_check(name, cond, ctr) } 48func g_check_unused(name: *u8, cond: i64, pass: *i64, total: *i64) -> i64 { 49 total[0] = total[0] + 1 50 g_puts(name) 51 if cond == 1 { pass[0] = pass[0] + 1; g_puts(" PASS\n") } else { g_puts(" FAIL\n") } 52 return 0 53} 54 55func main(argc: i64, argv: *i64) -> i64 { 56 let w: *i64 = ss_begin() 57 let snip_doc0: *u8 = "Wine Reference\nMain menu\nContents\nAccount\nMore navigation and tool links for visitors.\nRed wine carries a distinct aroma, and this sentence explains the color and flavor clearly." as *u8 58 ss_add(w, 1, "doc:981" as *u8, snip_doc0, g_strlen(snip_doc0)) 59 let snip_doc1: *u8 = "Snippet Boundary\nMain menu\nContents\nAccount\nMore navigation and tool links for visitors.\nEscapeterm describes \"quoted\" text with a backslash \\ and caf\xC3\xA9 in a complete useful sentence." as *u8 60 ss_add(w, 1, "doc:982" as *u8, snip_doc1, g_strlen(snip_doc1)) 61 let snip_doc2: *u8 = "Fallbackterm\nTiny body." as *u8 62 ss_add(w, 1, "doc:983" as *u8, snip_doc2, g_strlen(snip_doc2)) 63 let snip_doc3: *u8 = "Caps Reference\nMain menu\nContents\nAccount\nMore navigation and tool links for visitors.\nCapsterm describes bounded output with complete words describes bounded output with complete words describes bounded output with complete words describes bounded output with complete words describes bounded output with complete words describes bounded output with complete words ." as *u8 64 ss_add(w, 1, "doc:984" as *u8, snip_doc3, g_strlen(snip_doc3)) 65 let snip_doc4: *u8 = "Word Reference\nMain menu\nContents\nAccount\nMore navigation and tool links for visitors.\nDogmatic terms appear in this irrelevant sentence with enough prose to qualify.\nA dog needs daily exercise, and this sentence describes that specific animal accurately." as *u8 66 ss_add(w, 1, "doc:985" as *u8, snip_doc4, g_strlen(snip_doc4)) 67 68 sys_unlinkat("knowledge/store/dp-ssgatesnipfocus20260912-pub-manifest.txt\x00" as *u8) 69 ss_commit("knowledge/store/dp-ssgatesnipfocus20260912-pub-" as *u8, w, 1) 70 let dom: *u8 = "ssgatesnipfocus20260912" as *u8 71 let ctr: *i64 = gv_ctr() 72 let out: *u8 = sys_mmap(DSV_OUTCAP) 73 let snip_req0: *u8 = "GET /api/search?q=red+wine&scope=site HTTP/1.1\r\n\r\n" as *u8 74 let snip_n0: i64 = dss_api_search(dom, snip_req0, g_strlen(snip_req0), out) 75 g_check("API selects relevant prose after navigation" as *u8, g_contains(out, snip_n0, "\"snippet\":\"Red wine carries a distinct aroma, and this sentence explains the color and flavor clearly\"" as *u8), ctr) 76 g_puts("SNIP-API-0 BEGIN\n"); sys_write(1, out, snip_n0); g_puts("\nSNIP-API-0 END\n") 77 let snip_req1: *u8 = "GET /api/search?q=escapeterm&scope=site HTTP/1.1\r\n\r\n" as *u8 78 let snip_n1: i64 = dss_api_search(dom, snip_req1, g_strlen(snip_req1), out) 79 g_check("API escapes JSON without HTML entities or highlighting" as *u8, g_contains(out, snip_n1, "\"snippet\":\"Escapeterm describes \\\"quoted\\\" text with a backslash \\\\ and caf\xC3\xA9 in a complete useful sentence\"" as *u8), ctr) 80 g_puts("SNIP-API-1 BEGIN\n"); sys_write(1, out, snip_n1); g_puts("\nSNIP-API-1 END\n") 81 let snip_req2: *u8 = "GET /api/search?q=fallbackterm&scope=site HTTP/1.1\r\n\r\n" as *u8 82 let snip_n2: i64 = dss_api_search(dom, snip_req2, g_strlen(snip_req2), out) 83 g_check("API fallback unchanged without qualifying prose" as *u8, g_contains(out, snip_n2, "\"snippet\":\"Tiny body.\"" as *u8), ctr) 84 g_puts("SNIP-API-2 BEGIN\n"); sys_write(1, out, snip_n2); g_puts("\nSNIP-API-2 END\n") 85 let snip_req3: *u8 = "GET /api/search?q=dog&scope=site HTTP/1.1\r\n\r\n" as *u8 86 let snip_n3: i64 = dss_api_search(dom, snip_req3, g_strlen(snip_req3), out) 87 g_check("API chooses whole-word match over dogmatic decoy" as *u8, g_contains(out, snip_n3, "\"snippet\":\"A dog needs daily exercise, and this sentence describes that specific animal accurately\"" as *u8), ctr) 88 g_puts("SNIP-API-3 BEGIN\n"); sys_write(1, out, snip_n3); g_puts("\nSNIP-API-3 END\n") 89 let snip_html_req: *u8 = "GET /search?q=red+wine&scope=site HTTP/1.1\r\n\r\n" as *u8 90 let snip_html_n: i64 = dss_serve(dom, snip_html_req, g_strlen(snip_html_req), out) 91 g_check("HTML keeps same selected prose and highlighting" as *u8, g_contains(out, snip_html_n, "<div class=s><b>Red</b> <b>wine</b> carries a distinct aroma, and this sentence explains the color and flavor clearly</div>" as *u8), ctr) 92 let snip_cap_req: *u8 = "GET /api/search?q=capsterm&scope=site HTTP/1.1\r\n\r\n" as *u8 93 let snip_cap_n: i64 = dss_api_search(dom, snip_cap_req, g_strlen(snip_cap_req), out) 94 g_puts("SNIP-CAP BEGIN\n"); sys_write(1, out, snip_cap_n); g_puts("\nSNIP-CAP END\n") 95 96 97 g_check("API retains byte cap and whole-word end" as *u8, g_contains(out, snip_cap_n, "\"snippet\":\"Capsterm describes bounded output with complete words describes bounded output with complete words describes bounded output with complete words describes bounded output with complete words describes bounded output with complete words\"" as *u8), ctr) 98 let empty_tbl: *u8 = sys_mmap(272) 99 ss_tok_table(empty_tbl) 100 let empty_ptrs: *i64 = sys_mmap(DSS_MAXTERMS * 8) as *i64 101 let empty_box: *i64 = sys_mmap(32) as *i64 102 let empty_rc: i64 = dsv_snippet_span("" as *u8, 0, 0, empty_ptrs, 0, empty_tbl, dsv_slot(empty_box, 0), dsv_slot(empty_box, 1), dsv_slot(empty_box, 2)) 103 var empty_ok: i64 = 0 104 if empty_rc == 0 { if empty_box[0] == 0 { if empty_box[1] == 0 { empty_ok = 1 } } } 105 g_check("Empty document yields empty raw span" as *u8, empty_ok, ctr) 106 let rc: i64 = gv_verdict("SNIPFOCUS" as *u8, ctr, "site-fixture snippet selection only; full gate web precondition remains separate" as *u8) 107 sys_exit(rc) 108 return rc 109}