code wiki / (root) / nx_supp_ingredient_test.nx

nx_supp_ingredient_test.nx source

↩ module page · 168 lines · 8032 B

1// nx_supp_ingredient_test.nx -- the gate this catalog never had. 2// 3// FOUND BY nx_gatescan, AND THE TOOL UNDERSTATED IT IN ONE WAY AND 4// OVERSTATED IT IN ANOTHER, which is worth recording precisely. 5// 6// The scan reported nx_supp_ingredient as UNGATED-LOAD-BEARING with 6 7// consumers. Reading it showed the picture is more specific: a sibling's 8// gate (nx_supp_formula_test) does import this file and exercises FOUR of 9// its twelve functions -- so "ungated" was too strong, because name-based 10// attribution cannot see a shared gate. 11// 12// But the four it exercises are si_name, si_density_mg_per_ml, 13// si_capsule_fill_mg and si_cost_is_indicative -- the packaging and cost 14// helpers. ★THE FUNCTIONS THAT DECIDE WHETHER A SUBSTANCE MAY LAWFULLY BE 15// SOLD AT ALL -- si_class and si_is_lawful_dietary -- WERE EXERCISED BY 16// NOTHING. Wave 5 of this lane called that legal gate "the product 17// decision". The most consequential logic in the file was the least 18// checked, which is the general shape of this defect class: coverage 19// accumulates around whatever a sibling happened to need. 20// 21// So this gate deliberately does NOT re-test the four already covered. It 22// tests the eight that nothing was checking, starting with the legal ones. 23// expect_exit: 0 license_tier: ORIGINAL 24import "nx_syscalls.nx" 25import "nx_supp_ingredient.nx" 26 27func tw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 28func tn(v: i64) -> i64 { let b: *u8 = sys_mmap(24); var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } let t: *u8 = sys_mmap(24); 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 { b[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, b, k); return 0 } 29 30func main() -> i64 { 31 var pass: i64 = 0 32 var total: i64 = 0 33 34 // --- T1 ***THE PRODUCT DECISION, AND IT MUST DISCRIMINATE.*** An 35 // approved drug is precluded from the supplement route by 36 // 21 USC 321(ff)(3)(B); a synthetic signalling peptide is not a 37 // dietary ingredient under DSHEA's closed list at all. These are 38 // different refusals for different reasons and the catalog must 39 // not collapse them -- a blanket "no" would be right by accident 40 // and would mislead anyone asking why. --- 41 total = total + 1 42 var ok1: i64 = 1 43 if si_class(SI_OXYTOCIN) != SI_CLASS_DRUG { ok1 = 0 } 44 if si_class(SI_BREMELANOTIDE) != SI_CLASS_DRUG { ok1 = 0 } 45 if si_class(SI_KISSPEPTIN10) != SI_CLASS_NOT_DIETARY { ok1 = 0 } 46 if si_class(SI_BPC157) != SI_CLASS_NOT_DIETARY { ok1 = 0 } 47 tw("T1 drug-precluded (oxytocin, bremelanotide) vs not-a-dietary-ingredient (kisspeptin-10, BPC-157), kept DISTINCT: " as *u8) 48 if ok1 == 1 { pass = pass + 1; tw("PASS\n" as *u8) } else { tw("FAIL\n" as *u8) } 49 50 // --- T2 NON-VACUITY. If si_class refused everything the catalog would 51 // be useless and T1 would still pass. The nine botanicals and 52 // amino acids ARE lawful and must classify as such. --- 53 total = total + 1 54 var ok2: i64 = 1 55 var i: i64 = 0 56 var lawful: i64 = 0 57 while i < SI_N { 58 if si_is_lawful_dietary(i) == 1 { lawful = lawful + 1 } 59 i = i + 1 60 } 61 if lawful != 9 { ok2 = 0 } 62 tw("T2 exactly " as *u8); tn(lawful) 63 tw(" of " as *u8); tn(SI_N) 64 tw(" catalogued substances are lawful dietary ingredients (want 9 -- refusal is specific, not blanket): " as *u8) 65 if ok2 == 1 { pass = pass + 1; tw("PASS\n" as *u8) } else { tw("FAIL\n" as *u8) } 66 67 // --- T3 THE TWO VIEWS AGREE. si_is_lawful_dietary must be exactly the 68 // ODI/NDI classes and nothing else, for every id -- checked 69 // across the whole catalog rather than at a sampled point, so a 70 // single mis-tagged row cannot slip through. --- 71 total = total + 1 72 var ok3: i64 = 1 73 var j: i64 = 0 74 while j < SI_N { 75 let c: i64 = si_class(j) 76 var expect: i64 = 0 77 if c == SI_CLASS_ODI { expect = 1 } 78 if c == SI_CLASS_NDI { expect = 1 } 79 if si_is_lawful_dietary(j) != expect { ok3 = 0 } 80 j = j + 1 81 } 82 tw("T3 si_is_lawful_dietary agrees with si_class on all " as *u8); tn(SI_N) 83 tw(" rows: " as *u8) 84 if ok3 == 1 { pass = pass + 1; tw("PASS\n" as *u8) } else { tw("FAIL\n" as *u8) } 85 86 // --- T4 ***FAIL-CLOSED, AND IT IS THE WHOLE SAFETY PROPERTY.*** An 87 // uncatalogued substance must read as UNKNOWN and NOT lawful. If 88 // an out-of-range id returned a lawful class, a formulation 89 // engine would happily build a product around a substance nobody 90 // has ever assessed. --- 91 total = total + 1 92 var ok4: i64 = 1 93 if si_valid_id(SI_N) != 0 { ok4 = 0 } 94 if si_valid_id(0 - 1) != 0 { ok4 = 0 } 95 if si_class(SI_N) != SI_CLASS_UNKNOWN { ok4 = 0 } 96 if si_class(0 - 1) != SI_CLASS_UNKNOWN { ok4 = 0 } 97 if si_is_lawful_dietary(SI_N) != 0 { ok4 = 0 } 98 if si_is_lawful_dietary(999) != 0 { ok4 = 0 } 99 tw("T4 an uncatalogued id is UNKNOWN and NOT lawful (never a default yes): " as *u8) 100 if ok4 == 1 { pass = pass + 1; tw("PASS\n" as *u8) } else { tw("FAIL\n" as *u8) } 101 102 // --- T5 Clinical doses are present and positive for every LAWFUL 103 // ingredient. A zero dose would silently produce a formulation 104 // containing none of an active while still reporting success. --- 105 total = total + 1 106 var ok5: i64 = 1 107 var k: i64 = 0 108 while k < SI_N { 109 if si_is_lawful_dietary(k) == 1 { 110 if si_clinical_dose_mg(k) <= 0 { ok5 = 0 } 111 if si_density_mg_per_ml(k) <= 0 { ok5 = 0 } 112 } 113 k = k + 1 114 } 115 tw("T5 every lawful ingredient has a positive clinical dose AND density: " as *u8) 116 if ok5 == 1 { pass = pass + 1; tw("PASS\n" as *u8) } else { tw("FAIL\n" as *u8) } 117 118 // --- T6 COSTS ARE FLAGGED INDICATIVE FOR EVERY ROW. This function 119 // exists so no downstream model can present a bulk range as a 120 // purchase price; if it were ever true for some rows and false 121 // for others, a consumer could reasonably read the false ones as 122 // quotes. It must be uniform. --- 123 total = total + 1 124 var ok6: i64 = 1 125 var m: i64 = 0 126 while m < SI_N { 127 if si_cost_is_indicative(m) != 1 { ok6 = 0 } 128 if si_is_lawful_dietary(m) == 1 { 129 if si_cost_cents_per_kg(m) <= 0 { ok6 = 0 } 130 } 131 m = m + 1 132 } 133 tw("T6 every row's cost is marked INDICATIVE, and lawful rows carry a positive cost: " as *u8) 134 if ok6 == 1 { pass = pass + 1; tw("PASS\n" as *u8) } else { tw("FAIL\n" as *u8) } 135 136 // --- T7 Names are present and distinct. A duplicated or empty name in 137 // a catalog keyed by integer id is how the wrong substance ends 138 // up in a formulation with everything else looking correct. --- 139 total = total + 1 140 var ok7: i64 = 1 141 var a: i64 = 0 142 while a < SI_N { 143 let na: *u8 = si_name(a) 144 if na[0] == (0 as u8) { ok7 = 0 } 145 var b: i64 = a + 1 146 while b < SI_N { 147 let nb: *u8 = si_name(b) 148 var same: i64 = 1 149 var q: i64 = 0 150 while q < 64 { 151 if same == 1 { 152 if na[q] != nb[q] { same = 0 } 153 if na[q] == (0 as u8) { q = 64 } 154 } 155 q = q + 1 156 } 157 if same == 1 { ok7 = 0 } 158 b = b + 1 159 } 160 a = a + 1 161 } 162 tw("T7 all " as *u8); tn(SI_N); tw(" catalog names are non-empty and pairwise distinct: " as *u8) 163 if ok7 == 1 { pass = pass + 1; tw("PASS\n" as *u8) } else { tw("FAIL\n" as *u8) } 164 165 tw("SUPP-INGREDIENT-GATE passed " as *u8); tn(pass); tw("/" as *u8); tn(total) 166 if pass == total { tw(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 167 tw(" verdict=RED\n" as *u8); sys_exit(1); return 1 168}