code wiki / (root) / nx_ferment_process_test.nx

nx_ferment_process_test.nx source

↩ module page · 71 lines · 2796 B

1// nx_ferment_process_test.nx -- smoke for nx_ferment_process (R2). 2// 3// Proves the ferment state machine: 4// - the yogurt sequence runs to COMPLETE through all 5 phases (2-3) 5// - a STALLED ferment (pH never declines) HALTS the whole process via 6// the R0 never-poison law, recording the refusal verdict (4-5) 7// Exit code = failed assertion number; 0 = all pass. 8 9import "nx_syscalls.nx" 10import "nx_ferment_safety.nx" 11import "nx_ferment_process.nx" 12 13func main() -> i64 { 14 let env: *NxFermentSafetyEnvelope = nx_ferment_safety_envelope_default(1) 15 let phases: *NxFermentPhase = nx_ferment_phases_new(5) 16 nx_ferment_build_yogurt(phases) 17 18 // ---- HAPPY PATH: a normally-souring yogurt batch ---- 19 let pr: *NxFermentProcess = nx_ferment_process_new(env, phases, 5, NX_FK_DAIRY_CULTURED) 20 if nx_ferment_process_target(pr) != 82000 { return 1 } // starts at pasteurize 21 22 let log: *NxFermentReadingLog = nx_ferment_reading_log_new(64) 23 var temp: i64 = 20000 24 var ph: i64 = 6500 25 var now: i64 = 1 26 var status: nx_int = 0 27 var guard: i64 = 0 28 while guard < 600 { 29 if status == NX_PR_RUNNING { 30 let tgt: i64 = nx_ferment_process_target(pr) 31 if temp < tgt { temp = temp + 3000 32 if temp > tgt { temp = tgt } } 33 if temp > tgt { temp = temp - 3000 34 if temp < tgt { temp = tgt } } 35 if nx_ferment_process_current_is_ferment(pr) == 1 { 36 if ph > 4000 { ph = ph - 300 } // culture sours it 37 } 38 status = nx_ferment_process_step(pr, temp, ph, 0, 0, now, log) 39 now = now + 1 40 } 41 guard = guard + 1 42 } 43 if status != NX_PR_COMPLETE { return 2 } 44 if pr.current != 5 { return 3 } 45 46 // ---- UNSAFE PATH: a STALLED batch (pH stuck high) ---- 47 let pr2: *NxFermentProcess = nx_ferment_process_new(env, phases, 5, NX_FK_DAIRY_CULTURED) 48 let log2: *NxFermentReadingLog = nx_ferment_reading_log_new(64) 49 var temp2: i64 = 20000 50 var ph2: i64 = 6500 51 var now2: i64 = 1 52 var status2: nx_int = 0 53 var guard2: i64 = 0 54 while guard2 < 600 { 55 if status2 == NX_PR_RUNNING { 56 let tgt2: i64 = nx_ferment_process_target(pr2) 57 if temp2 < tgt2 { temp2 = temp2 + 3000 58 if temp2 > tgt2 { temp2 = tgt2 } } 59 if temp2 > tgt2 { temp2 = temp2 - 3000 60 if temp2 < tgt2 { temp2 = tgt2 } } 61 // STALLED: pH never declines, even in the ferment hold 62 status2 = nx_ferment_process_step(pr2, temp2, ph2, 0, 0, now2, log2) 63 now2 = now2 + 1 64 } 65 guard2 = guard2 + 1 66 } 67 if status2 != NX_PR_HALTED_UNSAFE { return 4 } 68 if pr2.last_verdict != NX_FS_REFUSED_PATHOGEN_PATTERN { return 5 } 69 70 return 0 71}