code wiki / _hdl_build / nx_ad_nb_fold_gate.nx

nx_ad_nb_fold_gate.nx source

↩ module page · 83 lines · 6417 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" 12import "nx_gate_verdict.nx" 13 14const FR_PATH: *u8 = "/tmp/nishi_ad_fold_registry.tsv" 15const FN_PATH: *u8 = "/tmp/nishi_ad_fold_nb.tsv" 16 17func 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 } 18func 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 } 19func 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 } 20 21func main(argc: i64, argv: *i64) -> i64 { 22 g_p("=== nx_ad_nb_fold_gate ===\n" as *u8) 23 let f1: i64 = sys_openat_wr(FR_PATH, 420); if f1 >= 0 { sys_close(f1) } 24 let f2: i64 = sys_openat_wr(FN_PATH, 420); if f2 >= 0 { sys_close(f2) } 25 26 // (a) the ad-only registry -- kind/id/label/template 27 er_register(FR_PATH, "size" as *u8, "leaderboard" as *u8, "Leaderboard 728x90" as *u8, "728x90" as *u8) 28 er_register(FR_PATH, "theme" as *u8, "ocean" as *u8, "Ocean" as *u8, "#06283d|#eaf6ff|#1b98e0|#062033" as *u8) 29 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) 30 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) 31 32 // (b) the UNIVERSAL builder catalog -- domain="ad", same emitters 33 nb_register(FN_PATH, "ad" as *u8, "size" as *u8, "leaderboard" as *u8, "Leaderboard 728x90" as *u8, "728x90" as *u8) 34 nb_register(FN_PATH, "ad" as *u8, "theme" as *u8, "ocean" as *u8, "Ocean" as *u8, "#06283d|#eaf6ff|#1b98e0|#062033" as *u8) 35 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) 36 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) 37 38 let br: *u8 = sys_mmap(16384) 39 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) 40 let bn: *u8 = sys_mmap(16384) 41 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) 42 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) 43 44 var pass: i64 = 0; var tot: i64 = 0 45 46 // T1 both banners actually rendered (business + CTA present) 47 tot = tot + 1; var ok1: i64 = 1 48 if as_contains(bn, nn, "Book a consult" as *u8) != 1 { ok1 = 0 } 49 if as_contains(bn, nn, "Andelin &amp; West" as *u8) != 1 { ok1 = 0 } 50 if nn < 200 { ok1 = 0 } 51 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) } 52 53 // T2 the FOLD is faithful: byte-identical to the ad-registry path 54 tot = tot + 1 55 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) } 56 57 // T3 NEGATIVE CONTROL: unknown theme + size ids -> default fallback, still renders, no crash 58 let bx: *u8 = sys_mmap(16384) 59 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) 60 tot = tot + 1; var ok3: i64 = 1 61 if nx2 < 100 { ok3 = 0 } 62 if as_contains(bx, nx2, "Acme" as *u8) != 1 { ok3 = 0 } 63 if as_contains(bx, nx2, "width:300px" as *u8) != 1 { ok3 = 0 } 64 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) } 65 66 // T4 SOVEREIGNTY: 0 third-party JS in both banners; detector still fires on a planted tag 67 tot = tot + 1; var ok4: i64 = 1 68 if as_has_thirdparty_js(br, nr) != 0 { ok4 = 0 } 69 if as_has_thirdparty_js(bn, nn) != 0 { ok4 = 0 } 70 if as_has_thirdparty_js("<script src='//x'>" as *u8, 18) != 1 { ok4 = 0 } 71 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) } 72 73 g_p("nx_ad_nb_fold_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 74 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 75 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 76 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 77 let ctr__dry: *i64 = gv_ctr() 78 ctr__dry[0] = pass 79 ctr__dry[1] = tot 80 let rc__dry: i64 = gv_verdict("AD-NB-FOLD-GATE" as *u8, ctr__dry, "ad domain folded onto the universal nb_* catalog: ONE SSOT)" as *u8) 81 sys_exit(rc__dry) 82 return rc__dry 83}