code wiki / (root) / nx_water_quality_test.nx

nx_water_quality_test.nx source

↩ module page · 98 lines · 5473 B

1// nx_water_quality_test.nx -- the water-quality GATE for nx_water_quality: TDS taste bands, the 2// composite taste score, health mineral thresholds, and the never-poison safety admission 3// (lead / arsenic / nitrate / PFAS / bacteria). 4// 5// MIGRATED OFF A HAND-ROLLED VERDICT 2026-08-14. This was a smoke test whose exit code was the 6// FAILED ASSERTION NUMBER: `return 11` meant the lead check failed. Two consequences, and both of 7// them are why /api/promote refused to ship it (D001): 8// 1. NOTHING COULD READ ITS OUTCOME. nx_gate_green judges a gate from the outside by its verdict 9// line, and there was none; no harness.jrnl frame was recorded either, so flake and erosion 10// were invisible for this gate specifically. 11// 2. IT STOPPED AT THE FIRST FAILURE. An early-returning assertion chain reports ONE defect per 12// run and hides every later one, so the true blast radius of a change is never visible. 13// It now inherits nx_gate_verdict: every tooth runs, declared == executed BY CONSTRUCTION (gv_ctr 14// owns both counters, so a tooth that silently stops running lowers BOTH numbers instead of 15// quietly reading green), and the exit code CARRIES the verdict. 16// 17// MIGRATED BY HAND, DELIBERATELY. The automated D001 candidate collapses N teeth into one boolean 18// (ctr[0]=green; ctr[1]=1) and reports `passed 1/1` -- a one-state judge cannot see a dropped 19// conjunct, which is the exact defect gv_ctr exists to prevent. 20// 21// NEGATIVE CONTROLS ARE NAMED. Six teeth carry a neg-control- prefix so the gate-law census can SEE 22// them: a control nobody can find is a control nobody maintains. They matter more than usual here -- 23// without them a wq_safety_admit that REFUSED EVERY SAMPLE would score full marks on the refusal 24// teeth, so the admit-a-good-sample tooth is the discrimination control that makes the rest mean 25// something. 26// license_tier: ORIGINAL expect_exit: 0 27 28import "nx_syscalls.nx" 29import "nx_gate_verdict.nx" 30import "nx_water_quality.nx" 31 32func main() -> i64 { 33 gv_head("nx_water_quality gate -- taste bands, mineral health, never-poison admission" as *u8) 34 let ctr: *i64 = gv_ctr() 35 36 // --- TDS palatability bands (WHO) --- 37 gv_check("tds-250-tastes-excellent" as *u8, wq_tds_taste_class(250) == WQ_EXCELLENT, ctr) 38 gv_check("tds-30-tastes-insipid" as *u8, wq_tds_taste_class(30) == WQ_INSIPID, ctr) 39 gv_check("tds-1000-tastes-poor" as *u8, wq_tds_taste_class(1000) == WQ_POOR, ctr) 40 gv_check("tds-1500-is-unacceptable" as *u8, wq_tds_taste_class(1500) == WQ_UNACCEPTABLE, ctr) 41 42 // --- composite taste score: an ideally-mineralized water scores 100 --- 43 let good: *NxWaterSample = nx_water_sample_new() 44 good.tds = 250 45 good.ca = 50 46 good.mg = 25 47 good.ph_x10 = 75 48 gv_check("ideally-mineralised-water-scores-100" as *u8, wq_taste_score(good) == 100, ctr) 49 50 // --- near-distilled water tastes flat: the score must DISCRIMINATE, not saturate at 100 --- 51 let flat: *NxWaterSample = nx_water_sample_new() 52 flat.tds = 2 53 flat.ph_x10 = 60 54 gv_check("neg-control-near-distilled-water-scores-flat-15" as *u8, wq_taste_score(flat) == 15, ctr) 55 56 // --- health: needs the WHO desirable minerals --- 57 gv_check("well-mineralised-water-is-healthful" as *u8, wq_is_healthful(good) == 1, ctr) 58 let poor_min: *NxWaterSample = nx_water_sample_new() 59 poor_min.tds = 250 60 poor_min.ca = 5 61 poor_min.mg = 5 62 poor_min.ph_x10 = 75 63 // POTABLE and HEALTHFUL are different questions and this pair is what proves the code knows it: 64 // the same sample must come back safe-to-drink AND not mineral-healthful. One tooth alone here 65 // would pass for an implementation that conflated the two. 66 gv_check("mineral-poor-water-is-still-potable" as *u8, wq_is_potable(poor_min) == 1, ctr) 67 gv_check("neg-control-mineral-poor-water-is-NOT-healthful" as *u8, wq_is_healthful(poor_min) == 0, ctr) 68 69 // --- NEVER-POISON safety admission --- 70 // THE DISCRIMINATION CONTROL. Every tooth below asserts a REFUSAL, and a wq_safety_admit that 71 // refused everything would pass all of them. This one asserts an ALLOW, so the refusals can only 72 // score if the function actually distinguishes. 73 gv_check("admits-a-clean-sample-the-positive-control" as *u8, wq_safety_admit(good) == WQ_SAFE, ctr) 74 75 let lead: *NxWaterSample = nx_water_sample_new() 76 lead.tds = 250 77 lead.lead_ppb = 20 78 gv_check("neg-control-refuses-lead-above-15ppb" as *u8, wq_safety_admit(lead) == WQ_REFUSED_LEAD, ctr) 79 80 let pfas: *NxWaterSample = nx_water_sample_new() 81 pfas.pfas_ppt = 5 82 gv_check("neg-control-refuses-pfas-above-4ppt-EPA-2024" as *u8, wq_safety_admit(pfas) == WQ_REFUSED_PFAS, ctr) 83 84 let bug: *NxWaterSample = nx_water_sample_new() 85 bug.bacteria = 1 86 gv_check("neg-control-refuses-any-bacteria" as *u8, wq_safety_admit(bug) == WQ_REFUSED_BACTERIA, ctr) 87 88 let ars: *NxWaterSample = nx_water_sample_new() 89 ars.arsenic_ppb = 15 90 gv_check("neg-control-refuses-arsenic-above-limit" as *u8, wq_safety_admit(ars) == WQ_REFUSED_ARSENIC, ctr) 91 92 let nit: *NxWaterSample = nx_water_sample_new() 93 nit.nitrate_mgl = 12 94 gv_check("neg-control-refuses-nitrate-above-limit" as *u8, wq_safety_admit(nit) == WQ_REFUSED_NITRATE, ctr) 95 96 return gv_verdict("nx_water_quality_test" as *u8, ctr, 97 "taste bands, taste-score discrimination, potable-vs-healthful separation, and never-poison admission with a positive control" as *u8) 98}