code wiki / (root) / nx_aimode_read_gate.nx

nx_aimode_read_gate.nx source

↩ module page · 115 lines · 7716 B

1// nx_aimode_read_gate.nx -- proves BR50's parser (nx_aimode_lib) on PLANTED fixtures, and the live read of 2// the operator's AI Mode share behind gv_need (network precondition -> SKIP offline, never RED). 3// Parser teeth run on literals assembled here (no network): the /async/folwr continuation extractor with its 4// &amp; / & / \/ un-escaping, the citation-beacon counter, and the shell/consent/sign-in classifiers. 5// NEG-CONTROL: a planted enable-JS shell must classify as a shell with ZERO citations, i.e. br_share_read 6// would refuse it REFUSED-NO-ANSWER -- it must NOT read as an answer. 7// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_gate_verdict.nx" 10import "nx_x509_trust_store.nx" 11import "nx_trust_store_load_from_certdata.nx" 12import "nx_aimode_lib.nx" 13import "nx_atomic_rewrite.nx" 14 15const G_CERTCAP: i64 = 4194304 16const G_OUTCAP: i64 = 8388608 17const G_CITECAP: i64 = 262144 18const G_URLCAP: i64 = 16384 19 20func g_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 21// byte-exact compare of NUL-terminated a vs b. Returns 1/0. 22func g_streq(a: *u8, b: *u8) -> i64 { 23 var i: i64 = 0 24 while a[i] != (0 as u8) { if (a[i]&0xff) != (b[i]&0xff) { return 0 } i = i + 1 } 25 if b[i] != (0 as u8) { return 0 } 26 return 1 27} 28 29func main() -> i64 { 30 let ctr: *i64 = gv_ctr() 31 gv_head("nx_aimode_read_gate -- AI Mode share reader: continuation extract, citation count, refusal classifiers, live read" as *u8) 32 33 // ---- fixture 1: warm search doc carrying the /async/folwr continuation (&amp;-escaped, quote-terminated) ---- 34 let warm: *u8 = "<div jsdata=\x22x\x22 data-p=\x22/async/folwr?a=1&amp;garc=XY&amp;url=z9\x22></div><script>foo</script>" as *u8 35 var wl: i64 = g_slen(warm) 36 let folwr: *u8 = sys_mmap(G_URLCAP) 37 let fl: i64 = am_extract_folwr(warm, wl, folwr) 38 let expect_folwr: *u8 = "https://www.google.com/async/folwr?a=1&garc=XY&url=z9" as *u8 39 gv_check("folwr-extracted-absolute-and-unescaped" as *u8, g_streq(folwr, expect_folwr), ctr) 40 gv_check_eq("folwr-extracted-length" as *u8, fl, g_slen(expect_folwr), ctr) 41 42 // a doc with no continuation -> length 0 43 let nofol: *u8 = "<html><body>no continuation here</body></html>" as *u8 44 gv_check_eq("folwr-absent-returns-zero" as *u8, am_extract_folwr(nofol, g_slen(nofol), folwr), 0, ctr) 45 46 // ---- fixture 2: answer fragment with THREE citation beacons + prose ---- 47 let ans: *u8 = "<div>The most advanced framework couples continuum mechanics and multi-body dynamics.<a ping=\x22/url?sa=t&amp;url=CAESaaa\x22>SimTK</a> more prose about hyperelastic tissue and neural operators.<a ping=\x22/url?sa=t&amp;url=CAESbbb\x22>NIH</a> and yet more.<a ping=\x22/url?sa=t&amp;url=CAESccc\x22>ScienceDirect</a></div>" as *u8 48 var al: i64 = g_slen(ans) 49 let cites: *u8 = sys_mmap(G_CITECAP) 50 let nc: i64 = am_citations(ans, al, cites, G_CITECAP) 51 gv_check_eq("citations-counted-exact" as *u8, nc, 3, ctr) 52 // the citation sink carries 3 newline-terminated beacon references, &amp; decoded to & 53 gv_check("citation-list-has-decoded-url-param" as *u8, (ms_find(cites, g_slen(cites), "url=CAESbbb" as *u8, 10, 0) >= 0) as i64, ctr) 54 gv_check("citation-list-amp-decoded" as *u8, (ms_find(cites, g_slen(cites), "&amp;" as *u8, 5, 0) < 0) as i64, ctr) 55 56 gv_check("citation-list-byte-exact-preserves-leading-slash-and-ampersand" as *u8, g_streq(cites, "/url?sa=t&url=CAESaaa\n/url?sa=t&url=CAESbbb\n/url?sa=t&url=CAESccc\n" as *u8), ctr) 57 58 // ---- fixture 3: refusal classifiers ---- 59 let shell: *u8 = "<html><head><title>Google Search</title></head><body><noscript>enable js: /httpservice/retry/enablejs?sei=AAA</noscript></body></html>" as *u8 60 let consent: *u8 = "<html>Before you continue to Google -- consent.google.com/save</html>" as *u8 61 let signin: *u8 = "<html>please visit https://accounts.google.com/ServiceLogin to continue</html>" as *u8 62 gv_check_eq("shell-classified" as *u8, am_is_shell(shell, g_slen(shell)), 1, ctr) 63 gv_check_eq("consent-classified" as *u8, am_is_consent(consent, g_slen(consent)), 1, ctr) 64 gv_check_eq("signin-classified" as *u8, am_is_signin(signin, g_slen(signin)), 1, ctr) 65 66 // ---- NEG-CONTROL: the shell is NOT an answer -- shell-flagged AND zero citations -> br refuses NO-ANSWER ---- 67 let shell_cites: i64 = am_citations(shell, g_slen(shell), 0 as *u8, 0) 68 gv_check("neg-control-shell-refused-not-answer" as *u8, ((am_is_shell(shell, g_slen(shell)) == 1) as i64) * ((shell_cites == 0) as i64), ctr) 69 // and the answer fixture is NOT a shell (positive control the neg-control is paired with) 70 gv_check("answer-fixture-not-shell" as *u8, (am_is_shell(ans, al) == 0) as i64, ctr) 71 72 // ---- gv_bite: the extractor must FIND the continuation (good) and a doc without it must return 0 (bad) ---- 73 gv_bite("bite-folwr-present-vs-absent" as *u8, (am_extract_folwr(nofol, g_slen(nofol), folwr) == 0) as i64, (am_extract_folwr(warm, wl, folwr) == 0) as i64, ctr) 74 75 let output_path:*u8="knowledge/gates/aimode-atomic-output-t341.txt" 76 let output_a:*u8="retained prior output\n";let output_b:*u8="verified replacement\n" 77 let output_a_len:i64=g_slen(output_a);let output_b_len:i64=g_slen(output_b) 78 let first_rc:i64=atomic_rewrite_checked(output_path,output_a,output_a_len) 79 gv_check("checked-output-write-exact",first_rc==0&&ar_same_file(output_path,output_a,output_a_len)==1,ctr) 80 let bad_write:i64=atomic_rewrite_checked(output_path,output_b,0) 81 gv_check("checked-output-refusal-preserves-existing-bytes",bad_write==AR_CHECK_EMPTY&&ar_same_file(output_path,output_a,output_a_len)==1,ctr) 82 let replace_rc:i64=atomic_rewrite_checked(output_path,output_b,output_b_len) 83 gv_check("checked-output-replacement-exact",replace_rc==0&&ar_same_file(output_path,output_b,output_b_len)==1,ctr) 84 gv_check("checked-output-missing-parent-refused",atomic_rewrite_checked("knowledge/gates/aimode-absent-parent-t341/result.txt",output_b,output_b_len)==AR_CHECK_OPEN,ctr) 85 86 // ---- LIVE (behind gv_need: network + a populated answer -> SKIP offline, never RED) ---- 87 let store: *TrustStore = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, G_CERTCAP) as *TrustStore 88 let out: *u8 = sys_mmap(G_OUTCAP) 89 let lcites: *u8 = sys_mmap(G_CITECAP) 90 let finalu: *u8 = sys_mmap(G_URLCAP) 91 let lnc: *i64 = (sys_mmap(8)) as *i64 92 let ltl: *i64 = (sys_mmap(8)) as *i64 93 var lrc: i64 = 0 - 1 94 if (store as i64) != 0 { 95 lrc = br_share_read("https://share.google/aimode/vVS1jO66c6HI3D4YN" as *u8, store, out, G_OUTCAP, lcites, G_CITECAP, finalu, G_URLCAP, lnc, ltl, 0) 96 } 97 let present: i64 = gv_need("network + AI-Mode answer for the operator's share" as *u8, (lrc == AM_OK) as i64, ctr) 98 if present == 1 { 99 // DONE-RULE proxy (the answer is nondeterministic, so assert the shell/answer discriminator, not exact text): 100 // substantial prose and multiple citations distinguish the six-layer answer from the 92KB script shell. 101 gv_check("live-answer-substantial-not-shell" as *u8, (ltl[0] >= 2000) as i64, ctr) 102 gv_check("live-answer-multi-citation" as *u8, (lnc[0] >= 3) as i64, ctr) 103 } 104 105 gv_values_head() 106 gv_kv("folwr_extract_len" as *u8, fl) 107 gv_kv("fixture_citations" as *u8, nc) 108 gv_kv("live_rc" as *u8, lrc) 109 gv_kv("live_text_bytes" as *u8, ltl[0]) 110 gv_kv("live_citations" as *u8, lnc[0]) 111 112 let rc: i64 = gv_verdict("NX-AIMODE-READ-GATE" as *u8, ctr, "continuation extractor + citation counter + refusal classifiers proven on fixtures; live share read behind gv_need" as *u8) 113 gv_exit(rc) 114 return rc 115}