code wiki / _hdl_build / nx_pattern_library_test.nx
nx_pattern_library_test.nx source
↩ module page · 74 lines · 4326 B
1// nx_pattern_library_test.nx -- ACCEPTANCE GATE for the Builder's pattern library + the autonomy it
2// unlocks. Measures coverage over the REAL module shapes built this session (the honest comprehensiveness).
3import "nx_pattern_library.nx"
4import "nx_syscalls.nx"
5
6func lt_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
7func lt_putn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m} 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 }
8
9func main() -> i64 {
10 var pass: i64 = 0
11 var total: i64 = 0
12
13 // T1: covered vs novel + match
14 total = total + 1
15 var t1: i64 = 1
16 if pl_covered(PL_VERDICT_GATE) != 1 { t1 = 0 }
17 if pl_covered(PL_PID_LOOP) != 1 { t1 = 0 }
18 if pl_covered(0) != 0 { t1 = 0 } // novel
19 if pl_covered(99) != 0 { t1 = 0 } // unknown shape
20 if pl_match(PL_GEOMETRY) != PL_GEOMETRY { t1 = 0 }
21 if pl_match(0) != 0 { t1 = 0 }
22 // census BOUNDARY law instead of a hardcoded count (the literal went
23 // stale on every growth: 15 broke at emit11, 16 broke at emit12 --
24 // emitter-vs-census currency is the SYNC GATE's job, not this KAT's):
25 // the census edge is covered, one past it is novel.
26 if pl_covered(pl_n_patterns()) != 1 { t1 = 0 }
27 if pl_covered(pl_n_patterns() + 1) != 0 { t1 = 0 }
28 if pl_covered(PL_WIRE_MARKER) != 1 { t1 = 0 }
29 if pl_covered(PL_PREDICTOR_CODER) != 1 { t1 = 0 }
30 if pl_covered(PL_TEMPLATE_TABLE) != 1 { t1 = 0 }
31 if t1 == 1 { pass = pass + 1 } else { lt_puts("T1 FAIL covered\n" as *u8) }
32
33 // T2: COVERAGE over this session's REAL module shapes -- map each module to its pattern:
34 // jam_check=VERDICT_GATE, claim_extract=PARSER_KAT, research_exceed=COMPARATOR,
35 // metrology=ACCUMULATOR, polite_crawl=GOVERNOR, build_pipeline=STATE_FLOW,
36 // mask_geom=GEOMETRY, heater_pid=PID_LOOP, scaffold=SCAFFOLD, litho_stepper=THRESHOLD_TABLE
37 // -> ALL 10 covered = 1000 permil (the pattern library spans the session's work)
38 total = total + 1
39 let shapes: *i64 = sys_mmap(128) as *i64
40 shapes[0]=PL_VERDICT_GATE; shapes[1]=PL_PARSER_KAT; shapes[2]=PL_COMPARATOR; shapes[3]=PL_ACCUMULATOR
41 shapes[4]=PL_GOVERNOR; shapes[5]=PL_STATE_FLOW; shapes[6]=PL_GEOMETRY; shapes[7]=PL_PID_LOOP
42 shapes[8]=PL_SCAFFOLD; shapes[9]=PL_THRESHOLD_TABLE
43 // + the post-census growth shapes (math/browser/race arcs)
44 shapes[10]=PL_MATH_KERNEL; shapes[11]=PL_WIRE_TLV; shapes[12]=PL_STRUCT_WALK; shapes[13]=PL_IO_CONTRACT
45 shapes[14]=PL_WIRE_MARKER; shapes[15]=PL_PREDICTOR_CODER; shapes[16]=PL_TEMPLATE_TABLE
46 if pl_coverage_permil(shapes, 17) == 1000 { pass = pass + 1 } else { lt_puts("T2 FAIL coverage=" as *u8); lt_putn(pl_coverage_permil(shapes, 17)); lt_puts("\n" as *u8) }
47
48 // T3: a backlog mixing covered + novel -> partial coverage (honest: novel shapes still need Claude)
49 total = total + 1
50 let mixed: *i64 = sys_mmap(64) as *i64
51 mixed[0]=PL_VERDICT_GATE; mixed[1]=PL_GEOMETRY; mixed[2]=0; mixed[3]=PL_COMPARATOR // one novel -> 3/4
52 if pl_coverage_permil(mixed, 4) == 750 { pass = pass + 1 } else { lt_puts("T3 FAIL mixed=" as *u8); lt_putn(pl_coverage_permil(mixed, 4)); lt_puts("\n" as *u8) }
53
54 // T4: S-class-exceed comprehensiveness gate -- the session's shapes clear an 800-permil floor
55 total = total + 1
56 var t4: i64 = 1
57 if pl_is_comprehensive(shapes, 17, 800) != 1 { t4 = 0 }
58 if pl_is_comprehensive(mixed, 4, 800) != 0 { t4 = 0 } // 750 < 800 -> not yet comprehensive (honest)
59 if t4 == 1 { pass = pass + 1 } else { lt_puts("T4 FAIL comprehensive\n" as *u8) }
60
61 // T5: names
62 total = total + 1
63 var t5: i64 = 1
64 let n1: *u8 = pl_name(PL_GOVERNOR)
65 if n1[0] != (71 as u8) { t5 = 0 } // 'G' of GOVERNOR
66 let n0: *u8 = pl_name(0)
67 if n0[0] != (78 as u8) { t5 = 0 } // 'N' of NOVEL
68 if t5 == 1 { pass = pass + 1 } else { lt_puts("T5 FAIL names\n" as *u8) }
69
70 lt_puts("PATTERN-LIBRARY " as *u8); lt_putn(pass); lt_puts("/" as *u8); lt_putn(total); lt_puts("\n" as *u8)
71 if pass == total { lt_puts("PATTERN-LIBRARY ALL-PASS\n" as *u8); sys_exit(0) }
72 sys_exit(1)
73 return 1
74}