nx_grounding_test.nx source
↩ module page · 156 lines · 8656 B
1// nx_grounding_test.nx -- gate for the anti-over-optimism rung. The tests that
2// matter are T3 (a composite is as weak as its weakest input) and T5 (the
3// business layer is honestly reported as NOT verified). If those pass, the
4// system can no longer launder an asserted constant into a confident claim.
5// expect_exit: 0 license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_grounding.nx"
8
9func t_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
10func t_putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } let t: *u8 = sys_mmap(28); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 }
11
12func main() -> i64 {
13 var pass: i64 = 0
14 var total: i64 = 0
15
16 // --- T1 the tier ladder is ordered strongest-last ---
17 total = total + 1
18 var ok1: i64 = 1
19 if GND_ATTESTED >= GND_ASSERTED { ok1 = 0 }
20 if GND_ASSERTED >= GND_DERIVED { ok1 = 0 }
21 if GND_DERIVED >= GND_VALIDATED { ok1 = 0 }
22 if GND_VALIDATED >= GND_ANCHORED { ok1 = 0 }
23 t_puts("T1 tiers ordered ATTESTED<ASSERTED<DERIVED<VALIDATED<ANCHORED: " as *u8)
24 if ok1 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
25
26 // --- T2 the chemistry is ANCHORED; the business layer is ASSERTED;
27 // the cGMP flags are ATTESTED -- HONESTLY ---
28 total = total + 1
29 let mass: i64 = gnd_class_tier(GC_PEPTIDE_MASS)
30 let cpi: i64 = gnd_class_tier(GC_CPI_SCORE)
31 let cost: i64 = gnd_class_tier(GC_INGREDIENT_COST)
32 let cgmp: i64 = gnd_class_tier(GC_CGMP_FLAG)
33 let fp: i64 = gnd_class_tier(GC_FREEZING_CURVE)
34 t_puts("T2 peptide-mass=" as *u8); t_puts(gnd_name(mass)); t_puts(" CPI=" as *u8); t_puts(gnd_name(cpi)); t_puts(" cost=" as *u8); t_puts(gnd_name(cost)); t_puts(" cGMP=" as *u8); t_puts(gnd_name(cgmp)); t_puts(" freezing=" as *u8); t_puts(gnd_name(fp)); t_puts(": " as *u8)
35 var ok2: i64 = 1
36 if mass != GND_ANCHORED { ok2 = 0 }
37 if cpi != GND_ASSERTED { ok2 = 0 }
38 if cost != GND_ASSERTED { ok2 = 0 }
39 if cgmp != GND_ATTESTED { ok2 = 0 }
40 if fp != GND_VALIDATED { ok2 = 0 }
41 if ok2 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
42
43 // --- T3 THE COMPOSITION LAW: weakest link. An "effective cost" built
44 // from an ASSERTED price and a DERIVED formula is ASSERTED, not
45 // DERIVED. A pile of asserted constants cannot launder itself. ---
46 total = total + 1
47 let eff: i64 = gnd_compose(GND_ASSERTED, GND_DERIVED)
48 let three: i64 = gnd_compose3(GND_ANCHORED, GND_VALIDATED, GND_ASSERTED)
49 t_puts("T3 compose(ASSERTED,DERIVED)=" as *u8); t_puts(gnd_name(eff)); t_puts(" compose3(ANCHORED,VALIDATED,ASSERTED)=" as *u8); t_puts(gnd_name(three)); t_puts(" (both ASSERTED = weakest): " as *u8)
50 var ok3: i64 = 1
51 if eff != GND_ASSERTED { ok3 = 0 }
52 if three != GND_ASSERTED { ok3 = 0 }
53 if ok3 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
54
55 // --- T4 gnd_min over a claim's whole input set ---
56 total = total + 1
57 let tiers: *i64 = sys_mmap(64)
58 tiers[0] = GND_ANCHORED
59 tiers[1] = GND_ANCHORED
60 tiers[2] = GND_ATTESTED // one operator attestation drags the whole claim down
61 tiers[3] = GND_VALIDATED
62 let m4: i64 = gnd_min(tiers, 4)
63 let empty: i64 = gnd_min(tiers, 0)
64 t_puts("T4 min over [ANCHORED,ANCHORED,ATTESTED,VALIDATED]=" as *u8); t_puts(gnd_name(m4)); t_puts(" empty-set=" as *u8); t_puts(gnd_name(empty)); t_puts(" want ATTESTED/UNKNOWN: " as *u8)
65 var ok4: i64 = 1
66 if m4 != GND_ATTESTED { ok4 = 0 }
67 if empty != GND_UNKNOWN { ok4 = 0 }
68 if ok4 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
69
70 // --- T5 THE HONEST LINE: only VALIDATED/ANCHORED are "verified", so the
71 // entire go-to-market layer reports NOT verified ---
72 total = total + 1
73 let v_mass: i64 = gnd_is_verified(gnd_class_tier(GC_PEPTIDE_MASS))
74 let v_fp: i64 = gnd_is_verified(gnd_class_tier(GC_FREEZING_CURVE))
75 let v_pi: i64 = gnd_is_verified(gnd_class_tier(GC_ISOELECTRIC_POINT))
76 let v_cpi: i64 = gnd_is_verified(gnd_class_tier(GC_CPI_SCORE))
77 let v_cost: i64 = gnd_is_verified(gnd_class_tier(GC_INGREDIENT_COST))
78 let v_reg: i64 = gnd_is_verified(gnd_class_tier(GC_REGULATORY_CLASS))
79 let v_cgmp: i64 = gnd_is_verified(gnd_class_tier(GC_CGMP_FLAG))
80 t_puts("T5 verified? mass=" as *u8); t_putn(v_mass); t_puts(" freezing=" as *u8); t_putn(v_fp); t_puts(" pI=" as *u8); t_putn(v_pi); t_puts(" | CPI=" as *u8); t_putn(v_cpi); t_puts(" cost=" as *u8); t_putn(v_cost); t_puts(" regclass=" as *u8); t_putn(v_reg); t_puts(" cGMP=" as *u8); t_putn(v_cgmp); t_puts(": " as *u8)
81 var ok5: i64 = 1
82 if v_mass != 1 { ok5 = 0 }
83 if v_fp != 1 { ok5 = 0 }
84 if v_pi != 0 { ok5 = 0 } // DERIVED is NOT "verified"
85 if v_cpi != 0 { ok5 = 0 }
86 if v_cost != 0 { ok5 = 0 }
87 if v_reg != 0 { ok5 = 0 }
88 if v_cgmp != 0 { ok5 = 0 }
89 if ok5 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
90
91 // --- T6 everything below VALIDATED needs a caveat when presented ---
92 total = total + 1
93 let c_anchor: i64 = gnd_needs_caveat(GND_ANCHORED)
94 let c_valid: i64 = gnd_needs_caveat(GND_VALIDATED)
95 let c_derived: i64 = gnd_needs_caveat(GND_DERIVED)
96 let c_assert: i64 = gnd_needs_caveat(GND_ASSERTED)
97 t_puts("T6 needs-caveat ANCHORED=" as *u8); t_putn(c_anchor); t_puts(" VALIDATED=" as *u8); t_putn(c_valid); t_puts(" DERIVED=" as *u8); t_putn(c_derived); t_puts(" ASSERTED=" as *u8); t_putn(c_assert); t_puts(" want 0/0/1/1: " as *u8)
98 var ok6: i64 = 1
99 if c_anchor != 0 { ok6 = 0 }
100 if c_valid != 0 { ok6 = 0 }
101 if c_derived != 1 { ok6 = 0 }
102 if c_assert != 1 { ok6 = 0 }
103 if ok6 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
104
105 // --- T7 decision-usable line: DERIVED and up inform a decision;
106 // ATTESTED/ASSERTED are placeholders that need the real thing ---
107 total = total + 1
108 let u_derived: i64 = gnd_decision_usable(GND_DERIVED)
109 let u_assert: i64 = gnd_decision_usable(GND_ASSERTED)
110 let u_attest: i64 = gnd_decision_usable(GND_ATTESTED)
111 t_puts("T7 decision-usable DERIVED=" as *u8); t_putn(u_derived); t_puts(" ASSERTED=" as *u8); t_putn(u_assert); t_puts(" ATTESTED=" as *u8); t_putn(u_attest); t_puts(" want 1/0/0: " as *u8)
112 var ok7: i64 = 1
113 if u_derived != 1 { ok7 = 0 }
114 if u_assert != 0 { ok7 = 0 }
115 if u_attest != 0 { ok7 = 0 }
116 if ok7 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
117
118 // --- T8 every claim class has a valid tier + a name + a meaning ---
119 total = total + 1
120 var i8: i64 = 0
121 var ok8: i64 = 1
122 while i8 < GC_N {
123 let tr: i64 = gnd_class_tier(i8)
124 if gnd_valid(tr) != 1 { ok8 = 0 }
125 if tr == GND_UNKNOWN { ok8 = 0 }
126 let nm: *u8 = gnd_name(tr)
127 let mn: *u8 = gnd_meaning(tr)
128 if nm[0] == (0 as u8) { ok8 = 0 }
129 if mn[0] == (0 as u8) { ok8 = 0 }
130 i8 = i8 + 1
131 }
132 t_puts("T8 all " as *u8); t_putn(GC_N); t_puts(" claim classes carry a valid tier + name + meaning: " as *u8)
133 if ok8 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
134
135 // --- T9 count how many claim classes are actually verified vs asserted:
136 // the honest ledger of this whole body of work ---
137 total = total + 1
138 var i9: i64 = 0
139 var nverified: i64 = 0
140 var nasserted: i64 = 0
141 while i9 < GC_N {
142 let tr: i64 = gnd_class_tier(i9)
143 if gnd_is_verified(tr) == 1 { nverified = nverified + 1 }
144 if tr <= GND_ASSERTED { nasserted = nasserted + 1 }
145 i9 = i9 + 1
146 }
147 t_puts("T9 claim ledger: verified=" as *u8); t_putn(nverified); t_puts(" asserted-or-below=" as *u8); t_putn(nasserted); t_puts(" of " as *u8); t_putn(GC_N); t_puts(" (4 verified: 2 anchored + 2 validated): " as *u8)
148 var ok9: i64 = 1
149 if nverified != 4 { ok9 = 0 }
150 if nasserted != 5 { ok9 = 0 }
151 if ok9 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) }
152
153 t_puts("GROUNDING-GATE passed " as *u8); t_putn(pass); t_puts("/" as *u8); t_putn(total)
154 if pass == total { t_puts(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
155 t_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1
156}