code wiki / _hdl_build / nx_sitegen_gate.nx

nx_sitegen_gate.nx source

↩ module page · 232 lines · 13219 B

1// nx_sitegen_gate.nx -- gate for the AUTO-BUILDER ENGINE (nx_sitegen). Proves a whole site page builds from a 2// DECLARATIVE BLUEPRINT (data) via the sovereign emitters, deterministically, with refuse-by-construction and 3// graceful-unknown-block. Positive AND negative controls. It builds the andelinwest legal site FROM A DATA 4// BLUEPRINT (the same content the hand-written nx_web_builder_test emitted by procedural calls -- now driven 5// by data), reads the output back over a real fd, and asserts: the UX elements are present; non-compliant 6// blueprints are REFUSED with ZERO bytes emitted; an unknown block kind is skipped without corrupting the 7// page; and the same blueprint builds BYTE-IDENTICAL twice (reproducible = the anti-vendor-lock property). 8// Appends "CMSGATE row=nx_sitegen site-builder ... verdict=PASS" to knowledge/status/cms_gate.log ONLY on 9// all-pass. Exit 0 iff all pass. license_tier: ORIGINAL 10import "nx_sitegen.nx" 11import "nx_syscalls.nx" 12 13func sg_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 14func sg_num(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 } 15func sg_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var k: i64=0; while s[k]!=(0 as u8){dst[o]=s[k];o=o+1;k=k+1} return o } 16func sg_catnum(dst: *u8, off: i64, v: i64) -> i64 { var o: i64=off; let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; 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{dst[o]=t[k-1-i];o=o+1;i=i+1} return o } 17 18func sg_row(id: i64, ok: i64, what: *u8) -> i64 { 19 sg_w("SGROW " as *u8); sg_num(id); sg_w(" " as *u8) 20 if ok==1 { sg_w("PASS " as *u8) } else { sg_w("FAIL " as *u8) } 21 sg_w(what); sg_w("\n" as *u8) 22 return ok 23} 24 25// read a whole (small) file into buf; returns byte count (>=0) or -1. uses openat_rd + read (no 4GB reserve). 26func sg_slurp(path: *u8, buf: *u8, cap: i64) -> i64 { 27 let fd: i64 = sys_openat_rd(path) 28 if fd < 0 { return 0 - 1 } 29 var total: i64 = 0 30 var go: i64 = 1 31 while go == 1 { 32 let r: i64 = sys_read(fd, buf + total, cap - total) 33 if r <= 0 { go = 0 } 34 if r > 0 { total = total + r } 35 if total >= cap { go = 0 } 36 } 37 sys_close(fd) 38 return total 39} 40 41// does hay[0..hn) contain the nul-terminated needle? 1/0. 42func sg_contains(hay: *u8, hn: i64, needle: *u8) -> i64 { 43 var nl: i64 = 0 44 while needle[nl] != (0 as u8) { nl = nl + 1 } 45 if nl == 0 { return 1 } 46 if nl > hn { return 0 } 47 let last: i64 = hn - nl 48 var i: i64 = 0 49 while i <= last { 50 var j: i64 = 0 51 var hit: i64 = 1 52 while j < nl { 53 if (hay[i+j] as i64) != (needle[j] as i64) { hit = 0; j = nl } 54 if hit == 1 { j = j + 1 } 55 } 56 if hit == 1 { return 1 } 57 i = i + 1 58 } 59 return 0 60} 61 62func sg_bytes_eq(a: *u8, an: i64, b: *u8, bn: i64) -> i64 { 63 if an != bn { return 0 } 64 var i: i64 = 0 65 while i < an { if (a[i] as i64) != (b[i] as i64) { return 0 } i = i + 1 } 66 return 1 67} 68 69func main() -> i64 { 70 let kind: *i64 = sys_mmap(8*16) as *i64 71 let a: *i64 = sys_mmap(8*16) as *i64 72 let b: *i64 = sys_mmap(8*16) as *i64 73 let c: *i64 = sys_mmap(8*16) as *i64 74 let d: *i64 = sys_mmap(8*16) as *i64 75 let list: *i64 = sys_mmap(8*16) as *i64 76 let lcount: *i64 = sys_mmap(8*16) as *i64 77 // (anon mmap is zero-filled, so unset fields default to 0) 78 79 // ===== the andelinwest legal site, expressed AS A BLUEPRINT (pure data) ===== 80 kind[0]=SG_HEADER; a[0]="Andelin West" as *u8 as i64; b[0]="Free consultation" as *u8 as i64; c[0]="#consult" as *u8 as i64 81 kind[1]=SG_HERO 82 a[1]="Straightforward legal help for Utah families and businesses." as *u8 as i64 83 b[1]="Talk to a licensed Utah attorney. Most matters start with one short call." as *u8 as i64 84 c[1]="Start your free consultation" as *u8 as i64 85 d[1]="#consult" as *u8 as i64 86 kind[2]=SG_SEARCH; a[2]="/search" as *u8 as i64; b[2]="Search: divorce, will, injury, contract..." as *u8 as i64 87 kind[3]=SG_CARDS; a[3]="How we help" as *u8 as i64; lcount[3]=4 88 let cards: *i64 = sys_mmap(8*8) as *i64 89 cards[0]="Family Law" as *u8 as i64; cards[1]="Divorce, custody, and support, handled with care." as *u8 as i64 90 cards[2]="Estate Planning" as *u8 as i64; cards[3]="Wills, trusts, and probate done right the first time." as *u8 as i64 91 cards[4]="Business Law" as *u8 as i64; cards[5]="Formation, contracts, and disputes for Utah businesses." as *u8 as i64 92 cards[6]="Personal Injury" as *u8 as i64; cards[7]="Injured? We deal with the insurers so you can heal." as *u8 as i64 93 list[3]=cards as i64 94 kind[4]=SG_STEPS; a[4]="Resolve it in 3 steps" as *u8 as i64; lcount[4]=3 95 let steps: *i64 = sys_mmap(8*8) as *i64 96 steps[0]="Tell us what happened -- 2 minutes, no jargon." as *u8 as i64 97 steps[1]="We review and call you back, usually the same day." as *u8 as i64 98 steps[2]="We handle it -- clear updates at every stage." as *u8 as i64 99 list[4]=steps as i64 100 kind[5]=SG_TRUST; lcount[5]=3 101 let trust: *i64 = sys_mmap(8*8) as *i64 102 trust[0]="Licensed by the Utah State Bar" as *u8 as i64 103 trust[1]="Free initial consultation" as *u8 as i64 104 trust[2]="Serving Utah families since 2008" as *u8 as i64 105 list[5]=trust as i64 106 kind[6]=SG_FOOTER; a[6]="Andelin West, PLLC -- Utah -- (801) 555-0100" as *u8 as i64 107 let nblk: i64 = 7 108 109 // ---- BUILD the legal site from the blueprint ---- 110 let p1: *u8 = "/tmp/nx_sitegen_aw.html" as *u8 111 let fd1: i64 = sys_openat_wr(p1, 0x1a4) 112 var grade1: i64 = 0 - 1 113 if fd1 >= 0 { grade1 = sg_build_page(fd1, "Andelin West -- Utah Attorneys" as *u8, kind, a, b, c, d, list, lcount, nblk); sys_close(fd1) } 114 let buf1: *u8 = sys_mmap(262144) 115 let len1: i64 = sg_slurp(p1, buf1, 262143) 116 117 var pass: i64 = 0 118 var rows: i64 = 0 119 var ok: i64 = 0 120 121 // R0: builds, full UX grade, non-empty 122 ok = 0; if grade1 == 100 { if len1 > 0 { ok = 1 } } 123 rows=rows+1; pass=pass+sg_row(0, ok, "legal site builds from data blueprint: grade=100, output non-empty" as *u8) 124 125 // R1: hero headline emitted from data 126 ok = sg_contains(buf1, len1, "Straightforward legal help for Utah families" as *u8) 127 rows=rows+1; pass=pass+sg_row(1, ok, "hero headline present (HERO block walked from data)" as *u8) 128 129 // R2: primary CTA label + href emitted from data 130 ok = 0; if sg_contains(buf1, len1, "Start your free consultation" as *u8)==1 { if sg_contains(buf1, len1, "#consult" as *u8)==1 { ok=1 } } 131 rows=rows+1; pass=pass+sg_row(2, ok, "primary CTA label + href present (the conversion path)" as *u8) 132 133 // R3: onsite search form 134 ok = sg_contains(buf1, len1, "role=\"search\"" as *u8) 135 rows=rows+1; pass=pass+sg_row(3, ok, "onsite search form present (SEARCH block)" as *u8) 136 137 // R4: all four card titles (the CARDS list was fully walked) 138 ok = 0 139 if sg_contains(buf1, len1, "Family Law" as *u8)==1 { if sg_contains(buf1, len1, "Estate Planning" as *u8)==1 { if sg_contains(buf1, len1, "Business Law" as *u8)==1 { if sg_contains(buf1, len1, "Personal Injury" as *u8)==1 { ok=1 } } } } 140 rows=rows+1; pass=pass+sg_row(4, ok, "all 4 practice-area cards present (CARDS list walked from data)" as *u8) 141 142 // R5: responsive by construction (viewport + media query baked in by the emitter) 143 ok = 0; if sg_contains(buf1, len1, "width=device-width" as *u8)==1 { if sg_contains(buf1, len1, "@media(max-width:600px)" as *u8)==1 { ok=1 } } 144 rows=rows+1; pass=pass+sg_row(5, ok, "responsive by construction: viewport + media query present" as *u8) 145 146 // R6: trust signals + footer (ordered walk reached the end) 147 ok = 0; if sg_contains(buf1, len1, "Utah State Bar" as *u8)==1 { if sg_contains(buf1, len1, "Andelin West, PLLC" as *u8)==1 { ok=1 } } 148 rows=rows+1; pass=pass+sg_row(6, ok, "trust signals + footer present (ordered walk completed)" as *u8) 149 150 // R7 (NEG): a blueprint with 4 resolution steps is REFUSED by construction (decision-fatigue rule), 0 bytes 151 let steps4: *i64 = sys_mmap(8*8) as *i64 152 steps4[0]=steps[0]; steps4[1]=steps[1]; steps4[2]=steps[2]; steps4[3]="One step too many -- must be refused." as *u8 as i64 153 lcount[4]=4; list[4]=steps4 as i64 154 let p7: *u8 = "/tmp/nx_sitegen_bad4.html" as *u8 155 let fd7: i64 = sys_openat_wr(p7, 0x1a4) 156 var ret7: i64 = 0 157 if fd7 >= 0 { ret7 = sg_build_page(fd7, "bad" as *u8, kind, a, b, c, d, list, lcount, nblk); sys_close(fd7) } 158 let buf7: *u8 = sys_mmap(4096) 159 let len7: i64 = sg_slurp(p7, buf7, 4095) 160 ok = 0; if ret7 < 0 { if len7 == 0 { ok = 1 } } 161 rows=rows+1; pass=pass+sg_row(7, ok, ">3-steps blueprint REFUSED, zero bytes emitted (neg control)" as *u8) 162 lcount[4]=3; list[4]=steps as i64 // restore the legal blueprint for the determinism check 163 164 // R8 (NEG): a blueprint with NO CTA and NO search is REFUSED (not UX-compliant) 165 let k8: *i64 = sys_mmap(8*8) as *i64 166 let a8: *i64 = sys_mmap(8*8) as *i64 167 let b8: *i64 = sys_mmap(8*8) as *i64 168 let c8: *i64 = sys_mmap(8*8) as *i64 169 let d8: *i64 = sys_mmap(8*8) as *i64 170 let l8: *i64 = sys_mmap(8*8) as *i64 171 let lc8: *i64 = sys_mmap(8*8) as *i64 172 k8[0]=SG_HERO; a8[0]="Headline only" as *u8 as i64; b8[0]="No call to action, no search." as *u8 as i64 173 k8[1]=SG_STEPS; a8[1]="Steps" as *u8 as i64; lc8[1]=3; l8[1]=steps as i64 174 k8[2]=SG_TRUST; lc8[2]=3; l8[2]=trust as i64 175 k8[3]=SG_FOOTER; a8[3]="Foot" as *u8 as i64 176 let p8: *u8 = "/tmp/nx_sitegen_nocta.html" as *u8 177 let fd8: i64 = sys_openat_wr(p8, 0x1a4) 178 var ret8: i64 = 0 179 if fd8 >= 0 { ret8 = sg_build_page(fd8, "nocta" as *u8, k8, a8, b8, c8, d8, l8, lc8, 4); sys_close(fd8) } 180 let buf8: *u8 = sys_mmap(4096) 181 let len8: i64 = sg_slurp(p8, buf8, 4095) 182 ok = 0; if ret8 < 0 { if len8 == 0 { ok = 1 } } 183 rows=rows+1; pass=pass+sg_row(8, ok, "no-CTA + no-search blueprint REFUSED, zero bytes (neg control)" as *u8) 184 185 // R9: an UNKNOWN block kind is skipped gracefully -- the page still completes (forward-compatible) 186 let k9: *i64 = sys_mmap(8*8) as *i64 187 let a9: *i64 = sys_mmap(8*8) as *i64 188 let b9: *i64 = sys_mmap(8*8) as *i64 189 let c9: *i64 = sys_mmap(8*8) as *i64 190 let d9: *i64 = sys_mmap(8*8) as *i64 191 let l9: *i64 = sys_mmap(8*8) as *i64 192 let lc9: *i64 = sys_mmap(8*8) as *i64 193 k9[0]=SG_HEADER; a9[0]="Brand9" as *u8 as i64; b9[0]="Go" as *u8 as i64; c9[0]="#go" as *u8 as i64 194 k9[1]=SG_HERO; a9[1]="H9" as *u8 as i64; b9[1]="sub9" as *u8 as i64; c9[1]="Go" as *u8 as i64; d9[1]="#go" as *u8 as i64 195 k9[2]=SG_SEARCH; a9[2]="/s" as *u8 as i64; b9[2]="find" as *u8 as i64 196 k9[3]=SG_STEPS; a9[3]="3 steps" as *u8 as i64; lc9[3]=3; l9[3]=steps as i64 197 k9[4]=SG_TRUST; lc9[4]=3; l9[4]=trust as i64 198 k9[5]=99 // UNKNOWN -- a block kind this engine version does not implement 199 k9[6]=SG_FOOTER; a9[6]="FOOTER-MARKER-9" as *u8 as i64 200 let p9: *u8 = "/tmp/nx_sitegen_unk.html" as *u8 201 let fd9: i64 = sys_openat_wr(p9, 0x1a4) 202 var ret9: i64 = 0 - 1 203 if fd9 >= 0 { ret9 = sg_build_page(fd9, "unk" as *u8, k9, a9, b9, c9, d9, l9, lc9, 7); sys_close(fd9) } 204 let buf9: *u8 = sys_mmap(65536) 205 let len9: i64 = sg_slurp(p9, buf9, 65535) 206 ok = 0; if ret9 >= 0 { if sg_contains(buf9, len9, "FOOTER-MARKER-9" as *u8)==1 { if len9 > 0 { ok=1 } } } 207 rows=rows+1; pass=pass+sg_row(9, ok, "unknown block kind skipped; page completes to footer (graceful/extensible)" as *u8) 208 209 // R10: the SAME blueprint builds BYTE-IDENTICAL twice (reproducible -- not trapped in a proprietary editor) 210 let p10: *u8 = "/tmp/nx_sitegen_aw2.html" as *u8 211 let fd10: i64 = sys_openat_wr(p10, 0x1a4) 212 if fd10 >= 0 { sg_build_page(fd10, "Andelin West -- Utah Attorneys" as *u8, kind, a, b, c, d, list, lcount, nblk); sys_close(fd10) } 213 let buf10: *u8 = sys_mmap(262144) 214 let len10: i64 = sg_slurp(p10, buf10, 262143) 215 ok = sg_bytes_eq(buf1, len1, buf10, len10) 216 rows=rows+1; pass=pass+sg_row(10, ok, "deterministic: same blueprint -> byte-identical build (reproducible)" as *u8) 217 218 sg_w("NX-SITEGEN-GATE rows=" as *u8); sg_num(rows); sg_w(" pass=" as *u8); sg_num(pass); sg_w("\n" as *u8) 219 if pass == rows { 220 let line: *u8 = sys_mmap(256) 221 var off: i64 = sg_cat(line, 0, "CMSGATE row=nx_sitegen site-builder rows=" as *u8) 222 off = sg_catnum(line, off, rows) 223 off = sg_cat(line, off, " pass=" as *u8); off = sg_catnum(line, off, pass) 224 off = sg_cat(line, off, " verdict=PASS\n" as *u8) 225 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4) 226 if gf >= 0 { sys_write(gf, line, off); sys_close(gf) } 227 sg_w("NX-SITEGEN-GATE verdict=PASS -- declarative auto-builder engine recorded in cms_gate.log\n" as *u8) 228 sys_exit(0); return 0 229 } 230 sg_w("NX-SITEGEN-GATE verdict=FAIL -- NOT recorded (no fake-green)\n" as *u8) 231 sys_exit(1); return 1 232}