nx_maint_render_test.nx source
↩ module page · 69 lines · 3882 B
1// nx_maint_render_test.nx -- gate for R6 (the fronts).
2//
3// Renders real plans (R5) into DIY + ENTERPRISE cards, proves the labels
4// surface, the SAFETY card screams shut-down, valid HTML, and the FAIL-CLOSED
5// privacy guarantee (a clean card passes; a buffer with a <script> or an http
6// load is REFUSED).
7//
8// expect_exit: 0
9//
10// license_tier: ORIGINAL
11
12import "nx_syscalls_x86_64.nx"
13import "nx_maint_render.nx"
14
15func main() -> i64 {
16 let buf: *u8 = sys_mmap(4096)
17 let plan: *ActionPlan = sys_mmap(64) as *ActionPlan
18
19 // ===== DIY card: thermal DEGRADED_CAPACITY -> fix-yourself ======
20 nx_plan_for(NX_MK_THERMAL, NX_HVAC_DEGRADED_CAPACITY, NX_TREND_STABLE, plan)
21 let sev1: i64 = nx_maint_severity(NX_MK_THERMAL, NX_HVAC_DEGRADED_CAPACITY)
22 let len1: i64 = nx_maint_render_card(buf, 4096, "Furnace" as *u8, sev1, plan.cause, plan.action, plan.diy, plan.urgency, NX_RENDER_DIY)
23 if len1 <= 0 { return 10 }
24 if nx_maint_render_is_clean(buf, len1) != 1 { return 11 } // 0 script, 0 http
25 if mr_contains(buf, len1, "<!doctype html" as *u8) != 1 { return 12 }
26 if mr_contains(buf, len1, "</html>" as *u8) != 1 { return 13 }
27 if mr_contains(buf, len1, "Furnace" as *u8) != 1 { return 14 }
28 if mr_contains(buf, len1, "Degraded" as *u8) != 1 { return 15 }
29 if mr_contains(buf, len1, "Dirty filter" as *u8) != 1 { return 16 }
30 if mr_contains(buf, len1, "Fix yourself" as *u8) != 1 { return 17 }
31 if mr_contains(buf, len1, "What to do" as *u8) != 1 { return 18 }
32 if mr_contains(buf, len1, "yourself." as *u8) != 1 { return 19 }
33
34 // ===== ENTERPRISE card: rot BEARING_WEAR -> dispatch a pro ======
35 nx_plan_for(NX_MK_ROTATING, NX_ROT_BEARING_WEAR, NX_TREND_STABLE, plan)
36 let sev2: i64 = nx_maint_severity(NX_MK_ROTATING, NX_ROT_BEARING_WEAR)
37 let len2: i64 = nx_maint_render_card(buf, 4096, "Pool Pump" as *u8, sev2, plan.cause, plan.action, plan.diy, plan.urgency, NX_RENDER_ENTERPRISE)
38 if len2 <= 0 { return 20 }
39 if nx_maint_render_is_clean(buf, len2) != 1 { return 21 }
40 if mr_contains(buf, len2, "Work order" as *u8) != 1 { return 22 }
41 if mr_contains(buf, len2, "Dispatch:" as *u8) != 1 { return 23 }
42 if mr_contains(buf, len2, "Replace component" as *u8) != 1 { return 24 }
43 if mr_contains(buf, len2, "Failing bearing" as *u8) != 1 { return 25 }
44 if mr_contains(buf, len2, "professional" as *u8) != 1 { return 26 }
45 if mr_contains(buf, len2, "Urgent" as *u8) != 1 { return 27 }
46
47 // ===== SAFETY card: elec OVERLOAD -> shut down ==================
48 nx_plan_for(NX_MK_ELECTRICAL, NX_ELEC_OVERLOAD, NX_TREND_STABLE, plan)
49 let sev3: i64 = nx_maint_severity(NX_MK_ELECTRICAL, NX_ELEC_OVERLOAD)
50 let len3: i64 = nx_maint_render_card(buf, 4096, "Kitchen Circuit" as *u8, sev3, plan.cause, plan.action, plan.diy, plan.urgency, NX_RENDER_DIY)
51 if len3 <= 0 { return 30 }
52 if nx_maint_render_is_clean(buf, len3) != 1 { return 31 }
53 if mr_contains(buf, len3, "SAFETY HAZARD" as *u8) != 1 { return 32 }
54 if mr_contains(buf, len3, "SHUT DOWN" as *u8) != 1 { return 33 }
55 if mr_contains(buf, len3, "professional" as *u8) != 1 { return 34 }
56
57 // ===== FAIL-CLOSED privacy guarantee (liar-kill) ===============
58 let bad: *u8 = sys_mmap(128)
59 let badlen: i64 = mr_cat(bad, 0, "<div><script>steal()</script></div>" as *u8)
60 if nx_maint_render_is_clean(bad, badlen) != 0 { return 40 } // script -> REFUSED
61 let bad2: *u8 = sys_mmap(128)
62 let bad2len: i64 = mr_cat(bad2, 0, "<img src=http://tracker.example/x>" as *u8)
63 if nx_maint_render_is_clean(bad2, bad2len) != 0 { return 41 } // http load -> REFUSED
64
65 // ===== cap too small -> loud -1 ================================
66 if nx_maint_render_card(buf, 100, "X" as *u8, NX_HEALTH_OK, NX_CAUSE_NONE, NX_ACT_NONE, 1, NX_HEALTH_OK, NX_RENDER_DIY) != (0 - 1) { return 50 }
67
68 return 0
69}