nx_audit_compose_test.nx source
↩ module page · 101 lines · 4705 B
1// nx_audit_compose_test.nx -- audit + dashboard + health + recovery.
2//
3// Simulates a busy session: hunt kills, gather yields, xenocell
4// evidence, twin-key approval, scam pattern flagged, treaty
5// breach. Dashboard aggregates. Book records ALERTs. Health-check
6// transitions GREEN → YELLOW → RED. Recovery procedure fires.
7// Session summary captures the whole arc.
8
9import "nx_syscalls.nx"
10import "nx_tier.nx"
11import "nx_book.nx"
12import "nx_audit_dashboard.nx"
13import "nx_health_check.nx"
14import "nx_recovery.nx"
15import "nx_session_summary.nx"
16
17func main() -> i64 {
18 // ===== Step 1: session begins =================================
19 let summary: *NxSessionSummary = nx_session_summary_new(1000)
20 let book: *NxBook = nx_book_new(32)
21 let dash: *NxAuditDashboardSnapshot = nx_audit_dashboard_snapshot_new()
22 let state: *NxHealthState = nx_health_state_new()
23 nx_audit_dashboard_set_capture_ts(dash, 1000)
24
25 // Initial health GREEN (idle)
26 if nx_health_check(state, dash, 1000) != NX_HC_GREEN { return 1 }
27
28 // ===== Step 2: a few kills + yields happen ====================
29 nx_audit_dashboard_set_hunt(dash, 1, 3) // 1 active, 3 kills
30 nx_audit_dashboard_set_gather(dash, 5, 600)
31 nx_book_record(book, 1, 2000, NX_BK_RECLAIM_APPLIED, NX_BS_NOTICE, 100, 0xa1)
32
33 // Still GREEN (no alerts)
34 if nx_health_check(state, dash, 2000) != NX_HC_GREEN { return 2 }
35
36 // ===== Step 3: xeno alert + book entry -> YELLOW ===============
37 nx_audit_dashboard_set_xeno(dash, 1)
38 nx_book_record(book, 2, 3000, NX_BK_XENO_ALERT, NX_BS_ALERT, 200, 0xb2)
39 nx_audit_dashboard_set_book_alerts(dash, nx_book_count_alerts_unseen(book))
40 nx_audit_dashboard_set_colony(dash, 1) // ALERTED
41
42 let v_yellow: nx_int = nx_health_check(state, dash, 3000)
43 if v_yellow != NX_HC_YELLOW { return 3 }
44 if nx_health_just_transitioned_to(state, NX_HC_YELLOW) != 1 { return 4 }
45
46 // ===== Step 4: scam + treaty breach + colony RESPONDING -> RED ==
47 nx_audit_dashboard_set_scam(dash, 1)
48 nx_audit_dashboard_set_treaty_breaches(dash, 1)
49 nx_book_record(book, 3, 4000, NX_BK_SCAM_FLAGGED, NX_BS_WARNING, 300, 0xc3)
50 nx_book_record(book, 4, 4100, NX_BK_TREATY_BREACHED, NX_BS_WARNING, 400, 0xd4)
51 nx_audit_dashboard_set_colony(dash, 2) // RESPONDING
52
53 let v_red: nx_int = nx_health_check(state, dash, 4000)
54 if v_red != NX_HC_RED { return 5 }
55 if state.consecutive_red != 1 { return 6 }
56 if nx_health_should_trigger_recovery(state) != 1 { return 7 }
57
58 // ===== Step 5: recovery executes ==============================
59 let r: *NxRecoverySession = nx_recovery_new(7777, 4500)
60 nx_book_record(book, 5, 4500, NX_BK_HEALTH_RED_TRIGGERED, NX_BS_ALERT,
61 r.session_id, 0xed1)
62 nx_recovery_run_full(r, 2, 1, 4, 5000)
63 if nx_recovery_is_complete(r) != 1 { return 8 }
64 if r.cells_lysed != 2 { return 9 }
65 if r.cells_promoted != 1 { return 10 }
66 if r.resources_composted != 4 { return 11 }
67
68 // ===== Step 6: recovery brings substrate back to GREEN =========
69 nx_audit_dashboard_set_colony(dash, 0) // HEALTHY
70 nx_audit_dashboard_set_scam(dash, 0)
71 nx_audit_dashboard_set_treaty_breaches(dash, 0)
72 // Family reviews the ALERT entries
73 nx_book_mark_seen(book, 2)
74 nx_book_mark_seen(book, 5)
75 nx_audit_dashboard_set_book_alerts(dash, nx_book_count_alerts_unseen(book))
76
77 let v_after: nx_int = nx_health_check(state, dash, 6000)
78 if v_after != NX_HC_GREEN { return 12 }
79 if state.consecutive_red != 0 { return 13 }
80
81 // ===== Step 7: finalize session summary =======================
82 nx_session_summary_set_hunt(summary, 3, 1)
83 nx_session_summary_set_gather(summary, 5, 600)
84 nx_session_summary_set_book(summary, nx_book_count(book) as i64,
85 nx_book_count_alerts_unseen(book))
86 // Hunt 3 + gather 5 in journal-like simulated count: ratio ~ 0.375 = q10 384
87 nx_session_summary_set_imbalance(summary, 384)
88 // any_compromised_alert=1 since we did transition to RED during session
89 nx_session_summary_finalize(summary, 7000, 1)
90 if nx_session_summary_verdict(summary) != NX_SV_COMPROMISED { return 14 }
91
92 // ===== Step 8: forensic asserts ===============================
93 if nx_book_count(book) != 5 { return 15 }
94 if nx_book_count_by_kind(book, NX_BK_XENO_ALERT) != 1 { return 16 }
95 if nx_book_count_by_kind(book, NX_BK_HEALTH_RED_TRIGGERED) != 1 { return 17 }
96 if nx_book_count_alerts_unseen(book) != 0 { return 18 } // family reviewed
97 if state.transition_count >= 2 { } else { return 19 } // multiple transitions
98 if nx_session_summary_duration_us(summary) != 6000 { return 20 }
99
100 return 0
101}