code wiki / (root) / nx_prodready_test.nx

nx_prodready_test.nx source

↩ module page · 215 lines · 10572 B

1// nx_prodready_test.nx -- gate for the production-readiness engine. Walks the 2// real libido stack from "no product" to "production ready", proving the plan 3// surfaces the RIGHT next gap at each step in kill order -- the whole point of 4// the engine. 5// expect_exit: 0 license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_supp_ingredient.nx" 8import "nx_supp_formula.nx" 9import "nx_supp_jurisdiction.nx" 10import "nx_prodready.nx" 11 12func t_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 13func t_putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } let t: *u8 = sys_mmap(28); 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 } var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 } 14 15// A powder product carrying the two OTC-friendly actives, all attestations 16// done -- the "ready" reference to walk backwards from. 17func ready_product() -> *NxProduct { 18 let p: *NxProduct = nx_product_new() 19 p.market = SJ_US 20 pr_add_ingredient(p, SI_PYCNOGENOL) 21 pr_add_ingredient(p, SI_PANAX_GINSENG) 22 p.format = SF_FORMAT_POWDER 23 p.retail_cents = 3999 24 p.target_margin_permil = 700 25 p.servings = 30 26 p.identity_ready = 1 27 p.gmp_qualified = 1 28 p.claims_reviewed = 1 29 p.coa_on_file = 1 30 return p 31} 32 33func main() -> i64 { 34 var pass: i64 = 0 35 var total: i64 = 0 36 37 // --- T1 a fully-prepared product is production ready (gap = READY) --- 38 total = total + 1 39 let rp: *NxProduct = ready_product() 40 let gap: i64 = pr_first_gap(rp) 41 let ready: i64 = pr_is_production_ready(rp) 42 let score: i64 = pr_readiness_permil(rp) 43 t_puts("T1 prepared product: first_gap=" as *u8); t_putn(gap); t_puts(" ready=" as *u8); t_putn(ready); t_puts(" score=" as *u8); t_putn(score); t_puts(" permil want -1/1/1000: " as *u8) 44 var ok1: i64 = 1 45 if gap != PR_READY { ok1 = 0 } 46 if ready != 1 { ok1 = 0 } 47 if score != 1000 { ok1 = 0 } 48 if ok1 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 49 50 // --- T2 LEGAL is the FIRST gap and OVERRIDES everything downstream --- 51 // Add oxytocin (a drug): even with every attestation done, the product is 52 // blocked at dimension 0, not somewhere later. 53 total = total + 1 54 let bad: *NxProduct = ready_product() 55 pr_add_ingredient(bad, SI_OXYTOCIN) 56 let g2: i64 = pr_first_gap(bad) 57 let unlawful: i64 = pr_first_unlawful(bad) 58 t_puts("T2 + oxytocin: first_gap=" as *u8); t_putn(g2); t_puts(" (LEGAL=0) first_unlawful_id=" as *u8); t_putn(unlawful); t_puts(" want 0/10: " as *u8) 59 var ok2: i64 = 1 60 if g2 != PR_LEGAL { ok2 = 0 } 61 if unlawful != SI_OXYTOCIN { ok2 = 0 } 62 if ok2 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 63 64 // --- T3 KILL ORDER: a legal-but-oversized capsule product blocks at 65 // FORMAT, not at the (also-open) later attestations --- 66 total = total + 1 67 let fat: *NxProduct = nx_product_new() 68 fat.market = SJ_US 69 pr_add_ingredient(fat, SI_L_CITRULLINE) 70 pr_add_ingredient(fat, SI_MACA) 71 pr_add_ingredient(fat, SI_ASHWAGANDHA) 72 fat.format = SF_FORMAT_CAPSULE 73 fat.max_units = 2 74 fat.retail_cents = 3999 75 let g3: i64 = pr_first_gap(fat) 76 let legal3: i64 = pr_legal_ok(fat) 77 let format3: i64 = pr_format_ok(fat) 78 t_puts("T3 3-heavy-ingredient capsule: legal=" as *u8); t_putn(legal3); t_puts(" format_ok=" as *u8); t_putn(format3); t_puts(" first_gap=" as *u8); t_putn(g3); t_puts(" want 1/0/1(FORMAT): " as *u8) 79 var ok3: i64 = 1 80 if legal3 != 1 { ok3 = 0 } 81 if format3 != 0 { ok3 = 0 } 82 if g3 != PR_FORMAT { ok3 = 0 } 83 if ok3 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 84 85 // --- T4 switching that same product to POWDER clears FORMAT and the 86 // gap MOVES DOWNSTREAM (to the first open attestation) --- 87 total = total + 1 88 fat.format = SF_FORMAT_POWDER 89 let g4: i64 = pr_first_gap(fat) 90 t_puts("T4 same product as POWDER: first_gap=" as *u8); t_putn(g4); t_puts(" (now IDENTITY=3, format cleared): " as *u8) 91 if g4 == PR_IDENTITY { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 92 93 // --- T5 ECONOMICS gap: a price too low blocks at dimension 2 --- 94 total = total + 1 95 let cheap: *NxProduct = ready_product() 96 cheap.retail_cents = 300 97 let g5: i64 = pr_first_gap(cheap) 98 let econ5: i64 = pr_economics_ok(cheap) 99 t_puts("T5 $3.00 retail: economics_ok=" as *u8); t_putn(econ5); t_puts(" first_gap=" as *u8); t_putn(g5); t_puts(" want 0/2(ECONOMICS): " as *u8) 100 if econ5 == 0 { if g5 == PR_ECONOMICS { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) } 101 102 // --- T6 the ATTESTATION ladder: each open flag surfaces in order --- 103 total = total + 1 104 let att: *NxProduct = ready_product() 105 att.identity_ready = 0 106 att.gmp_qualified = 0 107 att.claims_reviewed = 0 108 att.coa_on_file = 0 109 let ga: i64 = pr_first_gap(att) 110 att.identity_ready = 1 111 let gb: i64 = pr_first_gap(att) 112 att.gmp_qualified = 1 113 let gc: i64 = pr_first_gap(att) 114 att.claims_reviewed = 1 115 let gd: i64 = pr_first_gap(att) 116 att.coa_on_file = 1 117 let ge: i64 = pr_first_gap(att) 118 t_puts("T6 attestation ladder = " as *u8); t_putn(ga); t_puts("/" as *u8); t_putn(gb); t_puts("/" as *u8); t_putn(gc); t_puts("/" as *u8); t_putn(gd); t_puts("/" as *u8); t_putn(ge); t_puts(" want 3/4/5/6/-1: " as *u8) 119 var ok6: i64 = 1 120 if ga != PR_IDENTITY { ok6 = 0 } 121 if gb != PR_MANUFACTURING { ok6 = 0 } 122 if gc != PR_CLAIMS { ok6 = 0 } 123 if gd != PR_COA { ok6 = 0 } 124 if ge != PR_READY { ok6 = 0 } 125 if ok6 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 126 127 // --- T7 readiness score tracks dimensions passed --- 128 total = total + 1 129 let half: *NxProduct = ready_product() 130 half.identity_ready = 0 131 half.gmp_qualified = 0 132 let s7: i64 = pr_readiness_permil(half) 133 let passed7: i64 = pr_dims_passed(half) 134 t_puts("T7 two attestations open: dims_passed=" as *u8); t_putn(passed7); t_puts("/7 score=" as *u8); t_putn(s7); t_puts(" permil (5/7=714): " as *u8) 135 var ok7: i64 = 1 136 if passed7 != 5 { ok7 = 0 } 137 if s7 != 714 { ok7 = 0 } 138 if ok7 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 139 140 // --- T8 computed-blocker vs attestation split: is the CONCEPT broken or 141 // just the paperwork? --- 142 total = total + 1 143 let concept_broken: *NxProduct = ready_product() 144 pr_add_ingredient(concept_broken, SI_KISSPEPTIN10) // not a dietary ingredient 145 let cb: i64 = pr_open_computed_blockers(concept_broken) 146 let ca: i64 = pr_open_attestations(concept_broken) 147 let paperwork: *NxProduct = ready_product() 148 paperwork.coa_on_file = 0 149 let pcb: i64 = pr_open_computed_blockers(paperwork) 150 let pca: i64 = pr_open_attestations(paperwork) 151 t_puts("T8 concept-broken: computed=" as *u8); t_putn(cb); t_puts(" attest=" as *u8); t_putn(ca); t_puts(" ; paperwork-only: computed=" as *u8); t_putn(pcb); t_puts(" attest=" as *u8); t_putn(pca); t_puts(": " as *u8) 152 var ok8: i64 = 1 153 if cb < 1 { ok8 = 0 } 154 if pcb != 0 { ok8 = 0 } 155 if pca != 1 { ok8 = 0 } 156 if ok8 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 157 158 // --- T9 the plan lines exist for every dimension (no blank actions) --- 159 total = total + 1 160 var d9: i64 = 0 161 var ok9: i64 = 1 162 while d9 < PR_N_DIM { 163 let a: *u8 = pr_action(d9) 164 let nm: *u8 = pr_dim_name(d9) 165 if a[0] == (0 as u8) { ok9 = 0 } 166 if nm[0] == (0 as u8) { ok9 = 0 } 167 d9 = d9 + 1 168 } 169 t_puts("T9 every dimension has a name + a next-action plan line: " as *u8) 170 if ok9 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 171 172 // --- T10 bitmask round-trips: what went in is what is present --- 173 total = total + 1 174 let bm: *NxProduct = nx_product_new() 175 pr_add_ingredient(bm, SI_PYCNOGENOL) 176 pr_add_ingredient(bm, SI_GINKGO) 177 let has_pyc: i64 = pr_has_ingredient(bm, SI_PYCNOGENOL) 178 let has_gko: i64 = pr_has_ingredient(bm, SI_GINKGO) 179 let has_maca: i64 = pr_has_ingredient(bm, SI_MACA) 180 let bad_add: i64 = pr_add_ingredient(bm, 99) 181 t_puts("T10 mask: pycnogenol=" as *u8); t_putn(has_pyc); t_puts(" ginkgo=" as *u8); t_putn(has_gko); t_puts(" maca(absent)=" as *u8); t_putn(has_maca); t_puts(" bad-id-rejected=" as *u8); t_putn(bad_add); t_puts(": " as *u8) 182 var ok10: i64 = 1 183 if has_pyc != 1 { ok10 = 0 } 184 if has_gko != 1 { ok10 = 0 } 185 if has_maca != 0 { ok10 = 0 } 186 if bad_add != 0 { ok10 = 0 } 187 if ok10 == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } 188 189 // --- T11 an empty product is NOT ready (nothing to sell) --- 190 total = total + 1 191 let empty: *NxProduct = nx_product_new() 192 empty.retail_cents = 3999 193 empty.identity_ready = 1 194 empty.gmp_qualified = 1 195 empty.claims_reviewed = 1 196 empty.coa_on_file = 1 197 let eready: i64 = pr_is_production_ready(empty) 198 let elegal: i64 = pr_legal_ok(empty) 199 t_puts("T11 empty product: legal=" as *u8); t_putn(elegal); t_puts(" ready=" as *u8); t_putn(eready); t_puts(" want 0/0: " as *u8) 200 if elegal == 0 { if eready == 0 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) } 201 202 // --- T12 BELARUS/EAEU market: the same lawful stack is sellable but the 203 // concept is not blocked at LEGAL (premarket is a later concern) --- 204 total = total + 1 205 let eaeu: *NxProduct = ready_product() 206 eaeu.market = SJ_EAEU 207 let g12: i64 = pr_legal_ok(eaeu) 208 let us_legal: i64 = pr_legal_ok(ready_product()) 209 t_puts("T12 EAEU legal=" as *u8); t_putn(g12); t_puts(" US legal=" as *u8); t_putn(us_legal); t_puts(" (both lawful, botanicals sell in both): " as *u8) 210 if g12 == 1 { if us_legal == 1 { pass = pass + 1; t_puts("PASS\n" as *u8) } else { t_puts("FAIL\n" as *u8) } } else { t_puts("FAIL\n" as *u8) } 211 212 t_puts("PRODREADY-GATE passed " as *u8); t_putn(pass); t_puts("/" as *u8); t_putn(total) 213 if pass == total { t_puts(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 214 t_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1 215}