code wiki / _hdl_build / nx_site_compose_gate.nx

nx_site_compose_gate.nx source

↩ module page · 105 lines · 7592 B

1// nx_site_compose_gate.nx -- gate for the UNIFIED file-driven multi-type builder (nx_site_compose). Proves ONE 2// engine builds all THREE page types from DATA FILES, selected by the `type|` line: a legal .site with no type 3// line -> legal page; type|game -> the game page (title + wasm wired); type|video -> the video gallery (the 4// title|thumb|url list walked). Dispatch is exclusive (each output lacks the other two types' fingerprints), the 5// three outputs are mutually distinct (one engine, type-selected -- not one hardcoded page), and the same .site 6// builds byte-identical. Positive AND negative (cross-type bleed) controls. Appends a CMSGATE row to 7// knowledge/status/cms_gate.log on all-pass. license_tier: ORIGINAL 8import "nx_site_compose.nx" 9import "nx_syscalls.nx" 10 11func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func cnum(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 } 13func ccat(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 } 14func ccatnum(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 } 15func crow(id: i64, ok: i64, what: *u8) -> i64 { cw("CMPROW " as *u8); cnum(id); cw(" " as *u8); if ok==1 { cw("PASS " as *u8) } else { cw("FAIL " as *u8) } cw(what); cw("\n" as *u8); return ok } 16func cslurp(path: *u8, buf: *u8, cap: i64) -> i64 { 17 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } 18 var total: i64 = 0; var go: i64 = 1 19 while go == 1 { let r: i64 = sys_read(fd, buf + total, cap - total); if r <= 0 { go = 0 } if r > 0 { total = total + r } if total >= cap { go = 0 } } 20 sys_close(fd); return total 21} 22func chas(hay: *u8, hn: i64, needle: *u8) -> i64 { 23 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 24 if nl==0 { return 1 } if nl>hn { return 0 } 25 let last: i64=hn-nl; var i: i64=0 26 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 } 27 return 0 28} 29func ceq(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 } 30 31// build a .site file (read from site_path) through compose_build to out_path; return out byte count (in obuf). 32func cbuild(site_path: *u8, out_path: *u8, sbuf: *u8, scap: i64, obuf: *u8, ocap: i64) -> i64 { 33 let sn: i64 = cslurp(site_path, sbuf, scap) 34 if sn <= 0 { return 0 - 1 } 35 let fd: i64 = sys_openat_wr(out_path, 0x1a4) 36 if fd >= 0 { compose_build(sbuf, sn, fd, "web_assets/_game_build/game_page.tpl.html" as *u8); sys_close(fd) } 37 return cslurp(out_path, obuf, ocap) 38} 39 40func main() -> i64 { 41 let sbuf: *u8 = sys_mmap(65536) 42 let lbuf: *u8 = sys_mmap(262144) 43 let gbuf: *u8 = sys_mmap(262144) 44 let vbuf: *u8 = sys_mmap(262144) 45 let v2buf: *u8 = sys_mmap(262144) 46 47 let ln: i64 = cbuild("web_assets/_sites/andelinwest.site" as *u8, "/tmp/nx_cmp_legal.html" as *u8, sbuf, 65535, lbuf, 262143) 48 let gn: i64 = cbuild("web_assets/_sites/petgame.site" as *u8, "/tmp/nx_cmp_game.html" as *u8, sbuf, 65535, gbuf, 262143) 49 let vn: i64 = cbuild("web_assets/_sites/petvids.site" as *u8, "/tmp/nx_cmp_video.html" as *u8, sbuf, 65535, vbuf, 262143) 50 let v2n: i64 = cbuild("web_assets/_sites/petvids.site" as *u8, "/tmp/nx_cmp_video2.html" as *u8, sbuf, 65535, v2buf, 262143) 51 52 var rows: i64 = 0 53 var pass: i64 = 0 54 var ok: i64 = 0 55 56 // R0: a .site with NO type line builds the LEGAL page (default) 57 ok = 0; if ln > 0 { if chas(lbuf, ln, "Andelin West" as *u8)==1 { if chas(lbuf, ln, "Family Law" as *u8)==1 { ok=1 } } } 58 rows=rows+1; pass=pass+crow(0, ok, "no type line -> LEGAL page builds (Andelin West, Family Law)" as *u8) 59 60 // R1 (neg/dispatch): legal output carries no video player and no game wasm 61 ok = 0; if chas(lbuf, ln, "<video controls" as *u8)==0 { if chas(lbuf, ln, "/pets3d.wasm" as *u8)==0 { ok=1 } } 62 rows=rows+1; pass=pass+crow(1, ok, "legal output has no video player + no game wasm (clean dispatch)" as *u8) 63 64 // R2: type|game builds the GAME page with title + wasm wired 65 ok = 0; if gn > 0 { if chas(gbuf, gn, "Nishi Pixelmon" as *u8)==1 { if chas(gbuf, gn, "/pets3d.wasm" as *u8)==1 { ok=1 } } } 66 rows=rows+1; pass=pass+crow(2, ok, "type|game -> GAME page (Nishi Pixelmon + /pets3d.wasm wired)" as *u8) 67 68 // R3 (neg/dispatch): game output carries no video player and no legal blocks 69 ok = 0; if chas(gbuf, gn, "<video controls" as *u8)==0 { if chas(gbuf, gn, "Family Law" as *u8)==0 { ok=1 } } 70 rows=rows+1; pass=pass+crow(3, ok, "game output has no video player + no legal blocks (clean dispatch)" as *u8) 71 72 // R4: type|video builds the VIDEO gallery (heading + inline players) 73 ok = 0; if vn > 0 { if chas(vbuf, vn, "Latest pet videos" as *u8)==1 { if chas(vbuf, vn, "<video controls" as *u8)==1 { ok=1 } } } 74 rows=rows+1; pass=pass+crow(4, ok, "type|video -> VIDEO gallery (Latest pet videos + inline players)" as *u8) 75 76 // R5: every video row walked from the .site list (title|thumb|url) 77 ok = 0; if chas(vbuf, vn, "Whiskers naps in the sun" as *u8)==1 { if chas(vbuf, vn, "Rex fetches the ball" as *u8)==1 { if chas(vbuf, vn, "/vids/goldie.mp4" as *u8)==1 { ok=1 } } } 78 rows=rows+1; pass=pass+crow(5, ok, "all 3 video rows parsed from the .site (title|thumb|url walked)" as *u8) 79 80 // R6 (neg/dispatch): video output carries no game wasm and no legal blocks 81 ok = 0; if chas(vbuf, vn, "/pets3d.wasm" as *u8)==0 { if chas(vbuf, vn, "Family Law" as *u8)==0 { ok=1 } } 82 rows=rows+1; pass=pass+crow(6, ok, "video output has no game wasm + no legal blocks (clean dispatch)" as *u8) 83 84 // R7: the 3 outputs are mutually distinct (one engine, type-selected -- not one hardcoded page) 85 ok = 0; if ceq(lbuf, ln, gbuf, gn)==0 { if ceq(gbuf, gn, vbuf, vn)==0 { if ceq(lbuf, ln, vbuf, vn)==0 { ok=1 } } } 86 rows=rows+1; pass=pass+crow(7, ok, "3 distinct pages from 3 data files via 1 engine (type-selected)" as *u8) 87 88 // R8: deterministic -- same .site -> byte-identical build 89 ok = ceq(vbuf, vn, v2buf, v2n) 90 rows=rows+1; pass=pass+crow(8, ok, "deterministic: same .site -> byte-identical build (reproducible)" as *u8) 91 92 cw("NX-SITE-COMPOSE-GATE rows=" as *u8); cnum(rows); cw(" pass=" as *u8); cnum(pass); cw("\n" as *u8) 93 if pass == rows { 94 let line: *u8 = sys_mmap(256) 95 var off: i64 = ccat(line, 0, "CMSGATE row=nx_site_compose site-builder-unified-filedriven rows=" as *u8) 96 off = ccatnum(line, off, rows); off = ccat(line, off, " pass=" as *u8); off = ccatnum(line, off, pass) 97 off = ccat(line, off, " verdict=PASS\n" as *u8) 98 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4) 99 if gf >= 0 { sys_write(gf, line, off); sys_close(gf) } 100 cw("NX-SITE-COMPOSE-GATE verdict=PASS -- unified file-driven multi-type builder recorded in cms_gate.log\n" as *u8) 101 sys_exit(0); return 0 102 } 103 cw("NX-SITE-COMPOSE-GATE verdict=FAIL -- NOT recorded (no fake-green)\n" as *u8) 104 sys_exit(1); return 1 105}