code wiki / _hdl_build / nx_ad_nb_fold_gate.nx
nx_ad_nb_fold_gate.nx source
↩ module page · 76 lines · 6018 B
1// nx_ad_nb_fold_gate.nx -- GATE: the AD domain FOLDED onto the universal builder catalog. Seed the SAME ad
2// emitters into (a) the ad-only registry (er_register) and (b) the universal Nishi-builder catalog
3// (nb_register, domain="ad"), render a banner from EACH, and assert they are BYTE-IDENTICAL -- so the one
4// universal catalog (nb_*) is a faithful SSOT for the ad domain, exactly as it already is for web + game.
5// Plus a NEGATIVE CONTROL (unknown ids fall back to defaults, no crash) and SOVEREIGNTY (0 third-party JS in
6// both banners; the detector still fires on a planted tag). Additive: the live er_* path is untouched. license_tier: ORIGINAL
7import "nx_ad_emitter_apply.nx"
8import "nx_ad_emitter_registry.nx"
9import "nx_nishi_builder.nx"
10import "nx_ad_serve.nx"
11import "nx_syscalls.nx"
12
13const FR_PATH: *u8 = "/tmp/nishi_ad_fold_registry.tsv"
14const FN_PATH: *u8 = "/tmp/nishi_ad_fold_nb.tsv"
15
16func 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 }
17func 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 }
18func gb_eq(a: *u8, na: i64, b: *u8, nb: i64) -> i64 { if na != nb { return 0 } var i: i64 = 0; while i < na { if a[i] != b[i] { return 0 } i = i + 1 } return 1 }
19
20func main(argc: i64, argv: *i64) -> i64 {
21 g_p("=== nx_ad_nb_fold_gate ===\n" as *u8)
22 let f1: i64 = sys_openat_wr(FR_PATH, 420); if f1 >= 0 { sys_close(f1) }
23 let f2: i64 = sys_openat_wr(FN_PATH, 420); if f2 >= 0 { sys_close(f2) }
24
25 // (a) the ad-only registry -- kind/id/label/template
26 er_register(FR_PATH, "size" as *u8, "leaderboard" as *u8, "Leaderboard 728x90" as *u8, "728x90" as *u8)
27 er_register(FR_PATH, "theme" as *u8, "ocean" as *u8, "Ocean" as *u8, "#06283d|#eaf6ff|#1b98e0|#062033" as *u8)
28 er_register(FR_PATH, "accent" as *u8, "star" as *u8, "Star" as *u8, "<svg class='nb-logo' viewBox='0 0 24 24'><path fill='{ACCENT}' d='M12 2l2.9 6.3z'/></svg>" as *u8)
29 er_register(FR_PATH, "animation" as *u8, "slide" as *u8, "Slide-in" as *u8, "@keyframes nbsl-{S}{from{opacity:.3}to{opacity:1}}.nb-{S} .nb-head{animation:nbsl-{S} .6s}" as *u8)
30
31 // (b) the UNIVERSAL builder catalog -- domain="ad", same emitters
32 nb_register(FN_PATH, "ad" as *u8, "size" as *u8, "leaderboard" as *u8, "Leaderboard 728x90" as *u8, "728x90" as *u8)
33 nb_register(FN_PATH, "ad" as *u8, "theme" as *u8, "ocean" as *u8, "Ocean" as *u8, "#06283d|#eaf6ff|#1b98e0|#062033" as *u8)
34 nb_register(FN_PATH, "ad" as *u8, "accent" as *u8, "star" as *u8, "Star" as *u8, "<svg class='nb-logo' viewBox='0 0 24 24'><path fill='{ACCENT}' d='M12 2l2.9 6.3z'/></svg>" as *u8)
35 nb_register(FN_PATH, "ad" as *u8, "animation" as *u8, "slide" as *u8, "Slide-in" as *u8, "@keyframes nbsl-{S}{from{opacity:.3}to{opacity:1}}.nb-{S} .nb-head{animation:nbsl-{S} .6s}" as *u8)
36
37 let br: *u8 = sys_mmap(16384)
38 let nr: i64 = ab_emit_from_registry(FR_PATH, "Andelin & West" as *u8, "Estate planning, done right" as *u8, "Wills, trusts & probate." as *u8, "Book a consult" as *u8, "/contact" as *u8, "leaderboard" as *u8, "ocean" as *u8, "star" as *u8, "slide" as *u8, br)
39 let bn: *u8 = sys_mmap(16384)
40 let nn: i64 = ab_emit_from_nb(FN_PATH, "Andelin & West" as *u8, "Estate planning, done right" as *u8, "Wills, trusts & probate." as *u8, "Book a consult" as *u8, "/contact" as *u8, "leaderboard" as *u8, "ocean" as *u8, "star" as *u8, "slide" as *u8, bn)
41 g_p("registry banner=" as *u8); g_i(nr); g_p("B nb-catalog banner=" as *u8); g_i(nn); g_p("B\n" as *u8)
42
43 var pass: i64 = 0; var tot: i64 = 0
44
45 // T1 both banners actually rendered (business + CTA present)
46 tot = tot + 1; var ok1: i64 = 1
47 if as_contains(bn, nn, "Book a consult" as *u8) != 1 { ok1 = 0 }
48 if as_contains(bn, nn, "Andelin & West" as *u8) != 1 { ok1 = 0 }
49 if nn < 200 { ok1 = 0 }
50 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 nb-catalog banner rendered (business + CTA present)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
51
52 // T2 the FOLD is faithful: byte-identical to the ad-registry path
53 tot = tot + 1
54 if gb_eq(br, nr, bn, nn) == 1 { pass = pass + 1; g_p("PASS T2 fold faithful: nb-catalog banner BYTE-IDENTICAL to the ad-registry banner\n" as *u8) } else { g_p("FAIL T2 banners differ (registry vs nb-catalog)\n" as *u8) }
55
56 // T3 NEGATIVE CONTROL: unknown theme + size ids -> default fallback, still renders, no crash
57 let bx: *u8 = sys_mmap(16384)
58 let nx2: i64 = ab_emit_from_nb(FN_PATH, "Acme" as *u8, "Hi" as *u8, "x" as *u8, "Go" as *u8, "/x" as *u8, "no-such-size" as *u8, "no-such-theme" as *u8, "no-such-accent" as *u8, "no-such-anim" as *u8, bx)
59 tot = tot + 1; var ok3: i64 = 1
60 if nx2 < 100 { ok3 = 0 }
61 if as_contains(bx, nx2, "Acme" as *u8) != 1 { ok3 = 0 }
62 if as_contains(bx, nx2, "width:300px" as *u8) != 1 { ok3 = 0 }
63 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 negative control: unknown ids fall back to defaults (300x250), banner still renders\n" as *u8) } else { g_p("FAIL T3 len=" as *u8); g_i(nx2); g_p("\n" as *u8) }
64
65 // T4 SOVEREIGNTY: 0 third-party JS in both banners; detector still fires on a planted tag
66 tot = tot + 1; var ok4: i64 = 1
67 if as_has_thirdparty_js(br, nr) != 0 { ok4 = 0 }
68 if as_has_thirdparty_js(bn, nn) != 0 { ok4 = 0 }
69 if as_has_thirdparty_js("<script src='//x'>" as *u8, 18) != 1 { ok4 = 0 }
70 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 sovereignty: 0 third-party JS in both banners; detector fires on a planted tag\n" as *u8) } else { g_p("FAIL T4\n" as *u8) }
71
72 g_p("nx_ad_nb_fold_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
73 if pass == tot { g_p(" verdict=GREEN (ad domain folded onto the universal nb_* catalog: ONE SSOT)\n" as *u8); return 0 }
74 g_p(" verdict=RED\n" as *u8)
75 return 1
76}