code wiki / _hdl_build / nx_ad_offering_gate.nx
nx_ad_offering_gate.nx source
↩ module page · 77 lines · 4353 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"
16
17const OG_LOG: *u8 = "knowledge/status/ad_offering.log"
18const OG_PREVIEW: *u8 = "knowledge/status/ad_offering_preview.html"
19
20func 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 }
21func 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 }
22
23func 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 {
24 og_w(fd, "OFFERINGGATE authored=organ source=store page_bytes=" as *u8); og_wn(fd, plen)
25 og_w(fd, " has_headline=" as *u8); og_wn(fd, has_head)
26 og_w(fd, " has_zero_promise=" as *u8); og_wn(fd, has_zero)
27 og_w(fd, " clean_thirdparty_js=" as *u8); og_wn(fd, clean3p)
28 og_w(fd, " has_reach_label=" as *u8); og_wn(fd, has_reach)
29 og_w(fd, " store_reach_fee=" as *u8); og_wn(fd, store_fee)
30 og_w(fd, " page_renders_live_fee=" as *u8); og_wn(fd, has_fee)
31 og_w(fd, " page_renders_live_ceiling=" as *u8); og_wn(fd, has_ceil)
32 if ok == 1 { og_w(fd, " verdict=GREEN\n" as *u8) } else { og_w(fd, " verdict=RED\n" as *u8) }
33 return 0
34}
35
36func main() -> i64 {
37 let page: *u8 = sys_mmap(8192)
38 let pn: i64 = on_emit(page)
39
40 let has_head: i64 = as_contains(page, pn, "Brought to you by you" as *u8)
41 let has_zero: i64 = as_contains(page, pn, "you pay <strong>$0</strong>" as *u8)
42 let clean3p: i64 = as_has_thirdparty_js(page, pn)
43 let has_reach: i64 = as_contains(page, pn, "Reach (impressions)" as *u8)
44
45 // DATA-DRIVEN proof: read the live reach price from the store, render it, and require the page
46 // to contain exactly that -- proving the figures are pulled from DATA, not hardcoded.
47 let fee: i64 = ab_perform_fee_of("adpricing:reach" as *u8)
48 let bonus: i64 = ab_exceed_bonus_of("adpricing:reach" as *u8)
49 let feebuf: *u8 = sys_mmap(32)
50 let fl: i64 = on_money(feebuf, 0, fee); feebuf[fl] = 0 as u8
51 let ceilbuf: *u8 = sys_mmap(32)
52 var ceil: i64 = 0 - 1
53 if fee >= 0 { if bonus >= 0 { ceil = fee + bonus } }
54 let cl: i64 = on_money(ceilbuf, 0, ceil); ceilbuf[cl] = 0 as u8
55 let has_fee: i64 = as_contains(page, pn, feebuf)
56 let has_ceil: i64 = as_contains(page, pn, ceilbuf)
57
58 var ok: i64 = 1
59 if has_head != 1 { ok = 0 }
60 if has_zero != 1 { ok = 0 }
61 if clean3p != 0 { ok = 0 }
62 if has_reach != 1 { ok = 0 }
63 if fee < 0 { ok = 0 } // figures should be live (operator go-live); a PENDING fee fails here
64 if has_fee != 1 { ok = 0 } // page renders the live store fee
65 if has_ceil != 1 { ok = 0 } // page renders the live ceiling
66
67 // write the viewable preview (so the operator can open the actual sell page).
68 let prev: i64 = sys_openat_wr(OG_PREVIEW, 420)
69 if prev >= 0 { sys_write(prev, page, pn); sys_close(prev) }
70
71 og_emit(1, pn, has_head, has_zero, clean3p, has_reach, fee, has_fee, has_ceil, ok)
72 let lf: i64 = sys_openat_append(OG_LOG, 420)
73 if lf >= 0 { og_emit(lf, pn, has_head, has_zero, clean3p, has_reach, fee, has_fee, has_ceil, ok); sys_close(lf) }
74
75 if ok == 1 { return 0 }
76 return 1
77}