code wiki / _hdl_build / nx_ad_emitter_apply_gate.nx
nx_ad_emitter_apply_gate.nx source
↩ module page · 61 lines · 4662 B
1// nx_ad_emitter_apply_gate.nx -- GATE proving the builder CONSUMES grown emitters: teach a temp catalog the
2// grown ocean/star/slide/leaderboard emitters, render a banner FROM the catalog by id, and assert each grown
3// piece actually appears (size, theme colors, star path, slide keyframe) AND the invariants still hold (0
4// third-party JS / 0 external fetch). This closes the loop: grow -> registry -> usable banner. Emits a preview
5// to knowledge/staging/ad/banner_from_registry.html as evidence. license_tier: ORIGINAL
6import "nx_ad_emitter_apply.nx"
7import "nx_ad_emitter_registry.nx"
8import "nx_ad_serve.nx"
9import "nx_syscalls.nx"
10
11const AG_PATH: *u8 = "/tmp/ad_emitters_apply_gate.tsv"
12
13func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
14func g_i(v: i64) -> i64 { let t: *u8 = sys_mmap(24); var m: i64 = v; 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 } let o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1; while q>=0 { o[w]=t[q]; w=w+1; q=q-1 } sys_write(1,o,w); return 0 }
15func g_chk(name: *u8, hay: *u8, n: i64, needle: *u8, want: i64, pass: *i64, tot: *i64) -> i64 {
16 tot[0] = tot[0] + 1
17 var got: i64 = as_contains(hay, n, needle)
18 if got == want { pass[0] = pass[0] + 1; g_p("PASS " as *u8); g_p(name); g_p("\n" as *u8) } else { g_p("FAIL " as *u8); g_p(name); g_p("\n" as *u8) }
19 return 0
20}
21func g_write(fname: *u8, frag: *u8, flen: i64) -> i64 {
22 let doc: *u8 = sys_mmap(20480); var o: i64 = 0
23 o = as_append(doc, o, "<!doctype html><html><head><meta charset='utf-8'></head><body style='margin:0;padding:28px;background:#eef2f7;display:flex;justify-content:center'>" as *u8)
24 var i: i64 = 0; while i < flen { doc[o] = frag[i]; o = o + 1; i = i + 1 }
25 o = as_append(doc, o, "</body></html>" as *u8)
26 let fd: i64 = sys_openat_wr(fname, 420); if fd >= 0 { sys_write(fd, doc, o); sys_close(fd) }
27 return 0
28}
29
30func main(argc: i64, argv: *i64) -> i64 {
31 g_p("=== nx_ad_emitter_apply_gate ===\n" as *u8)
32 // fresh temp catalog + teach the grown emitters we will consume
33 let fd: i64 = sys_openat_wr(AG_PATH, 420); if fd >= 0 { sys_close(fd) }
34 er_register(AG_PATH, "size" as *u8, "leaderboard" as *u8, "Leaderboard 728x90" as *u8, "728x90" as *u8)
35 er_register(AG_PATH, "theme" as *u8, "ocean" as *u8, "Ocean" as *u8, "#06283d|#eaf6ff|#1b98e0|#062033" as *u8)
36 er_register(AG_PATH, "accent" as *u8, "star" as *u8, "Star" as *u8, "<svg class='nb-logo' width='30' height='30' viewBox='0 0 24 24' aria-hidden='true'><path fill='{ACCENT}' d='M12 2l2.9 6.3 6.9.6-5.2 4.5 1.6 6.7L12 17l-6.2 3.6 1.6-6.7L2.2 8.9l6.9-.6z'/></svg>" as *u8)
37 er_register(AG_PATH, "animation" as *u8, "slide" as *u8, "Slide" as *u8, "@keyframes nbsl-{S}{from{transform:translateX(-8px);opacity:.3}to{transform:translateX(0);opacity:1}}.nb-{S} .nb-head{animation:nbsl-{S} .6s ease-out}" as *u8)
38
39 // render a banner FROM the catalog using the GROWN emitters (by id)
40 let out: *u8 = sys_mmap(16384)
41 let n: i64 = ab_emit_from_registry(AG_PATH, "Andelin & West" as *u8, "Estate planning" as *u8,
42 "Wills, trusts & probate." as *u8, "Book a consult" as *u8, "https://andelinwest.com/" as *u8,
43 "leaderboard" as *u8, "ocean" as *u8, "star" as *u8, "slide" as *u8, out)
44 g_write("knowledge/staging/ad/banner_from_registry.html" as *u8, out, n)
45 g_p("rendered " as *u8); g_i(n); g_p(" bytes from grown emitters [leaderboard/ocean/star/slide]\n" as *u8)
46
47 let pass: *i64 = sys_mmap(16) as *i64; let tot: *i64 = sys_mmap(16) as *i64; pass[0] = 0; tot[0] = 0
48 g_chk("T1 grown SIZE applied (width:728px)" as *u8, out, n, "width:728px" as *u8, 1, pass, tot)
49 g_chk("T2 grown THEME applied (ocean bg #06283d)" as *u8, out, n, "#06283d" as *u8, 1, pass, tot)
50 g_chk("T3 grown ACCENT applied (star path)" as *u8, out, n, "M12 2l2.9" as *u8, 1, pass, tot)
51 g_chk("T4 grown ANIMATION applied (slide keyframe nbsl-)" as *u8, out, n, "nbsl-" as *u8, 1, pass, tot)
52 g_chk("T5 default monogram NOT present (grown accent replaced it)" as *u8, out, n, "0 0 36 36" as *u8, 0, pass, tot)
53 // invariant: still 0 third-party JS
54 tot[0] = tot[0] + 1
55 if as_has_thirdparty_js(out, n) == 0 { pass[0] = pass[0] + 1; g_p("PASS T6 invariant: 0 third-party JS in the grown banner\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
56
57 g_p("nx_ad_emitter_apply_gate pass=" as *u8); g_i(pass[0]); g_p("/" as *u8); g_i(tot[0])
58 if pass[0] == tot[0] { g_p(" verdict=GREEN (grow -> registry -> usable banner; loop CLOSED)\n" as *u8); return 0 }
59 g_p(" verdict=RED\n" as *u8)
60 return 1
61}