nx_dashboard_test.nx source
↩ module page · 58 lines · 2692 B
1// nx_dashboard_test.nx -- end-to-end dashboard render of a synthetic
2// 2-batch stream. Writes the rendered HTML to stdout (fd=1).
3
4import "nx_syscalls.nx"
5import "nx_runtime.nx"
6import "nx_tier.nx"
7import "nx_cbor.nx"
8import "nx_trace_emit.nx"
9import "nx_batch_audit_sidecar.nx"
10import "nx_dashboard.nx"
11
12func main() -> nx_int {
13 let buf: *u8 = (sys_mmap(2048)) as *u8
14
15 // ===== Batch 1 (trace=1000): 4 scenes, 1 violation, SEVERE outfit =
16 //
17 // BATCH_OPEN -> 4 OUTFIT_PICK -> BATCH_CLOSE rollup
18 let attrs0: *i64 = (sys_mmap(16)) as *i64
19 var p: nx_int = nx_cbor_emit_span(buf, 0, 1000, 1, 0 - 1,
20 NX_SPAN_BATCH_OPEN, 0, 1, attrs0, 0)
21
22 let attrs1: *i64 = (sys_mmap(96)) as *i64
23 attrs1[0] = NX_DASH_KEY_N_SCENES; attrs1[1] = 4
24 attrs1[2] = NX_DASH_KEY_N_VIOLATIONS; attrs1[3] = 1
25 attrs1[4] = NX_DASH_KEY_OUTFIT_BAND; attrs1[5] = NX_UTIL_SEVERE_BIAS
26 attrs1[6] = NX_DASH_KEY_OUTFIT_DISTINCT; attrs1[7] = 1
27 attrs1[8] = NX_DASH_KEY_POSE_BAND; attrs1[9] = NX_UTIL_SEVERE_BIAS
28 attrs1[10] = NX_DASH_KEY_POSE_DISTINCT; attrs1[11] = 1
29 p = nx_cbor_emit_span(buf, p, 1000, 2, 1,
30 NX_SPAN_BATCH_CLOSE, 0, 400, attrs1, 6)
31
32 // ===== Batch 2 (trace=1001): 10 scenes, 0 violations, UNIFORM ====
33 let attrs2: *i64 = (sys_mmap(96)) as *i64
34 attrs2[0] = NX_DASH_KEY_N_SCENES; attrs2[1] = 10
35 attrs2[2] = NX_DASH_KEY_N_VIOLATIONS; attrs2[3] = 0
36 attrs2[4] = NX_DASH_KEY_OUTFIT_BAND; attrs2[5] = NX_UTIL_UNIFORM
37 attrs2[6] = NX_DASH_KEY_OUTFIT_DISTINCT; attrs2[7] = 8
38 attrs2[8] = NX_DASH_KEY_POSE_BAND; attrs2[9] = NX_UTIL_MILD_BIAS
39 attrs2[10] = NX_DASH_KEY_POSE_DISTINCT; attrs2[11] = 5
40 p = nx_cbor_emit_span(buf, p, 1001, 3, 0 - 1,
41 NX_SPAN_BATCH_CLOSE, 500, 800, attrs2, 6)
42
43 // ===== Render =================================================
44 let n_rendered: nx_int = nx_dashboard_render(1,
45 "Substrate batch audit -- 2 traces" as *u8,
46 buf, p, 16)
47
48 // Should have rendered exactly 2 BATCH_CLOSE summaries
49 if n_rendered != 2 { return 1 }
50
51 // Confirm util-band -> badge-kind mapping
52 if _dash_util_badge_kind(NX_UTIL_UNIFORM) != NX_HTML_BADGE_GOOD { return 2 }
53 if _dash_util_badge_kind(NX_UTIL_MILD_BIAS) != NX_HTML_BADGE_DRIFT { return 3 }
54 if _dash_util_badge_kind(NX_UTIL_SEVERE_BIAS) != NX_HTML_BADGE_BROKEN { return 4 }
55 if _dash_util_badge_kind(NX_UTIL_EMPTY) != NX_HTML_BADGE_NEUTRAL { return 5 }
56
57 return 0
58}