code wiki / _hdl_build / nx_adnet_ops_gate.nx

nx_adnet_ops_gate.nx source

↩ module page · 96 lines · 5946 B

1// nx_adnet_ops_gate.nx -- GATE for the operator view (nx_adnet_ops). 2// The load-bearing tooth is the QUIET one: a healthy plane must produce ZERO bytes. An operator report 3// that always prints something trains people to ignore it, and then the one real finding scrolls past. 4// The rest check that each refusal built today is actually SURFACED -- a refusal nobody can see is 5// indistinguishable from the thing simply not working, and the operator learns about it from the 6// advertiser instead. 7// expect_exit: 0 license_tier: ORIGINAL 8import "nx_syscalls.nx" 9import "_hdl_build/nx_adnet_ops.nx" 10import "nx_gate_verdict.nx" 11 12func to_slen(s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { i = i + 1 } return i } 13func to_puts(s: *u8) -> i64 { sys_write(1, s, to_slen(s)); return 0 } 14func to_pn(v: i64) -> i64 { 15 let b: *u8 = sys_mmap(32) 16 if v == 0 { b[0] = 48 as u8; sys_write(1, b, 1); return 0 } 17 var n: i64 = 0 18 var x: i64 = v 19 while x > 0 { b[n] = ((x - (x / 10) * 10) + 48) as u8; n = n + 1; x = x / 10 } 20 let r: *u8 = sys_mmap(32) 21 var i: i64 = 0 22 while i < n { r[i] = b[n - 1 - i]; i = i + 1 } 23 sys_write(1, r, n) 24 return 0 25} 26func to_has(buf: *u8, n: i64, pat: *u8) -> i64 { 27 let pl: i64 = to_slen(pat) 28 if pl == 0 { return 0 } 29 if pl > n { return 0 } 30 var i: i64 = 0 31 while i <= n - pl { 32 var k: i64 = 0 33 var ok: i64 = 1 34 while k < pl { if buf[i + k] != pat[k] { ok = 0; break } k = k + 1 } 35 if ok == 1 { return 1 } 36 i = i + 1 37 } 38 return 0 39} 40func to_check(name: *u8, cond: i64) -> i64 { 41 if cond == 1 { to_puts(" PASS " as *u8) } else { to_puts(" FAIL " as *u8) } 42 to_puts(name); to_puts("\n" as *u8) 43 return cond 44} 45 46func main() -> i64 { 47 to_puts("=== nx_adnet_ops_gate ===\n" as *u8) 48 var pass: i64 = 0 49 var total: i64 = 0 50 let out: *u8 = sys_mmap(8192) 51 52 // ---- THE QUIET TOOTH: a healthy plane says NOTHING ---- 53 let inv_ok: *u8 = "@host\tnishifamily.com\nha-video\tNishi\t/synth/v.png\t/video\tany\t1\n" as *u8 54 let rates_ok: *u8 = "ha-video\t5000\t100\t-1\n" as *u8 55 let camps_ok: *u8 = "# none\n" as *u8 56 let apps_none: *u8 = "" as *u8 57 let n0: i64 = aop_report(inv_ok, to_slen(inv_ok), rates_ok, to_slen(rates_ok), camps_ok, to_slen(camps_ok), apps_none, 0, out, 8192) 58 pass = pass + to_check("HEALTHY PLANE PRODUCES ZERO BYTES (no alert fatigue)" as *u8, n0 == 0); total = total + 1 59 60 // ---- unpriced inventory: serving now, invoices REFUSED ---- 61 let inv_two: *u8 = "@host\tnishifamily.com\nha-video\tNishi\t/synth/v.png\t/video\tany\t1\nha-world\tNishi\t/synth/w.png\t/world\tany\t1\n" as *u8 62 let n1: i64 = aop_report(inv_two, to_slen(inv_two), rates_ok, to_slen(rates_ok), camps_ok, to_slen(camps_ok), apps_none, 0, out, 8192) 63 pass = pass + to_check("unpriced inventory SURFACED" as *u8, to_has(out, n1, "unpriced-inventory id=ha-world" as *u8)); total = total + 1 64 pass = pass + to_check("priced inventory NOT flagged" as *u8, to_has(out, n1, "id=ha-video" as *u8) == 0); total = total + 1 65 pass = pass + to_check("names the remedy, not just the problem" as *u8, to_has(out, n1, "adnet_rates.conf" as *u8)); total = total + 1 66 67 // ---- campaign with a budget but no spend field: refuses to serve, invisibly ---- 68 let camps_bad: *u8 = "camp-a\tacme\t/synth/v.png\t1000\t2000\t5000\tlive\n" as *u8 69 let n2: i64 = aop_report(inv_ok, to_slen(inv_ok), rates_ok, to_slen(rates_ok), camps_bad, to_slen(camps_bad), apps_none, 0, out, 8192) 70 pass = pass + to_check("campaign that cannot serve SURFACED" as *u8, to_has(out, n2, "campaign-cannot-serve id=camp-a" as *u8)); total = total + 1 71 pass = pass + to_check("remedy names the reconcile beat" as *u8, to_has(out, n2, "reconcile beat" as *u8)); total = total + 1 72 73 // ---- exhausted campaign: stopped serving, advertiser will ask why ---- 74 let camps_ex: *u8 = "camp-b\tacme\t/synth/v.png\t1000\t2000\t5000\tlive\t5000\n" as *u8 75 let n3: i64 = aop_report(inv_ok, to_slen(inv_ok), rates_ok, to_slen(rates_ok), camps_ex, to_slen(camps_ex), apps_none, 0, out, 8192) 76 pass = pass + to_check("exhausted campaign SURFACED" as *u8, to_has(out, n3, "campaign-exhausted id=camp-b" as *u8)); total = total + 1 77 let camps_run: *u8 = "camp-c\tacme\t/synth/v.png\t1000\t2000\t5000\tlive\t100\n" as *u8 78 let n4: i64 = aop_report(inv_ok, to_slen(inv_ok), rates_ok, to_slen(rates_ok), camps_run, to_slen(camps_run), apps_none, 0, out, 8192) 79 pass = pass + to_check("healthy running campaign NOT flagged" as *u8, n4 == 0); total = total + 1 80 81 // ---- pending applications are a work item, not a statistic ---- 82 let apps: *u8 = "application\t1785518618\tAcme\tops@acme.example\thttps://acme.example/\t\napplication\t1785518619\tBeta\tb@b.example\thttps://b.example/\t\n" as *u8 83 let n5: i64 = aop_report(inv_ok, to_slen(inv_ok), rates_ok, to_slen(rates_ok), camps_ok, to_slen(camps_ok), apps, to_slen(apps), out, 8192) 84 pass = pass + to_check("pending applications SURFACED with a count" as *u8, to_has(out, n5, "pending-applications n=2" as *u8)); total = total + 1 85 pass = pass + to_check("says staged-never-live so nobody assumes it auto-ran" as *u8, to_has(out, n5, "staged, never live" as *u8)); total = total + 1 86 87 to_puts("pass=" as *u8); to_pn(pass); to_puts(" fail=" as *u8); to_pn(total - pass); to_puts("\n" as *u8) 88 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 89 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 90 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 91 let ctr__dry: *i64 = gv_ctr() 92 ctr__dry[0] = pass 93 ctr__dry[1] = total 94 let rc__dry: i64 = gv_verdict("ADNET-OPS-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 95 sys_exit(rc__dry) 96 return rc__dry 97}