nx_citator_gate.nx source
↩ module page · 131 lines · 6347 B
1// nx_citator_gate.nx -- F995 INDEPENDENT GATE: citation treatment signals + the composed safety check.
2// Proves worst-wins (one overruling kills reliance no matter how many followings), the good-law bright
3// line, and the killer composition: a REAL quote from an OVERRULED case is UNSAFE to cite.
4// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
5
6import "nx_citator_lib.nx"
7
8func tg_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
9func tg_putn(v: i64) -> i64 {
10 let t: *u8 = sys_mmap(32)
11 var o: i64 = 0
12 var m: i64 = v
13 if m < 0 { t[o] = 45 as u8; o = o + 1; m = 0 - m }
14 let d: *u8 = sys_mmap(32)
15 var k: i64 = 0
16 if m == 0 { d[0] = 48 as u8; k = 1 }
17 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
18 var i: i64 = 0
19 while i < k { t[o] = d[k - 1 - i]; o = o + 1; i = i + 1 }
20 sys_write(1, t, o)
21 return 0
22}
23func tg_ck(cnt: *i64, name: *u8, got: i64, want: i64) -> i64 {
24 if got == want {
25 cnt[0] = cnt[0] + 1
26 tg_puts(" PASS " as *u8); tg_puts(name); tg_puts(" = " as *u8); tg_putn(got); tg_puts("\n" as *u8)
27 return 1
28 }
29 cnt[1] = cnt[1] + 1
30 tg_puts(" FAIL " as *u8); tg_puts(name); tg_puts(" got " as *u8); tg_putn(got)
31 tg_puts(" want " as *u8); tg_putn(want); tg_puts("\n" as *u8)
32 return 0
33}
34func tg_id(tag: *u8, nonce: i64, out: *u8) -> i64 {
35 var o: i64 = mt_catcopy(out, 0, tag)
36 o = mt_catn(out, o, nonce)
37 out[o] = 0 as u8
38 return o
39}
40
41func main(argc: i64, argv: *i64) -> i64 {
42 let pfx: *u8 = "knowledge/store/citatorgate-" as *u8
43 let nonce: i64 = sys_now_us()
44 let cnt: *i64 = sys_mmap(16) as *i64
45 cnt[0] = 0
46 cnt[1] = 0
47
48 tg_puts("NISHI-CITATOR-GATE (F995 treatment signals: is it still good law?)\n" as *u8)
49
50 // run-unique case ids
51 let good: *u8 = sys_mmap(64)
52 let dead: *u8 = sys_mmap(64)
53 let mixed: *u8 = sys_mmap(64)
54 let caution: *u8 = sys_mmap(64)
55 let unknown: *u8 = sys_mmap(64)
56 let c1: *u8 = sys_mmap(64)
57 let c2: *u8 = sys_mmap(64)
58 let c3: *u8 = sys_mmap(64)
59 tg_id("Good-v-State-" as *u8, nonce, good)
60 tg_id("Dead-v-State-" as *u8, nonce, dead)
61 tg_id("Mixed-v-State-" as *u8, nonce, mixed)
62 tg_id("Caution-v-State-" as *u8, nonce, caution)
63 tg_id("Unknown-v-State-" as *u8, nonce, unknown)
64 tg_id("Later-A-" as *u8, nonce, c1)
65 tg_id("Later-B-" as *u8, nonce, c2)
66 tg_id("Later-C-" as *u8, nonce, c3)
67
68 // build a treatment graph
69 cit_treat_put(pfx, good, c1, "followed" as *u8)
70 cit_treat_put(pfx, good, c2, "followed" as *u8)
71 cit_treat_put(pfx, dead, c1, "overruled" as *u8)
72 cit_treat_put(pfx, caution, c1, "questioned" as *u8)
73 cit_treat_put(pfx, caution, c2, "distinguished" as *u8)
74 // MIXED: followed twice AND overruled once -> worst-wins says OVERRULED
75 cit_treat_put(pfx, mixed, c1, "followed" as *u8)
76 cit_treat_put(pfx, mixed, c2, "followed" as *u8)
77 cit_treat_put(pfx, mixed, c3, "overruled" as *u8)
78
79 // ---- T1: a followed-only case is GOOD LAW ----
80 tg_ck(cnt, "T1 followed-only case status = 0 (good)" as *u8, cit_status(pfx, good), 0)
81 tg_ck(cnt, "T1a good case IS good law" as *u8, cit_is_good_law(pfx, good), 1)
82
83 // ---- T2: an overruled case is BAD LAW ----
84 tg_ck(cnt, "T2 overruled case status = 3 (bad)" as *u8, cit_status(pfx, dead), 3)
85 tg_ck(cnt, "T2a overruled case is NOT good law" as *u8, cit_is_good_law(pfx, dead), 0)
86
87 // ---- T3: WORST-WINS. followed x2 + overruled x1 -> OVERRULED dominates ----
88 tg_ck(cnt, "T3 mixed (2 followed, 1 overruled) status = 3" as *u8, cit_status(pfx, mixed), 3)
89 tg_ck(cnt, "T3a one overruling kills reliance despite the followings" as *u8, cit_is_good_law(pfx, mixed), 0)
90
91 // ---- T4: caution (questioned + distinguished, no overruling) -> worst=2, still good law but flagged ----
92 tg_ck(cnt, "T4 caution status = 2 (questioned dominates distinguished)" as *u8, cit_status(pfx, caution), 2)
93 tg_ck(cnt, "T4a caution is still good law (not overruled)" as *u8, cit_is_good_law(pfx, caution), 1)
94 tg_ck(cnt, "T4b but it carries a caution flag" as *u8, cit_is_caution(pfx, caution), 1)
95 tg_ck(cnt, "T4c good-law case carries NO caution flag" as *u8, cit_is_caution(pfx, good), 0)
96
97 // ---- T5: an unknown case (no treatment recorded) presumed good law, no caution ----
98 tg_ck(cnt, "T5 untreated case status = 0" as *u8, cit_status(pfx, unknown), 0)
99 tg_ck(cnt, "T5a untreated case is good law" as *u8, cit_is_good_law(pfx, unknown), 1)
100
101 // ---- T6: THE COMPOSITION. store a real quote for BOTH the good and the dead case ----
102 let realquote: *u8 = "the statute requires strict compliance" as *u8
103 cite_source_put(pfx, good, "We hold that the statute requires strict compliance in all cases." as *u8)
104 cite_source_put(pfx, dead, "We hold that the statute requires strict compliance in all cases." as *u8)
105
106 // the quote is REAL in both -- cite_ok passes for both
107 tg_ck(cnt, "T6 quote verifies against the good case" as *u8, cite_ok(pfx, good, realquote), 1)
108 tg_ck(cnt, "T6a SAME quote verifies against the dead case too" as *u8, cite_ok(pfx, dead, realquote), 1)
109
110 // ---- T7: THE KILLER. safe_to_cite passes for the good case, REFUSES the overruled one ----
111 // a real quote from dead law is UNSAFE -- the trap a citator exists to prevent.
112 tg_ck(cnt, "T7 safe-to-cite the GOOD case (real quote + good law)" as *u8,
113 cit_safe_to_cite(pfx, good, realquote), 1)
114 tg_ck(cnt, "T7a UNSAFE to cite the OVERRULED case despite the real quote" as *u8,
115 cit_safe_to_cite(pfx, dead, realquote), 0)
116
117 // ---- T8: safe_to_cite also refuses a FABRICATED quote even from a good-law case ----
118 tg_ck(cnt, "T8 fabricated quote from a good case is still UNSAFE" as *u8,
119 cit_safe_to_cite(pfx, good, "the statute is merely advisory" as *u8), 0)
120
121 tg_puts("nx_citator_gate: pass=" as *u8); tg_putn(cnt[0])
122 tg_puts(" fail=" as *u8); tg_putn(cnt[1]); tg_puts("\n" as *u8)
123 if cnt[1] == 0 {
124 tg_puts("F995 nx_citator: VERDICT=GREEN (worst-wins good-law signal; a real quote from overruled law is unsafe)\n" as *u8)
125 sys_exit(0)
126 return 0
127 }
128 tg_puts("F995 nx_citator: VERDICT=RED\n" as *u8)
129 sys_exit(1)
130 return 1
131}