code wiki / _hdl_build / nx_site_provision_gate.nx
nx_site_provision_gate.nx source
↩ module page · 40 lines · 3465 B
1// nx_site_provision_gate.nx -- proves provisioning is correct AND s-class-by-construction.
2// T1 (compliant config): a valid .site -> provisioned (r=0), HTML actually rendered (hero CTA present),
3// sites.conf line written, manifest written. T2 NEG-CONTROL (non-compliant config: no CTA/search/trust):
4// MUST be REFUSED (r<0) with NOTHING in sites.conf -- s-class enforced, no silent half-built site.
5// license_tier: ORIGINAL
6import "nx_site_provision_lib.nx"
7
8func main() -> i64 {
9 var fails: i64 = 0
10 let gametpl: *u8 = "/tmp/sp_none_tpl" as *u8
11 // a COMPLIANT .site (mirrors the live, WCAG-1000 andelinwest format: header CTA + hero CTA + search + 3 steps + trust)
12 sp_writefile("/tmp/sp_valid.site" as *u8, "title|TestCo\nheader|TestCo|Free consultation|#consult\nhero|Straightforward help for Utah families.|Talk to a licensed pro. One short call.|Start your free consultation|#consult\nsearch|/search|Search...\ncards|How we help\ncard|Family Law|Handled with care.\ncard|Estate Planning|Done right.\nsteps|Resolve it in 3 steps\nstep|Tell us what happened.\nstep|We review and call back.\nstep|We handle it.\ntrust|\nsig|Licensed by the Utah State Bar\nsig|Free initial consultation\nfooter|TestCo -- Utah\n" as *u8)
13 // a NON-COMPLIANT .site: no header/hero CTA, no search, no trust -> sg_compliant must reject
14 sp_writefile("/tmp/sp_invalid.site" as *u8, "title|BadCo\ncards|Stuff\ncard|A|just a card, no CTA/search/trust.\nfooter|BadCo\n" as *u8)
15 sp_writefile("/tmp/sp_conf" as *u8, "" as *u8)
16 sp_writefile("/tmp/sp_conf2" as *u8, "" as *u8)
17
18 // T1: compliant -> provisioned
19 let r1: i64 = sp_provision("testco" as *u8, "/tmp/sp_valid.site" as *u8, "/tmp/sp_valid.html" as *u8, "/tmp/sp_conf" as *u8, "/tmp/sp_manifest" as *u8, gametpl)
20 sp_w(1, "T1 compliant : rc=" as *u8); sp_wn(1, r1); sp_w(1, "\n" as *u8)
21 if r1 != 0 { fails = fails + 1 }
22 let hb: *u8 = sys_mmap(262144); let hn: i64 = sp_read("/tmp/sp_valid.html" as *u8, hb, 262140)
23 if sp_contains(hb, hn, "Start your free consultation" as *u8) == 0 { fails = fails + 1 } // hero CTA rendered
24 let cb: *u8 = sys_mmap(8192); let cn: i64 = sp_read("/tmp/sp_conf" as *u8, cb, 8190)
25 if sp_contains(cb, cn, "testco" as *u8) == 0 { fails = fails + 1 } // sites.conf line written
26 let mb: *u8 = sys_mmap(8192); let mn: i64 = sp_read("/tmp/sp_manifest" as *u8, mb, 8190)
27 if sp_contains(mb, mn, "compliant=1" as *u8) == 0 { fails = fails + 1 } // manifest written
28
29 // T2 NEG-CONTROL: non-compliant -> REFUSED, sites.conf untouched
30 let r2: i64 = sp_provision("badco" as *u8, "/tmp/sp_invalid.site" as *u8, "/tmp/sp_invalid.html" as *u8, "/tmp/sp_conf2" as *u8, "/tmp/sp_manifest2" as *u8, gametpl)
31 sp_w(1, "T2 neg-ctrl : rc=" as *u8); sp_wn(1, r2); sp_w(1, " (non-compliant config MUST be refused)\n" as *u8)
32 if r2 >= 0 { fails = fails + 1 }
33 let cb2: *u8 = sys_mmap(8192); let cn2: i64 = sp_read("/tmp/sp_conf2" as *u8, cb2, 8190)
34 if sp_contains(cb2, cn2, "badco" as *u8) == 1 { fails = fails + 1 } // must NOT have provisioned
35
36 if fails == 0 { sp_w(1, "GATE nx_site_provision verdict=GREEN pass=6/6 (config->s-class site; non-compliant REFUSED, sites.conf untouched)\n" as *u8); sys_exit(0); return 0 }
37 sp_w(1, "GATE nx_site_provision verdict=RED fails=" as *u8); sp_wn(1, fails); sp_w(1, "\n" as *u8)
38 sys_exit(1)
39 return 1
40}