code wiki / (root) / nx_research_engine_gate.nx

nx_research_engine_gate.nx source

↩ module page · 60 lines · 3628 B

1// nx_research_engine_gate.nx -- s-class gate for the shared research engine (nx_research_engine). Proves the 2// EXTRACT (rf_strip) and the GZIP-guard (rf_is_gzip) DETERMINISTICALLY, no network -- the functionality the engine 3// guarantees, measured + repeatable. This is the functionality the old copy-pasted fetchers carried, now 4// CENTRALIZED into one DRY engine and tested ONCE (rule 15). No functionality reduced; gzip-guard + extract proven. 5// (helpers carry a ge_ prefix -- the engine pulls in the TLS stack, so generic names like streq/slen/chk collide.) 6// criteria: 7// 1 rf_strip drops tags, keeps text: "<p>hi <b>there</b></p>" -> "hi there " 8// 2 rf_strip SUPPRESSES <script> body: "<script>var x=1;</script>OK" -> "OK" 9// 3 rf_strip collapses whitespace: "a b" -> "a b" 10// 4 rf_strip handles <style> + blocks: "<div>A</div><style>x{}</style><p>B</p>" -> "A B " 11// 5 rf_is_gzip: 0x1f 0x8b body detected (would skip), plain text NOT (would bank) 12// expect_exit: 0 license_tier: ORIGINAL 13import "nx_research_engine.nx" 14import "nx_gate_verdict.nx" 15 16func ge_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 17func ge_streq(a: *u8, an: i64, b: *u8) -> i64 { 18 var i: i64 = 0 19 while i < an { if (b[i] as i64) == 0 { return 0 } if a[i] != b[i] { return 0 } i = i + 1 } 20 if (b[an] as i64) != 0 { return 0 } 21 return 1 22} 23func ge_chk(name: *u8, ok: i64) -> i64 { 24 if ok == 1 { rf_puts(" PASS " as *u8); rf_puts(name); rf_puts("\n" as *u8); return 1 } 25 rf_puts(" FAIL " as *u8); rf_puts(name); rf_puts("\n" as *u8); return 0 26} 27func ge_tstrip(h: *u8, expect: *u8) -> i64 { 28 let o: *u8 = sys_mmap(4096) 29 let n: i64 = rf_strip(h, ge_slen(h), o, 4096) 30 return ge_streq(o, n, expect) 31} 32 33func main() -> i64 { 34 rf_puts("=== nx_research_engine gate -- shared fetch+extract+bank engine: functionality CENTRALIZED + tested ===\n" as *u8) 35 var pass: i64 = 0 36 var total: i64 = 0 37 let r1: i64 = ge_tstrip("<p>hi <b>there</b></p>" as *u8, "hi there " as *u8) 38 total = total + 1; pass = pass + ge_chk("T1 drop tags -> 'hi there '" as *u8, r1) 39 let r2: i64 = ge_tstrip("<script>var x=1;</script>OK" as *u8, "OK" as *u8) 40 total = total + 1; pass = pass + ge_chk("T2 suppress <script> body -> 'OK'" as *u8, r2) 41 let r3: i64 = ge_tstrip("a b" as *u8, "a b" as *u8) 42 total = total + 1; pass = pass + ge_chk("T3 collapse whitespace -> 'a b'" as *u8, r3) 43 let r4: i64 = ge_tstrip("<div>A</div><style>x{}</style><p>B</p>" as *u8, "A B " as *u8) 44 total = total + 1; pass = pass + ge_chk("T4 <style> + multi-block -> 'A B '" as *u8, r4) 45 let gz: *u8 = sys_mmap(8); gz[0] = 0x1f as u8; gz[1] = 0x8b as u8; gz[2] = 0 as u8 46 var t5: i64 = 0 47 if rf_is_gzip(gz, 3) == 1 { if rf_is_gzip("hello" as *u8, 5) == 0 { t5 = 1 } } 48 total = total + 1; pass = pass + ge_chk("T5 gzip guard: 0x1f8b skipped, text banked" as *u8, t5) 49 50 rf_puts("NX-RESEARCH-ENGINE-GATE " as *u8); rf_putn(pass); rf_puts(" / " as *u8); rf_putn(total) 51 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 52 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 53 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 54 let ctr__dry: *i64 = gv_ctr() 55 ctr__dry[0] = pass 56 ctr__dry[1] = total 57 let rc__dry: i64 = gv_verdict("RESEARCH-ENGINE-GATE" as *u8, ctr__dry, "extract + gzip-guard proven; ONE DRY engine, structured topic organs, no functionality lost)" as *u8) 58 sys_exit(rc__dry) 59 return rc__dry 60}