code wiki / (root) / nx_health_check_test.nx

nx_health_check_test.nx source

↩ module page · 62 lines · 2602 B

1// nx_health_check_test.nx -- smoke for nx_health_check. 2 3import "nx_syscalls.nx" 4import "nx_audit_dashboard.nx" 5import "nx_health_check.nx" 6 7func main() -> i64 { 8 if NX_HC_N_VERDICTS != 3 { return 1 } 9 if nx_hc_verdict_is_valid(NX_HC_GREEN) != 1 { return 2 } 10 if nx_hc_verdict_is_valid(3) != 0 { return 3 } 11 12 // Idle dashboard -> GREEN 13 let dash: *NxAuditDashboardSnapshot = nx_audit_dashboard_snapshot_new() 14 let st: *NxHealthState = nx_health_state_new() 15 if nx_health_check(st, dash, 1000) != NX_HC_GREEN { return 4 } 16 if st.last_verdict != NX_HC_GREEN { return 5 } 17 18 // Add 1 book alert (score=256, >= 200) and colony ALERTED -> YELLOW 19 nx_audit_dashboard_set_book_alerts(dash, 1) 20 nx_audit_dashboard_set_colony(dash, 1) // ALERTED 21 if nx_health_check(st, dash, 2000) != NX_HC_YELLOW { return 6 } 22 if st.last_verdict != NX_HC_YELLOW { return 7 } 23 24 // just_transitioned_to YELLOW -> 1 (we transitioned from GREEN) 25 if nx_health_just_transitioned_to(st, NX_HC_YELLOW) != 1 { return 8 } 26 27 // Escalate: colony RESPONDING -> RED 28 nx_audit_dashboard_set_colony(dash, 2) // RESPONDING 29 if nx_health_check(st, dash, 3000) != NX_HC_RED { return 9 } 30 if st.consecutive_red != 1 { return 10 } 31 32 // Recovery trigger: just transitioned in (consecutive_red=1 + transition>0) 33 if nx_health_should_trigger_recovery(st) != 1 { return 11 } 34 35 // Stay RED -> consecutive_red=2; still trigger 36 nx_health_check(st, dash, 4000) 37 if st.consecutive_red != 2 { return 12 } 38 if nx_health_should_trigger_recovery(st) != 1 { return 13 } 39 40 // Recover: colony back to HEALTHY + clear alerts 41 nx_audit_dashboard_set_colony(dash, 0) 42 nx_audit_dashboard_set_book_alerts(dash, 0) 43 if nx_health_check(st, dash, 5000) != NX_HC_GREEN { return 14 } 44 if st.consecutive_red != 0 { return 15 } // reset on non-RED 45 if nx_health_should_trigger_recovery(st) != 0 { return 16 } 46 47 // Last verdict + consecutive_red getters 48 if nx_health_last_verdict(st) != NX_HC_GREEN { return 17 } 49 if nx_health_consecutive_red(st) != 0 { return 18 } 50 51 // Score-based RED path -- need score > 768. 52 // book(256) + scam(256) + treaty(128) + twin_key(128) + ram(64) + vram(64) = 896 53 nx_audit_dashboard_set_pressure(dash, 950, 950) 54 nx_audit_dashboard_set_book_alerts(dash, 3) 55 nx_audit_dashboard_set_scam(dash, 1) 56 nx_audit_dashboard_set_treaty_breaches(dash, 1) 57 nx_audit_dashboard_set_twin_key_pending(dash, 1) 58 let v: nx_int = nx_health_check(st, dash, 6000) 59 if v != NX_HC_RED { return 19 } 60 61 return 0 62}