code wiki / _hdl_build / nx_sitegen_blocks_gate.nx

nx_sitegen_blocks_gate.nx source

↩ module page · 83 lines · 6511 B

1// nx_sitegen_blocks_gate.nx -- gate for the ENRICHED BLOCK SURFACE (new block types: FAQ, GALLERY, CTA banner). 2// Drives the full parse+build path (se_build_site) on a .site that uses the new blocks alongside the compliant 3// base, proving: each new block renders from data (FAQ as accessible <details>, gallery as a responsive img grid, 4// a CTA banner), every field is injection-ESCAPED, the new blocks COEXIST with the base, they do NOT bypass the 5// publish-gate (a page of only new blocks is REFUSED), and the build is deterministic. Appends a CMSGATE row to 6// knowledge/status/cms_gate.log on all-pass. license_tier: ORIGINAL 7import "nx_sitegen_studio.nx" 8import "nx_syscalls.nx" 9 10func bgw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func bgn(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 } 12func bgcat(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 } 13func bgcatn(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 } 14func bgrow(id: i64, ok: i64, what: *u8) -> i64 { bgw("BLKROW " as *u8); bgn(id); bgw(" " as *u8); if ok==1 { bgw("PASS " as *u8) } else { bgw("FAIL " as *u8) } bgw(what); bgw("\n" as *u8); return ok } 15func bglen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 16func bghas(hay: *u8, hn: i64, needle: *u8) -> i64 { 17 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 18 if nl==0 { return 1 } if nl>hn { return 0 } 19 let last: i64=hn-nl; var i: i64=0 20 while i<=last { var j: i64=0; var hit: i64=1; while j<nl { if (hay[i+j] as i64)!=(needle[j] as i64){hit=0;j=nl} if hit==1{j=j+1} } if hit==1 { return 1 } i=i+1 } 21 return 0 22} 23func bgeq(a: *u8, an: i64, b: *u8, bn: i64) -> i64 { if an!=bn { return 0 } var i: i64=0; while i<an { if (a[i] as i64)!=(b[i] as i64){return 0} i=i+1 } return 1 } 24 25func main() -> i64 { 26 let site: *u8 = "title|Enriched Test\nheader|BrandCo|Get started|#go\nhero|Welcome|We help you|Get started|#go\nsearch|/search|Search...\nfaq|Frequently asked questions\nqa|What do you do?|We build sites.\nqa|<script>alert(1)</script>|Hostile question escaped.\ngallery|Our work\nimg|/img/a.jpg|Project A\nimg|/img/b.jpg|Project B\ncta|Ready to begin?|Join thousands of happy users|Sign up now|#signup\nsteps|How it works\nstep|Tell us\ntrust|\nsig|Trusted since 2008\nfooter|BrandCo\n" as *u8 27 let out: *u8 = sys_mmap(262144) 28 let out2: *u8 = sys_mmap(262144) 29 let ln: i64 = se_build_site(site, bglen(site), out, 262143) 30 31 var rows: i64 = 0 32 var pass: i64 = 0 33 var ok: i64 = 0 34 35 // R0: FAQ renders from data (heading + Q + A) 36 ok = 0; if ln>0 { if bghas(out,ln,"Frequently asked questions" as *u8)==1 { if bghas(out,ln,"What do you do?" as *u8)==1 { if bghas(out,ln,"We build sites." as *u8)==1 { ok=1 } } } } 37 rows=rows+1; pass=pass+bgrow(0, ok, "FAQ block renders from data (heading + question + answer)" as *u8) 38 39 // R1: FAQ is accessible native details/summary (no JS) 40 ok = 0; if bghas(out,ln,"<details><summary>" as *u8)==1 { ok=1 } 41 rows=rows+1; pass=pass+bgrow(1, ok, "FAQ uses accessible <details>/<summary> (no JS)" as *u8) 42 43 // R2: GALLERY renders a responsive image grid from data 44 ok = 0; if bghas(out,ln,"/img/a.jpg" as *u8)==1 { if bghas(out,ln,"Project A" as *u8)==1 { if bghas(out,ln,"/img/b.jpg" as *u8)==1 { if bghas(out,ln,"loading=\"lazy\"" as *u8)==1 { ok=1 } } } } 45 rows=rows+1; pass=pass+bgrow(2, ok, "GALLERY renders a responsive image grid from data (lazy-loaded)" as *u8) 46 47 // R3: CTA banner renders (heading + label + href + band class) 48 ok = 0; if bghas(out,ln,"Ready to begin?" as *u8)==1 { if bghas(out,ln,"Sign up now" as *u8)==1 { if bghas(out,ln,"href=\"#signup\"" as *u8)==1 { if bghas(out,ln,"ctaband" as *u8)==1 { ok=1 } } } } 49 rows=rows+1; pass=pass+bgrow(3, ok, "CTA banner renders from data (heading + button + href)" as *u8) 50 51 // R4 (NEG): a hostile FAQ question is escaped 52 ok = 0; if bghas(out,ln,"<script>alert(1)" as *u8)==0 { if bghas(out,ln,"&lt;script&gt;alert(1)" as *u8)==1 { ok=1 } } 53 rows=rows+1; pass=pass+bgrow(4, ok, "NEG: hostile field in a new block is escaped (no raw <script>)" as *u8) 54 55 // R5: the new blocks COEXIST with the compliant base (header + hero still present) 56 ok = 0; if bghas(out,ln,"BrandCo" as *u8)==1 { if bghas(out,ln,"Welcome" as *u8)==1 { ok=1 } } 57 rows=rows+1; pass=pass+bgrow(5, ok, "new blocks coexist with the base (header + hero intact)" as *u8) 58 59 // R6 (NEG): new blocks do NOT bypass the publish-gate -- a page of ONLY new blocks is REFUSED 60 let bad: *u8 = "title|X\nfaq|q\nqa|a|b\ngallery|g\nimg|/i.jpg|alt\ncta|h|s|l|#x\n" as *u8 61 let lb: i64 = se_build_site(bad, bglen(bad), out2, 262143) 62 ok = 0; if lb == 0 { ok=1 } 63 rows=rows+1; pass=pass+bgrow(6, ok, "NEG: only-new-blocks page REFUSED (publish-gate not bypassed)" as *u8) 64 65 // R7: deterministic -- same .site rebuilds byte-identical 66 let l2: i64 = se_build_site(site, bglen(site), out2, 262143) 67 ok = bgeq(out, ln, out2, l2) 68 rows=rows+1; pass=pass+bgrow(7, ok, "deterministic: same .site rebuilds byte-identical" as *u8) 69 70 bgw("NX-SITEGEN-BLOCKS-GATE rows=" as *u8); bgn(rows); bgw(" pass=" as *u8); bgn(pass); bgw("\n" as *u8) 71 if pass == rows { 72 let line: *u8 = sys_mmap(256) 73 var off: i64 = bgcat(line, 0, "CMSGATE row=nx_sitegen_blocks enriched-block-surface rows=" as *u8) 74 off = bgcatn(line, off, rows); off = bgcat(line, off, " pass=" as *u8); off = bgcatn(line, off, pass) 75 off = bgcat(line, off, " verdict=PASS (FAQ + gallery + CTA blocks; escaped; additive; gate not bypassed)\n" as *u8) 76 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4) 77 if gf >= 0 { sys_write(gf, line, off); sys_close(gf) } 78 bgw("NX-SITEGEN-BLOCKS-GATE verdict=PASS -- enriched block surface (FAQ/gallery/CTA) recorded\n" as *u8) 79 sys_exit(0); return 0 80 } 81 bgw("NX-SITEGEN-BLOCKS-GATE verdict=FAIL -- NOT recorded (no fake-green)\n" as *u8) 82 sys_exit(1); return 1 83}