code wiki / _hdl_build / nx_ad_offering_gate.nx
nx_ad_offering_gate.nx source
↩ module page · 85 lines · 4890 B
1// nx_ad_offering_gate.nx -- GATE (runnable) for ADS-017 the offering sheet. Proves the sell page:
2// sell copy : contains the headline + the "$0 if we miss" promise + the goal labels
3// clean : zero third-party JS (the page itself is a marketing surface, still no <script>/src=)
4// DATA-DRIVEN (the rule-11 point): the rendered prices MATCH the LIVE store figures -- the gate
5// reads adpricing:reach straight from the store, renders "$<fee>"/"$<ceiling>", and
6// asserts the PAGE contains exactly those. Hardcoded copy with stale numbers would fail.
7// Also WRITES the rendered page to knowledge/status/ad_offering_preview.html so the operator can
8// open the actual sell page (with live figures) in a browser.
9//
10// Evidence -> knowledge/status/ad_offering.log (OFFERINGGATE authored=organ ... verdict=GREEN).
11// license_tier: ORIGINAL
12import "nx_ad_offering.nx"
13import "nx_ad_bill.nx"
14import "nx_ad_serve.nx"
15import "nx_syscalls.nx"
16import "nx_gate_verdict.nx"
17
18const OG_LOG: *u8 = "knowledge/status/ad_offering.log"
19const OG_PREVIEW: *u8 = "knowledge/status/ad_offering_preview.html"
20
21func og_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
22func og_wn(fd: i64, v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;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(fd, bb, k); return 0 }
23
24func og_emit(fd: i64, plen: i64, has_head: i64, has_zero: i64, clean3p: i64, has_reach: i64, store_fee: i64, has_fee: i64, has_ceil: i64, ok: i64) -> i64 {
25 og_w(fd, "OFFERINGGATE authored=organ source=store page_bytes=" as *u8); og_wn(fd, plen)
26 og_w(fd, " has_headline=" as *u8); og_wn(fd, has_head)
27 og_w(fd, " has_zero_promise=" as *u8); og_wn(fd, has_zero)
28 og_w(fd, " clean_thirdparty_js=" as *u8); og_wn(fd, clean3p)
29 og_w(fd, " has_reach_label=" as *u8); og_wn(fd, has_reach)
30 og_w(fd, " store_reach_fee=" as *u8); og_wn(fd, store_fee)
31 og_w(fd, " page_renders_live_fee=" as *u8); og_wn(fd, has_fee)
32 og_w(fd, " page_renders_live_ceiling=" as *u8); og_wn(fd, has_ceil)
33 if ok == 1 { og_w(fd, " verdict=GREEN\n" as *u8) } else { og_w(fd, " verdict=RED\n" as *u8) }
34 return 0
35}
36
37func main() -> i64 {
38 let page: *u8 = sys_mmap(8192)
39 let pn: i64 = on_emit(page)
40
41 let has_head: i64 = as_contains(page, pn, "Brought to you by you" as *u8)
42 let has_zero: i64 = as_contains(page, pn, "you pay <strong>$0</strong>" as *u8)
43 let clean3p: i64 = as_has_thirdparty_js(page, pn)
44 let has_reach: i64 = as_contains(page, pn, "Reach (impressions)" as *u8)
45
46 // DATA-DRIVEN proof: read the live reach price from the store, render it, and require the page
47 // to contain exactly that -- proving the figures are pulled from DATA, not hardcoded.
48 let fee: i64 = ab_perform_fee_of("adpricing:reach" as *u8)
49 let bonus: i64 = ab_exceed_bonus_of("adpricing:reach" as *u8)
50 let feebuf: *u8 = sys_mmap(32)
51 let fl: i64 = on_money(feebuf, 0, fee); feebuf[fl] = 0 as u8
52 let ceilbuf: *u8 = sys_mmap(32)
53 var ceil: i64 = 0 - 1
54 if fee >= 0 { if bonus >= 0 { ceil = fee + bonus } }
55 let cl: i64 = on_money(ceilbuf, 0, ceil); ceilbuf[cl] = 0 as u8
56 let has_fee: i64 = as_contains(page, pn, feebuf)
57 let has_ceil: i64 = as_contains(page, pn, ceilbuf)
58
59 var ok: i64 = 1
60 if has_head != 1 { ok = 0 }
61 if has_zero != 1 { ok = 0 }
62 if clean3p != 0 { ok = 0 }
63 if has_reach != 1 { ok = 0 }
64 if fee < 0 { ok = 0 } // figures should be live (operator go-live); a PENDING fee fails here
65 if has_fee != 1 { ok = 0 } // page renders the live store fee
66 if has_ceil != 1 { ok = 0 } // page renders the live ceiling
67
68 // write the viewable preview (so the operator can open the actual sell page).
69 let prev: i64 = sys_openat_wr(OG_PREVIEW, 420)
70 if prev >= 0 { sys_write(prev, page, pn); sys_close(prev) }
71
72 og_emit(1, pn, has_head, has_zero, clean3p, has_reach, fee, has_fee, has_ceil, ok)
73 let lf: i64 = sys_openat_append(OG_LOG, 420)
74 if lf >= 0 { og_emit(lf, pn, has_head, has_zero, clean3p, has_reach, fee, has_fee, has_ceil, ok); sys_close(lf) }
75
76 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
77 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
78 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
79 let ctr__dry: *i64 = gv_ctr()
80 ctr__dry[0] = ok
81 ctr__dry[1] = 1
82 let rc__dry: i64 = gv_verdict("AD-OFFERING-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
83 sys_exit(rc__dry)
84 return rc__dry
85}