nx_cite_redline_gate.nx source
↩ module page · 116 lines · 6286 B
1// nx_cite_redline_gate.nx -- F993 PRODUCT SURFACE: document-level citation redline.
2// A chatbot verifies one quote; a drafting tool must verify EVERY citation in a filed paragraph and
3// strike the ones that cannot be grounded. This proves the whole-document scanner catches a real mix
4// -- a good cite, a fabricated cite, a made-up source, and the malformed-citation dodge -- and that the
5// document-level green light (cite_doc_clean) refuses a paragraph carrying even one bad citation.
6// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
7
8import "nx_cite_lib.nx"
9// D001 MIGRATION 2026-08-16 -- third and last of this family; see the note in nx_clm_gate.nx.
10import "nx_gate_verdict.nx"
11
12func rl_ck(cnt: *i64, name: *u8, got: i64, want: i64) -> i64 {
13 // gv_check owns the counters and the PASS/FAIL word; the VALUES stay, because ★A GATE THAT REPORTS
14 // A BOOLEAN CANNOT SAY WHY.
15 var ok: i64 = 0
16 if got == want { ok = 1 }
17 let r: i64 = gv_check(name, ok, cnt)
18 gv_puts(" got=" as *u8); gv_num(got); gv_puts(" want=" as *u8); gv_num(want); gv_puts("\n" as *u8)
19 return r
20}
21func rl_id(tag: *u8, nonce: i64, out: *u8) -> i64 {
22 var o: i64 = mt_catcopy(out, 0, tag)
23 o = mt_catn(out, o, nonce)
24 out[o] = 0 as u8
25 return o
26}
27
28func main(argc: i64, argv: *i64) -> i64 {
29 // FIXTURE MOVED OUT OF THE SWEPT STORE (2026-08-07). knowledge/store/ is walked every 600s by
30 // the nx_segguard beat; this gate's fixture is one of TEN measured as actually folded by it. A
31 // fold landing mid-run rewrites the manifest under the code being measured, so a RED could not
32 // be attributed. Proven on the sibling defect: the SAME code went RED on a knowledge/store
33 // fixture and GREEN 24/24 on a /tmp one -- the RED tracked the FIXTURE, not the code.
34 // Created at SETUP, not teardown: a teardown does not run when a run crashes.
35 sys_mkdir("/tmp/redlinegate\x00" as *u8, 0x1ed)
36 let pfx: *u8 = "/tmp/redlinegate/redlinegate-" as *u8
37 let nonce: i64 = sys_now_us()
38 let cnt: *i64 = gv_ctr()
39
40 gv_head("NISHI-CITE-REDLINE-GATE (F993 product surface: verify every citation in a filed paragraph)" as *u8)
41
42 // store one real source; use a FIXED short id so the doc can reference it literally
43 let sid: *u8 = sys_mmap(64)
44 rl_id("S-" as *u8, nonce, sid)
45 cite_source_put(pfx, sid, "The trust account shall be reconciled quarterly." as *u8)
46
47 let rep: *u8 = sys_mmap(65536)
48
49 // ---- D1: an all-good document -> ZERO struck, clean ----
50 // build "...<<S-nonce|The trust account shall be reconciled quarterly.>>..."
51 let d1: *u8 = sys_mmap(4096)
52 var o: i64 = mt_catcopy(d1, 0, "Per the rule, <<" as *u8)
53 o = mt_catcopy(d1, o, sid)
54 o = mt_catcopy(d1, o, "|The trust account shall be reconciled quarterly.>> as required." as *u8)
55 d1[o] = 0 as u8
56 rl_ck(cnt, "D1 all-verified document -> 0 struck" as *u8, cite_scan_doc(pfx, d1, rep), 0)
57 rl_ck(cnt, "D1a document is clean (filable)" as *u8, cite_doc_clean(pfx, d1), 1)
58
59 // ---- D2: a document with a FABRICATED quote to the real source -> 1 struck ----
60 let d2: *u8 = sys_mmap(4096)
61 o = mt_catcopy(d2, 0, "The court held <<" as *u8)
62 o = mt_catcopy(d2, o, sid)
63 o = mt_catcopy(d2, o, "|The trust account may be reconciled whenever convenient.>> here." as *u8)
64 d2[o] = 0 as u8
65 rl_ck(cnt, "D2 fabricated quote -> 1 struck" as *u8, cite_scan_doc(pfx, d2, rep), 1)
66 rl_ck(cnt, "neg-control-D2a fabricated-quote document is NOT clean (never silently filable)" as *u8, cite_doc_clean(pfx, d2), 0)
67
68 // ---- D3: a document citing a MADE-UP source -> 1 struck ----
69 let d3: *u8 = sys_mmap(4096)
70 o = mt_catcopy(d3, 0, "See <<Smith-v-Nobody-999|anything at all>> for support." as *u8)
71 d3[o] = 0 as u8
72 rl_ck(cnt, "D3 made-up source -> 1 struck" as *u8, cite_scan_doc(pfx, d3, rep), 1)
73
74 // ---- D4: a MIX of good + fabricated + missing-source in one paragraph -> exactly 2 struck ----
75 let d4: *u8 = sys_mmap(4096)
76 o = mt_catcopy(d4, 0, "First <<" as *u8)
77 o = mt_catcopy(d4, o, sid)
78 o = mt_catcopy(d4, o, "|The trust account shall be reconciled quarterly.>>" as *u8) // good
79 o = mt_catcopy(d4, o, " and second <<" as *u8)
80 o = mt_catcopy(d4, o, sid)
81 o = mt_catcopy(d4, o, "|reconciled monthly>>" as *u8) // fabricated
82 o = mt_catcopy(d4, o, " and third <<Ghost-Case-1|whatever>> done." as *u8) // missing source
83 d4[o] = 0 as u8
84 rl_ck(cnt, "D4 mixed paragraph (1 good, 2 bad) -> exactly 2 struck" as *u8, cite_scan_doc(pfx, d4, rep), 2)
85
86 // ---- D5: THE DODGE. An UNTERMINATED citation (no closing >>) must be STRUCK, not skipped ----
87 let d5: *u8 = sys_mmap(4096)
88 o = mt_catcopy(d5, 0, "Sneaky <<" as *u8)
89 o = mt_catcopy(d5, o, sid)
90 o = mt_catcopy(d5, o, "|reconciled monthly with no closing marker so verification is skipped" as *u8)
91 d5[o] = 0 as u8
92 // ★A CONTROL NOBODY CAN FIND IS A CONTROL NOBODY MAINTAINS. D5 is the deny-side control that the
93 // trivial wrong implementation cannot pass: a scanner that only inspects WELL-FORMED citations
94 // reports this document clean, which is precisely the dodge.
95 rl_ck(cnt, "neg-control-D5 unterminated citation (the dodge) -> STRUCK not skipped" as *u8, cite_scan_doc(pfx, d5, rep), 1)
96
97 // ---- D6: a document with NO citations -> 0 struck (vacuously clean, honestly) ----
98 rl_ck(cnt, "D6 no-citation prose -> 0 struck" as *u8,
99 cite_scan_doc(pfx, "Plain prose with nothing to verify at all." as *u8, rep), 0)
100
101 // ---- D7: report content is populated (the human sees WHY, not just a count) ----
102 cite_scan_doc(pfx, d4, rep)
103 var rlen: i64 = 0
104 while rep[rlen] != (0 as u8) { rlen = rlen + 1 }
105 var has_report: i64 = 0
106 if rlen > 0 { has_report = 1 }
107 rl_ck(cnt, "D7 redline report is populated for the drafter" as *u8, has_report, 1)
108
109 gv_puts("---- sample redline (D4) ----\n" as *u8)
110 gv_puts(rep)
111
112 // ★A GATE WHOSE EXIT CODE DOES NOT CARRY ITS VERDICT SILENTLY BLESSES EVERY FAILURE IT FINDS.
113 let rc: i64 = gv_verdict("cite_redline_gate" as *u8, cnt, "F993 document-level citation redline over nx_cite_lib" as *u8)
114 sys_exit(rc)
115 return rc
116}