code wiki / (root) / nx_communitypulse_gate.nx

nx_communitypulse_gate.nx source

↩ module page · 396 lines · 28028 B

1// nx_communitypulse_gate.nx -- THE GATE FOR THE COMMUNITY PULSE (2026-08-24). 2// 3// SUBJECT: the nx_communitypulse ELF, forked for real with a fresh store per run (/tmp/<gate>/r<usec>/), so 4// the gate is idempotent by construction: nothing measured here was inherited from an earlier run. 5// FIXTURE: a six-cell forest nation > region > locality > {church a, agency b, nonprofit c}; a one-item 6// pulse instrument; kiosk ballots a=7 b=6 c=2 under k=5. That shape is chosen so every release state 7// occurs at once: a and b PUBLISHED, c WITHHELD-UNDER-K, the locality WITHHELD-COMPLEMENTARY (15 - 7 - 6 = 2 8// contributors would be isolatable), the region PUBLISHED (its only child is withheld, residual 15), the 9// nation PUBLISHED (residual 0). Every expected number below is derived from those ballots by hand and 10// asserted exactly; no tooth passes on an empty set (the fixture-reached-the-condition teeth come first). 11// Every negative control is a gv_bite: fires on the crafted bad input AND stays silent on the good one. 12import "nx_syscalls.nx" 13import "nx_gate_verdict.nx" 14import "nx_tool_run.nx" 15 16const CPG_SUBJECT_DEFAULT: *u8 = "_offc/nx_communitypulse.elf" 17const CPG_DIR: *u8 = "/tmp/nx_communitypulse_gate" 18const CPG_EXIT_OK: i64 = 0 19const CPG_EXIT_REFUSED: i64 = 1 20const CPG_EXIT_USAGE: i64 = 2 21const CPG_EXIT_UNOBSERVABLE: i64 = 3 22const CPG_MODE_DIR: i64 = 493 // 0755 23const CPG_CAPTURE_CAP: i64 = 65536 24const CPG_PATH_CAP: i64 = 512 25const CPG_ARGV_SLOTS: i64 = 16 26const CPG_WORD: i64 = 8 27const CPG_CONF_BYTES: i64 = 4096 28const CPG_NUM_BYTES: i64 = 32 29const CPG_SMALL: i64 = 16 30const CPG_ASCII_DASH: i64 = 45 31const CPG_ASCII_ZERO: i64 = 48 32const CPG_DECIMAL: i64 = 10 33const CPG_LP_BYTES: i64 = 16 34const CPG_ASCII_NL: i64 = 10 35const CPG_ASCII_M: i64 = 77 36// the fixture, as data 37const CPG_K: i64 = 5 38const CPG_RATE_MAX: i64 = 7 39const CPG_WINDOW_US: i64 = 3600000000 // one hour: every fixture ballot is inside it, so the trend halves cannot both clear k 40const CPG_A_DENOM: i64 = 100 41const CPG_B_DENOM: i64 = 50 42const CPG_C_DENOM: i64 = 20 43const CPG_A_N: i64 = 7 44const CPG_EXPECT_A_MEAN: *u8 = "|own=7|total=7|PUBLISHED|mean_pm=6285|" // 2+3+3+8+9+9+10 = 44; 44000/7 45const CPG_EXPECT_B_MEAN: *u8 = "|own=6|total=6|PUBLISHED|mean_pm=8000|" // 6+7+8+8+9+10 = 48; 48000/6 46const CPG_EXPECT_C: *u8 = "row|c|nonprofit|l1|own=2|total=2|WITHHELD-UNDER-K|" 47const CPG_EXPECT_L1: *u8 = "row|l1|locality|r1|own=0|total=15|WITHHELD-COMPLEMENTARY|" 48const CPG_EXPECT_R1: *u8 = "row|r1|region|n1|own=0|total=15|PUBLISHED|mean_pm=6866|" // (44+48+11)*1000/15 49const CPG_EXPECT_N1: *u8 = "row|n1|nation|-|own=0|total=15|PUBLISHED|mean_pm=6866|" 50const CPG_EXPECT_PART: *u8 = "partition published=4 withheld_k=1 withheld_comp=1 sum=6 cells=6 SUMS" 51const CPG_EXPECT_BALLOTS: *u8 = "ballots own_sum=15 roots_total=15 SUMS" 52const CPG_EXPECT_WEIGHTED_R1: *u8 = "weighted|r1|PUBLISHED|wmean_pm=6697|denom_sum=170|leaves=3" // (6285*100 + 8000*50 + 5500*20) / 170 53 54static cpg_cap_g: *u8 55static cpg_olen_g: *i64 56func cpg_write_text(path: *u8, s: *u8) -> i64 { 57 var n: i64 = 0 58 while s[n] != (0 as u8) { n = n + 1 } 59 let fd: i64 = sys_openat_wr(path, MODE_0644) 60 if fd < 0 { return 0 - 1 } 61 let wr: i64 = sys_write(fd, s, n) 62 sys_close(fd) 63 if wr != n { return 0 - 1 } 64 return n 65} 66func cpg_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } return off + i } 67func cpg_catn(dst: *u8, off: i64, v: i64) -> i64 { 68 var o: i64 = off 69 var m: i64 = v 70 if m < 0 { dst[o] = CPG_ASCII_DASH as u8; o = o + 1; m = 0 - m } 71 let t: *u8 = sys_mmap(CPG_NUM_BYTES) 72 var k: i64 = 0 73 if m == 0 { t[0] = CPG_ASCII_ZERO as u8; k = 1 } 74 while m > 0 { t[k] = (CPG_ASCII_ZERO + (m % CPG_DECIMAL)) as u8; m = m / CPG_DECIMAL; k = k + 1 } 75 while k > 0 { k = k - 1; dst[o] = t[k]; o = o + 1 } 76 return o 77} 78func cpg_path(dir: *u8, leaf: *u8) -> *u8 { 79 let p: *u8 = sys_mmap(CPG_PATH_CAP) 80 var o: i64 = cpg_cat(p, 0, dir) 81 o = cpg_cat(p, o, "/" as *u8) 82 o = cpg_cat(p, o, leaf) 83 p[o] = 0 as u8 84 return p 85} 86// run the subject: <conf> <verb> a1..a7 (0 = end). Returns the exit code; capture in cpg_cap_g. 87func cpg_run(subject: *u8, conf: *u8, verb: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8, a6: *u8, a7: *u8) -> i64 { 88 let av: *i64 = sys_mmap(CPG_WORD * CPG_ARGV_SLOTS) as *i64 89 var n: i64 = 0 90 av[n] = subject as i64; n = n + 1 91 av[n] = conf as i64; n = n + 1 92 av[n] = verb as i64; n = n + 1 93 if (a1 as i64) != 0 { av[n] = a1 as i64; n = n + 1 } 94 if (a2 as i64) != 0 { av[n] = a2 as i64; n = n + 1 } 95 if (a3 as i64) != 0 { av[n] = a3 as i64; n = n + 1 } 96 if (a4 as i64) != 0 { av[n] = a4 as i64; n = n + 1 } 97 if (a5 as i64) != 0 { av[n] = a5 as i64; n = n + 1 } 98 if (a6 as i64) != 0 { av[n] = a6 as i64; n = n + 1 } 99 if (a7 as i64) != 0 { av[n] = a7 as i64; n = n + 1 } 100 av[n] = 0 101 cpg_cap_g[0] = 0 as u8 102 let rc: i64 = tr_run_capture(subject, av, cpg_cap_g, CPG_CAPTURE_CAP, cpg_olen_g) 103 // NUL-terminate at the captured length: the diagnostic dump below prints the buffer as a string, and 104 // without this a shorter capture would print the tail of an earlier, longer one after its own bytes. 105 var term: i64 = cpg_olen_g[0] 106 if term < 0 { term = 0 } 107 if term >= CPG_CAPTURE_CAP { term = CPG_CAPTURE_CAP - 1 } 108 cpg_cap_g[term] = 0 as u8 109 return rc 110} 111func cpg_has(needle: *u8) -> i64 { return tr_contains(cpg_cap_g, cpg_olen_g[0], needle) } 112func cpg_file_has(path: *u8, needle: *u8) -> i64 { 113 let lp: *i64 = sys_mmap(CPG_LP_BYTES) as *i64 114 let b: *u8 = sys_read_file(path, lp) 115 if (b as i64) == 0 { return 0 } 116 return tr_contains(b, lp[0], needle) 117} 118func cpg_nil() -> *u8 { return 0 as *u8 } 119func cpg_kiosk1(subject: *u8, conf: *u8, prefix: *u8, cell: *u8, v: *u8) -> i64 { 120 let a: *u8 = sys_mmap(CPG_NUM_BYTES) 121 var o: i64 = cpg_cat(a, 0, "p01=" as *u8) 122 o = cpg_cat(a, o, v) 123 a[o] = 0 as u8 124 return cpg_run(subject, conf, "kiosk" as *u8, prefix, "pulse1" as *u8, cell, a, cpg_nil(), cpg_nil(), cpg_nil()) 125} 126 127func main(argc: i64, argv: *i64) -> i64 { 128 let ctr: *i64 = gv_ctr() 129 gv_head("nx_communitypulse gate -- one instrument, one floor, every level of the hierarchy, complementary suppression proven by a planted subtraction" as *u8) 130 var subject: *u8 = CPG_SUBJECT_DEFAULT 131 if argc >= 2 { subject = argv[1] as *u8 } 132 gv_puts(" subject: " as *u8); gv_puts(subject); gv_puts("\n\n" as *u8) 133 cpg_cap_g = sys_mmap(CPG_CAPTURE_CAP) 134 cpg_olen_g = sys_mmap(CPG_LP_BYTES) as *i64 135 136 // ---- SETUP: a fresh run directory (idempotent by construction), the conf, the specs, the seed ---- 137 sys_mkdir(CPG_DIR, CPG_MODE_DIR) 138 let rundir: *u8 = sys_mmap(CPG_PATH_CAP) 139 var ro: i64 = cpg_cat(rundir, 0, CPG_DIR) 140 ro = cpg_cat(rundir, ro, "/r" as *u8) 141 ro = cpg_catn(rundir, ro, sys_now_us()) 142 rundir[ro] = 0 as u8 143 sys_mkdir(rundir, CPG_MODE_DIR) 144 let prefix: *u8 = cpg_path(rundir, "cp-" as *u8) 145 let conf: *u8 = cpg_path(rundir, "pulse.conf" as *u8) 146 let conf_nokey: *u8 = cpg_path(rundir, "nokey.conf" as *u8) 147 let conf_field_ok: *u8 = cpg_path(rundir, "field_ok.conf" as *u8) 148 let conf_field_bad: *u8 = cpg_path(rundir, "field_bad.conf" as *u8) 149 let seed: *u8 = cpg_path(rundir, "export.seed" as *u8) 150 let spec_pulse: *u8 = cpg_path(rundir, "pulse1.survey" as *u8) 151 let spec_nocite: *u8 = cpg_path(rundir, "nocite.survey" as *u8) 152 let spec_short: *u8 = cpg_path(rundir, "short.survey" as *u8) 153 let spec_f12: *u8 = cpg_path(rundir, "f12.survey" as *u8) 154 let page_a: *u8 = cpg_path(rundir, "a.html" as *u8) 155 let page_c: *u8 = cpg_path(rundir, "c.html" as *u8) 156 let page_r1: *u8 = cpg_path(rundir, "r1.html" as *u8) 157 let export: *u8 = cpg_path(rundir, "export.nxcpx" as *u8) 158 let tampered: *u8 = cpg_path(rundir, "tampered.nxcpx" as *u8) 159 // the conf: every threshold the subject reads, as rows (the same file shape production uses) 160 let cb: *u8 = sys_mmap(CPG_CONF_BYTES) 161 var co: i64 = cpg_cat(cb, 0, "kmin=" as *u8); co = cpg_catn(cb, co, CPG_K); co = cpg_cat(cb, co, "\nkiosk_rate_max=" as *u8); co = cpg_catn(cb, co, CPG_RATE_MAX) 162 co = cpg_cat(cb, co, "\nkiosk_rate_window_us=" as *u8); co = cpg_catn(cb, co, CPG_WINDOW_US) 163 co = cpg_cat(cb, co, "\nitems_pulse=1\nitems_flourish=12\nalert_low_max=3\nalert_count=3\ntrend_window_us=" as *u8); co = cpg_catn(cb, co, CPG_WINDOW_US) 164 co = cpg_cat(cb, co, "\ncell_kinds=church,agency,nonprofit,locality,region,nation\n" as *u8) 165 let cbase: i64 = co 166 cb[co] = 0 as u8 167 cpg_write_text(conf_nokey, cb) 168 var c2: i64 = cpg_cat(cb, cbase, "export_seed=" as *u8); c2 = cpg_cat(cb, c2, seed); c2 = cpg_cat(cb, c2, "\n" as *u8) 169 cb[c2] = 0 as u8 170 cpg_write_text(conf, cb) 171 var c3: i64 = cpg_cat(cb, c2, "field_cells=a,b\n" as *u8); cb[c3] = 0 as u8 172 cpg_write_text(conf_field_ok, cb) 173 var c4: i64 = cpg_cat(cb, c2, "field_cells=a,c\n" as *u8); cb[c4] = 0 as u8 174 cpg_write_text(conf_field_bad, cb) 175 // a TEST key, never a production one: 32 bytes as 64 hex 176 cpg_write_text(seed, "0f1e2d3c4b5a69788796a5b4c3d2e1f00f1e2d3c4b5a69788796a5b4c3d2e1f0\n" as *u8) 177 cpg_write_text(spec_pulse, "@survey placeholder\n@kind pulse\n@title How are things going\n@license CC-BY-NC-4.0\n@cite gate fixture citation row\nQ|p01|S|0|10|Overall, how are things going for you these days?\n" as *u8) 178 cpg_write_text(spec_nocite, "@survey placeholder\n@kind pulse\n@title No citation\n@license CC-BY-NC-4.0\nQ|p01|S|0|10|How are things going?\n" as *u8) 179 cpg_write_text(spec_short, "@survey placeholder\n@kind flourish\n@title Eleven items\n@license CC-BY-NC-4.0\n@cite fixture\nQ|f01|S|0|10|a\nQ|f02|S|0|10|b\nQ|f03|S|0|10|c\nQ|f04|S|0|10|d\nQ|f05|S|0|10|e\nQ|f06|S|0|10|f\nQ|f07|S|0|10|g\nQ|f08|S|0|10|h\nQ|f09|S|0|10|i\nQ|f10|S|0|10|j\nQ|f11|S|0|10|k\n" as *u8) 180 cpg_write_text(spec_f12, "@survey placeholder\n@kind flourish\n@title Twelve items\n@license CC-BY-NC-4.0\n@cite fixture\nQ|f01|S|0|10|a\nQ|f02|S|0|10|b\nQ|f03|S|0|10|c\nQ|f04|S|0|10|d\nQ|f05|S|0|10|e\nQ|f06|S|0|10|f\nQ|f07|S|0|10|g\nQ|f08|S|0|10|h\nQ|f09|S|0|10|i\nQ|f10|S|0|10|j\nQ|f11|S|0|10|k\nQ|f12|S|0|10|l\n" as *u8) 181 var setup: i64 = 0 182 if cpg_file_has(conf, "export_seed=" as *u8) == 1 { if cpg_file_has(spec_f12, "Q|f12|" as *u8) == 1 { if cpg_file_has(seed, "0f1e2d3c" as *u8) == 1 { setup = 1 } } } 183 gv_check("setup-fixtures-written (conf, specs, seed in a fresh run dir)" as *u8, setup, ctr) 184 185 // ---- T1: usage is exit 2 ---- 186 let rcu: i64 = cpg_run(subject, conf, "nonsense" as *u8, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 187 var t1: i64 = 0 188 if rcu == CPG_EXIT_USAGE { t1 = 1 } 189 gv_check("unknown-verb-exits-usage-2" as *u8, t1, ctr) 190 191 // ---- T2: the forest. cp_org_scope ---- 192 var cells_ok: i64 = 1 193 if cpg_run(subject, conf, "cell-put" as *u8, prefix, "n1" as *u8, "nation" as *u8, "Testland" as *u8, "-" as *u8, "0" as *u8, cpg_nil()) != CPG_EXIT_OK { cells_ok = 0 } 194 if cpg_run(subject, conf, "cell-put" as *u8, prefix, "r1" as *u8, "region" as *u8, "North" as *u8, "n1" as *u8, "0" as *u8, cpg_nil()) != CPG_EXIT_OK { cells_ok = 0 } 195 if cpg_run(subject, conf, "cell-put" as *u8, prefix, "l1" as *u8, "locality" as *u8, "Rivertown" as *u8, "r1" as *u8, "0" as *u8, cpg_nil()) != CPG_EXIT_OK { cells_ok = 0 } 196 let da: *u8 = sys_mmap(CPG_SMALL); cpg_catn(da, 0, CPG_A_DENOM); da[3] = 0 as u8 197 let db: *u8 = sys_mmap(CPG_SMALL); cpg_catn(db, 0, CPG_B_DENOM); db[2] = 0 as u8 198 if cpg_run(subject, conf, "cell-put" as *u8, prefix, "a" as *u8, "church" as *u8, "St Johns" as *u8, "l1" as *u8, da, cpg_nil()) != CPG_EXIT_OK { cells_ok = 0 } 199 if cpg_run(subject, conf, "cell-put" as *u8, prefix, "b" as *u8, "agency" as *u8, "County Services" as *u8, "l1" as *u8, db, cpg_nil()) != CPG_EXIT_OK { cells_ok = 0 } 200 if cpg_run(subject, conf, "cell-put" as *u8, prefix, "c" as *u8, "nonprofit" as *u8, "Food Pantry" as *u8, "l1" as *u8, "0" as *u8, cpg_nil()) != CPG_EXIT_OK { cells_ok = 0 } 201 gv_check("six-cells-put (nation > region > locality > church, agency, nonprofit)" as *u8, cells_ok, ctr) 202 let rcl: i64 = cpg_run(subject, conf, "cell-list" as *u8, prefix, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 203 var t2b: i64 = 0 204 if rcl == CPG_EXIT_OK { if cpg_has("cells=6" as *u8) == 1 { if cpg_has("cell|a|church|St Johns|l1|denom=100" as *u8) == 1 { t2b = 1 } } } 205 gv_check("fixture-reached-the-condition (cell-list reads back all six with kinds, parents, denominators)" as *u8, t2b, ctr) 206 // negative controls on scoping 207 let rck: i64 = cpg_run(subject, conf, "cell-put" as *u8, prefix, "z" as *u8, "cult" as *u8, "Nope" as *u8, "l1" as *u8, "0" as *u8, cpg_nil()) 208 var kind_fired: i64 = 0 209 if rck == CPG_EXIT_REFUSED { if cpg_has("REFUSED-KIND" as *u8) == 1 { kind_fired = 1 } } 210 var kind_good: i64 = 0 211 if cells_ok == 0 { kind_good = 1 } 212 gv_bite("neg-control-unknown-kind-refused-by-name-declared-kinds-admitted" as *u8, kind_fired, kind_good, ctr) 213 let rcp: i64 = cpg_run(subject, conf, "cell-put" as *u8, prefix, "y" as *u8, "church" as *u8, "Orphan" as *u8, "nowhere" as *u8, "0" as *u8, cpg_nil()) 214 var par_fired: i64 = 0 215 if rcp == CPG_EXIT_REFUSED { if cpg_has("REFUSED-UNKNOWN-PARENT" as *u8) == 1 { par_fired = 1 } } 216 gv_bite("neg-control-unknown-parent-refused-known-parent-admitted" as *u8, par_fired, kind_good, ctr) 217 218 // ---- T3: the instrument. cp_instrument ---- 219 var inst_ok: i64 = 1 220 let rca: i64 = cpg_run(subject, conf, "instrument" as *u8, prefix, spec_pulse, "pulse1" as *u8, "a" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) 221 if rca != CPG_EXIT_OK { inst_ok = 0 } 222 if cpg_has("LOADED survey=pulse1-a items=1 kind=pulse license=CC-BY-NC-4.0 k=5" as *u8) == 0 { inst_ok = 0 } 223 if cpg_run(subject, conf, "instrument" as *u8, prefix, spec_pulse, "pulse1" as *u8, "b" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) != CPG_EXIT_OK { inst_ok = 0 } 224 if cpg_run(subject, conf, "instrument" as *u8, prefix, spec_pulse, "pulse1" as *u8, "c" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) != CPG_EXIT_OK { inst_ok = 0 } 225 gv_check("instrument-loaded-at-three-cells (survey id = instrument-cell, anon, conf floor carried)" as *u8, inst_ok, ctr) 226 let rcf: i64 = cpg_run(subject, conf, "instrument" as *u8, prefix, spec_f12, "flourish" as *u8, "a" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) 227 var t3b: i64 = 0 228 if rcf == CPG_EXIT_OK { if cpg_has("items=12 kind=flourish" as *u8) == 1 { t3b = 1 } } 229 gv_check("twelve-item-flourish-instrument-loads (conf items_flourish=12 matched)" as *u8, t3b, ctr) 230 let rcn: i64 = cpg_run(subject, conf, "instrument" as *u8, prefix, spec_nocite, "pulse1" as *u8, "a" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) 231 var cite_fired: i64 = 0 232 if rcn == CPG_EXIT_REFUSED { if cpg_has("REFUSED-NO-CITE" as *u8) == 1 { cite_fired = 1 } } 233 var cite_good: i64 = 0 234 if inst_ok == 0 { cite_good = 1 } 235 gv_bite("neg-control-instrument-without-citation-refused-cited-one-loads" as *u8, cite_fired, cite_good, ctr) 236 let rcs: i64 = cpg_run(subject, conf, "instrument" as *u8, prefix, spec_short, "flourish" as *u8, "b" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) 237 var items_fired: i64 = 0 238 if rcs == CPG_EXIT_REFUSED { if cpg_has("REFUSED-ITEMS kind=flourish declared=12 found=11" as *u8) == 1 { items_fired = 1 } } 239 var items_good: i64 = 0 240 if t3b == 0 { items_good = 1 } 241 gv_bite("neg-control-eleven-item-flourish-refused-twelve-admitted" as *u8, items_fired, items_good, ctr) 242 243 // ---- T4: kiosk intake with the rate row. cp_kiosk ---- 244 var k_ok: i64 = 1 245 if cpg_kiosk1(subject, conf, prefix, "a" as *u8, "2" as *u8) != CPG_EXIT_OK { k_ok = 0 } 246 if cpg_kiosk1(subject, conf, prefix, "a" as *u8, "3" as *u8) != CPG_EXIT_OK { k_ok = 0 } 247 if cpg_kiosk1(subject, conf, prefix, "a" as *u8, "3" as *u8) != CPG_EXIT_OK { k_ok = 0 } 248 if cpg_kiosk1(subject, conf, prefix, "a" as *u8, "8" as *u8) != CPG_EXIT_OK { k_ok = 0 } 249 if cpg_kiosk1(subject, conf, prefix, "a" as *u8, "9" as *u8) != CPG_EXIT_OK { k_ok = 0 } 250 if cpg_kiosk1(subject, conf, prefix, "a" as *u8, "9" as *u8) != CPG_EXIT_OK { k_ok = 0 } 251 if cpg_kiosk1(subject, conf, prefix, "a" as *u8, "10" as *u8) != CPG_EXIT_OK { k_ok = 0 } 252 if cpg_has("RECORDED survey=pulse1-a answers=1 kiosk_seen_in_window=7 of 7" as *u8) == 0 { k_ok = 0 } 253 gv_check("seven-kiosk-ballots-recorded-at-a (token-less, each a fresh ballot)" as *u8, k_ok, ctr) 254 let rc8: i64 = cpg_kiosk1(subject, conf, prefix, "a" as *u8, "5" as *u8) 255 var rate_fired: i64 = 0 256 if rc8 == CPG_EXIT_REFUSED { if cpg_has("REFUSED-RATE cell=a" as *u8) == 1 { if cpg_has("max=7 seen=7" as *u8) == 1 { rate_fired = 1 } } } 257 var rate_good: i64 = 0 258 if k_ok == 0 { rate_good = 1 } 259 gv_bite("neg-control-eighth-ballot-in-window-refused-by-the-rate-row-seven-admitted" as *u8, rate_fired, rate_good, ctr) 260 var kb_ok: i64 = 1 261 if cpg_kiosk1(subject, conf, prefix, "b" as *u8, "6" as *u8) != CPG_EXIT_OK { kb_ok = 0 } 262 if cpg_kiosk1(subject, conf, prefix, "b" as *u8, "7" as *u8) != CPG_EXIT_OK { kb_ok = 0 } 263 if cpg_kiosk1(subject, conf, prefix, "b" as *u8, "8" as *u8) != CPG_EXIT_OK { kb_ok = 0 } 264 if cpg_kiosk1(subject, conf, prefix, "b" as *u8, "8" as *u8) != CPG_EXIT_OK { kb_ok = 0 } 265 if cpg_kiosk1(subject, conf, prefix, "b" as *u8, "9" as *u8) != CPG_EXIT_OK { kb_ok = 0 } 266 if cpg_kiosk1(subject, conf, prefix, "b" as *u8, "10" as *u8) != CPG_EXIT_OK { kb_ok = 0 } 267 if cpg_kiosk1(subject, conf, prefix, "c" as *u8, "5" as *u8) != CPG_EXIT_OK { kb_ok = 0 } 268 if cpg_kiosk1(subject, conf, prefix, "c" as *u8, "6" as *u8) != CPG_EXIT_OK { kb_ok = 0 } 269 gv_check("six-ballots-at-b-and-two-at-c-recorded" as *u8, kb_ok, ctr) 270 let rcbad: i64 = cpg_kiosk1(subject, conf, prefix, "b" as *u8, "11" as *u8) 271 var range_fired: i64 = 0 272 if rcbad == CPG_EXIT_REFUSED { if cpg_has("REFUSED-ENGINE se_respond rc=-3" as *u8) == 1 { range_fired = 1 } } 273 var range_good: i64 = 0 274 if kb_ok == 0 { range_good = 1 } 275 gv_bite("neg-control-out-of-range-answer-refused-by-the-engine-in-range-admitted" as *u8, range_fired, range_good, ctr) 276 277 // ---- T5: the release. cp_rollup + cp_complement_suppress ---- 278 let rcr: i64 = cpg_run(subject, conf, "rollup" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 279 gv_puts(" [rollup]\n" as *u8); gv_puts(cpg_cap_g); gv_puts("\n" as *u8) 280 var t5: i64 = 0 281 if rcr == CPG_EXIT_OK { if cpg_has("k=5 cells=6" as *u8) == 1 { t5 = 1 } } 282 gv_check("rollup-exits-OK-over-six-cells-under-k-5" as *u8, t5, ctr) 283 var t5a: i64 = 0 284 if cpg_has(CPG_EXPECT_A_MEAN) == 1 { if cpg_has(CPG_EXPECT_B_MEAN) == 1 { t5a = 1 } } 285 gv_check("published-organisations-carry-the-hand-derived-means (a 6.285, b 8.000)" as *u8, t5a, ctr) 286 var t5c: i64 = 0 287 if cpg_has(CPG_EXPECT_C) == 1 { t5c = 1 } 288 gv_check("organisation-under-k-is-WITHHELD-UNDER-K-with-no-number (c, n=2)" as *u8, t5c, ctr) 289 var comp_fired: i64 = 0 290 if cpg_has(CPG_EXPECT_L1) == 1 { comp_fired = 1 } 291 var comp_good: i64 = 1 292 if cpg_has(CPG_EXPECT_N1) == 1 { comp_good = 0 } 293 gv_bite("neg-control-complementary-suppression-locality-with-residual-2-withheld-nation-with-residual-0-published" as *u8, comp_fired, comp_good, ctr) 294 var t5r: i64 = 0 295 if cpg_has(CPG_EXPECT_R1) == 1 { t5r = 1 } 296 gv_check("region-whose-only-child-is-withheld-publishes (residual 15 >= k)" as *u8, t5r, ctr) 297 var t5p: i64 = 0 298 if cpg_has(CPG_EXPECT_PART) == 1 { if cpg_has(CPG_EXPECT_BALLOTS) == 1 { t5p = 1 } } 299 gv_check("partition-and-ballot-sums-reconcile (4+1+1=6 cells; own 15 = roots 15)" as *u8, t5p, ctr) 300 301 // ---- T6: weights as data. cp_weights ---- 302 let rcw0: i64 = cpg_run(subject, conf, "weights" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 303 var den_fired: i64 = 0 304 if rcw0 == CPG_EXIT_REFUSED { if cpg_has("REFUSED-NO-DENOMINATOR cell=c" as *u8) == 1 { den_fired = 1 } } 305 let dc: *u8 = sys_mmap(CPG_SMALL); cpg_catn(dc, 0, CPG_C_DENOM); dc[2] = 0 as u8 306 cpg_run(subject, conf, "cell-put" as *u8, prefix, "c" as *u8, "nonprofit" as *u8, "Food Pantry" as *u8, "l1" as *u8, dc, cpg_nil()) 307 let rcw1: i64 = cpg_run(subject, conf, "weights" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 308 gv_puts(" [weights]\n" as *u8); gv_puts(cpg_cap_g); gv_puts("\n" as *u8) 309 var den_good: i64 = 1 310 if rcw1 == CPG_EXIT_OK { if cpg_has(CPG_EXPECT_WEIGHTED_R1) == 1 { den_good = 0 } } 311 gv_bite("neg-control-missing-denominator-refuses-by-name-declared-denominators-weight-the-region-to-6.697" as *u8, den_fired, den_good, ctr) 312 313 // ---- T7: the public page and the join. cp_public_page + cp_benchmark ---- 314 let rcpa: i64 = cpg_run(subject, conf, "page" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, "a" as *u8, page_a, cpg_nil(), cpg_nil()) 315 var t7a: i64 = 0 316 if rcpa == CPG_EXIT_OK { if cpg_file_has(page_a, "data-cell='a'" as *u8) == 1 { if cpg_file_has(page_a, "data-state='PUBLISHED'" as *u8) == 1 { if cpg_file_has(page_a, "data-mean-pm='6285'" as *u8) == 1 { t7a = 1 } } } } 317 gv_check("page-for-a-published-organisation-carries-its-number-and-margin" as *u8, t7a, ctr) 318 var t7b: i64 = 0 319 if cpg_file_has(page_a, "data-parent='l1'" as *u8) == 1 { if cpg_file_has(page_a, "data-parent-state='WITHHELD-COMPLEMENTARY'" as *u8) == 1 { if cpg_file_has(page_a, "data-benchmark='UNAVAILABLE'" as *u8) == 1 { t7b = 1 } } } 320 gv_check("page-shows-the-level-above-as-WITHHELD-and-no-comparison-when-that-level-is-suppressed" as *u8, t7b, ctr) 321 var t7t: i64 = 0 322 if cpg_file_has(page_a, "trend WITHHELD" as *u8) == 1 { t7t = 1 } 323 gv_check("trend-halves-under-the-floor-are-withheld-not-printed" as *u8, t7t, ctr) 324 let rcpc: i64 = cpg_run(subject, conf, "page" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, "c" as *u8, page_c, cpg_nil(), cpg_nil()) 325 var t7c: i64 = 0 326 if rcpc == CPG_EXIT_OK { if cpg_file_has(page_c, "data-state='WITHHELD-UNDER-K'" as *u8) == 1 { if cpg_file_has(page_c, "data-mean-pm=" as *u8) == 0 { t7c = 1 } } } 327 gv_check("page-for-an-organisation-under-k-prints-WITHHELD-and-no-number-at-all" as *u8, t7c, ctr) 328 let rcpr: i64 = cpg_run(subject, conf, "page" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, "r1" as *u8, page_r1, cpg_nil(), cpg_nil()) 329 var t7r: i64 = 0 330 if rcpr == CPG_EXIT_OK { if cpg_file_has(page_r1, "data-benchmark='WITHIN'" as *u8) == 1 { if cpg_file_has(page_r1, "data-delta-pm='0'" as *u8) == 1 { t7r = 1 } } } 331 gv_check("benchmark-join-region-versus-nation-reads-WITHIN-with-delta-0 (same contributors)" as *u8, t7r, ctr) 332 let rcpx: i64 = cpg_run(subject, conf, "page" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, "nosuch" as *u8, page_c, cpg_nil(), cpg_nil()) 333 var pg_fired: i64 = 0 334 if rcpx == CPG_EXIT_REFUSED { if cpg_has("REFUSED-UNKNOWN-CELL" as *u8) == 1 { pg_fired = 1 } } 335 var pg_good: i64 = 0 336 if t7a == 0 { pg_good = 1 } 337 gv_bite("neg-control-page-for-unknown-cell-refused-known-cell-emitted" as *u8, pg_fired, pg_good, ctr) 338 339 // ---- T8: the crisis alert. cp_alert ---- 340 let rcaa: i64 = cpg_run(subject, conf, "alert" as *u8, prefix, "pulse1" as *u8, "a" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) 341 var al_fired: i64 = 0 342 if rcaa == CPG_EXIT_REFUSED { if cpg_has("ALERT cell=a low=3 n=7 low_max=3 count=3" as *u8) == 1 { al_fired = 1 } } 343 let rcab: i64 = cpg_run(subject, conf, "alert" as *u8, prefix, "pulse1" as *u8, "b" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) 344 var al_good: i64 = 1 345 if rcab == CPG_EXIT_OK { if cpg_has("NO-ALERT cell=b low=0 n=6" as *u8) == 1 { al_good = 0 } } 346 gv_bite("neg-control-alert-fires-on-three-low-answers-silent-on-none" as *u8, al_fired, al_good, ctr) 347 let rcac: i64 = cpg_run(subject, conf, "alert" as *u8, prefix, "pulse1" as *u8, "c" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil()) 348 var t8c: i64 = 0 349 if rcac == CPG_EXIT_UNOBSERVABLE { if cpg_has("ALERT-UNOBSERVABLE cell=c n=2 k=5" as *u8) == 1 { t8c = 1 } } 350 gv_check("alert-under-the-floor-abstains-with-exit-3-and-publishes-no-count" as *u8, t8c, ctr) 351 352 // ---- T9: the signed open export. cp_open_export + cp_verify_export ---- 353 let rce: i64 = cpg_run(subject, conf, "export" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, export, cpg_nil(), cpg_nil(), cpg_nil()) 354 var t9: i64 = 0 355 if rce == CPG_EXIT_OK { if cpg_has("EXPORT path=" as *u8) == 1 { if cpg_has("rows=6 sha256=" as *u8) == 1 { t9 = 1 } } } 356 gv_check("export-written-with-pin-and-public-key" as *u8, t9, ctr) 357 var t9r: i64 = 0 358 if cpg_file_has(export, "row|c|nonprofit|l1|WITHHELD-UNDER-K|total=-|mean_pm=-|margin_pm=-" as *u8) == 1 { if cpg_file_has(export, "row|a|church|l1|PUBLISHED|total=7|mean_pm=6285|" as *u8) == 1 { t9r = 1 } } 359 gv_check("export-rows-carry-numbers-only-for-published-cells" as *u8, t9r, ctr) 360 let rcv: i64 = cpg_run(subject, conf, "verify" as *u8, export, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 361 var ver_good: i64 = 1 362 if rcv == CPG_EXIT_OK { if cpg_has("VERIFIED path=" as *u8) == 1 { ver_good = 0 } } 363 // tamper: flip the first byte of the body (N -> M) and keep the pin and signature 364 let lp: *i64 = sys_mmap(CPG_LP_BYTES) as *i64 365 let eb: *u8 = sys_read_file(export, lp) 366 var tam_fired: i64 = 0 367 if (eb as i64) != 0 { 368 eb[0] = CPG_ASCII_M as u8 369 let fd: i64 = sys_openat_wr(tampered, MODE_0644) 370 if fd >= 0 { sys_write(fd, eb, lp[0]); sys_close(fd) } 371 let rct: i64 = cpg_run(subject, conf, "verify" as *u8, tampered, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 372 if rct == CPG_EXIT_REFUSED { if cpg_has("TAMPERED path=" as *u8) == 1 { if cpg_has("pin_ok=0 sig_ok=0" as *u8) == 1 { tam_fired = 1 } } } 373 } 374 gv_bite("neg-control-one-flipped-body-byte-reads-TAMPERED-on-both-pin-and-signature-untouched-export-VERIFIED" as *u8, tam_fired, ver_good, ctr) 375 let rcnk: i64 = cpg_run(subject, conf_nokey, "export" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, tampered, cpg_nil(), cpg_nil(), cpg_nil()) 376 var nk_fired: i64 = 0 377 if rcnk == CPG_EXIT_REFUSED { if cpg_has("REFUSED-NO-KEY" as *u8) == 1 { nk_fired = 1 } } 378 var nk_good: i64 = 0 379 if t9 == 0 { nk_good = 1 } 380 gv_bite("neg-control-export-without-a-key-row-refuses-never-writes-unsigned-keyed-export-written" as *u8, nk_fired, nk_good, ctr) 381 382 // ---- T10: the field gate abstains without real cells, judges with them. cp_field_gate ---- 383 let rcf0: i64 = cpg_run(subject, conf, "field" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 384 var t10: i64 = 0 385 if rcf0 == CPG_EXIT_UNOBSERVABLE { if cpg_has("FIELD-UNOBSERVABLE" as *u8) == 1 { t10 = 1 } } 386 gv_check("field-gate-with-no-field_cells-row-abstains-exit-3-never-acquits" as *u8, t10, ctr) 387 let rcf1: i64 = cpg_run(subject, conf_field_ok, "field" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 388 var f_good: i64 = 1 389 if rcf1 == CPG_EXIT_OK { if cpg_has("FIELD-OK cells=2" as *u8) == 1 { f_good = 0 } } 390 let rcf2: i64 = cpg_run(subject, conf_field_bad, "field" as *u8, prefix, "pulse1" as *u8, "p01" as *u8, cpg_nil(), cpg_nil(), cpg_nil(), cpg_nil()) 391 var f_fired: i64 = 0 392 if rcf2 == CPG_EXIT_REFUSED { if cpg_has("field cell=c own=2 k=5 UNDER-FLOOR" as *u8) == 1 { f_fired = 1 } } 393 gv_bite("neg-control-field-gate-fails-when-a-named-cell-is-under-the-floor-passes-when-both-clear-it" as *u8, f_fired, f_good, ctr) 394 395 return gv_verdict("communitypulse" as *u8, ctr, "every release state witnessed on one forest, complementary suppression bite-proven, export tamper bite-proven, thresholds read from a conf" as *u8) 396}