code wiki / _hdl_build / nx_health_template_gate.nx
nx_health_template_gate.nx source
↩ module page · 72 lines · 4417 B
1// nx_health_template_gate.nx -- PURE gate for the content-aware health verdict. The load-bearing test (T1) is
2// the OPERATOR'S EXACT CASE: the real sites.elf 404 body served WITH a 200 status -> must verdict DOWN
3// (HT_ERROR_CONTENT), proving "a 404 being up with a 200 status is wrong" is caught. Plus: a known-good page is
4// OK, a real non-200 is WRONG_STATUS, and a 200 missing its template marker is MISSING_TEMPLATE. GREEN iff T1..T8.
5// Sovereign: nx_health_template + nx_syscalls. license_tier: ORIGINAL
6import "nx_health_template.nx"
7import "nx_syscalls.nx"
8
9func g_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
10func g_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
11func g_row(name: *u8, ok: i64) -> i64 {
12 if ok == 1 { g_w(" PASS " as *u8) } else { g_w(" FAIL " as *u8) }
13 g_w(name); g_w("\n" as *u8)
14 return ok
15}
16func g_eq(name: *u8, got: i64, want: i64) -> i64 { var ok: i64 = 0; if got == want { ok = 1 } return g_row(name, ok) }
17
18func main() -> i64 {
19 g_w("health-template gate (content-aware: a 200 with 404/error content is DOWN, not 'up')\n" as *u8)
20 var pass: i64 = 0
21 let total: i64 = 8
22
23 // The REAL sites.elf 404 page (what nishifamily.com/gallery returned), and a known-good gallery login page.
24 let body404: *u8 = "<!doctype html><meta charset=utf-8><title>404</title><h1>404 — not found</h1>" as *u8
25 let n404: i64 = g_len(body404)
26 let goodgal: *u8 = "<!doctype html><title>Nishi Gallery — private</title><h1>Nishi Gallery</h1><p>Log in to view the gallery.</p>" as *u8
27 let ng: i64 = g_len(goodgal)
28 let blank: *u8 = "<html><body>placeholder</body></html>" as *u8
29 let nb: i64 = g_len(blank)
30 let err500: *u8 = "<html><h1>Internal Server Error</h1></html>" as *u8
31 let n500: i64 = g_len(err500)
32 let gal_marker: *u8 = "Nishi Gallery" as *u8
33 let gm: i64 = 13
34
35 // ---- T1 ★ THE OPERATOR'S CASE: 200 status + 404 BODY -> HT_ERROR_CONTENT (DOWN, not up) ----
36 pass = pass + g_eq("T1 [200 status + 404 body] -> HT_ERROR_CONTENT (the false-green CAUGHT)\x00" as *u8, htpl_verdict(body404, n404, 200, gal_marker, gm), HT_ERROR_CONTENT)
37
38 // ---- T2 known-good gallery login page -> HT_OK ----
39 pass = pass + g_eq("T2 [200 + 'Nishi Gallery' marker, no error] -> HT_OK\x00" as *u8, htpl_verdict(goodgal, ng, 200, gal_marker, gm), HT_OK)
40
41 // ---- T3 real non-200 status -> HT_WRONG_STATUS ----
42 pass = pass + g_eq("T3 [status 404] -> HT_WRONG_STATUS\x00" as *u8, htpl_verdict(goodgal, ng, 404, gal_marker, gm), HT_WRONG_STATUS)
43
44 // ---- T4 200 + wrong/blank page (no marker, no error fingerprint) -> HT_MISSING_TEMPLATE ----
45 pass = pass + g_eq("T4 [200 + placeholder, missing the known-good marker] -> HT_MISSING_TEMPLATE\x00" as *u8, htpl_verdict(blank, nb, 200, gal_marker, gm), HT_MISSING_TEMPLATE)
46
47 // ---- T5 200 + 500-error body -> HT_ERROR_CONTENT (generic error page caught too) ----
48 pass = pass + g_eq("T5 [200 + 'Internal Server Error' body] -> HT_ERROR_CONTENT\x00" as *u8, htpl_verdict(err500, n500, 200, gal_marker, gm), HT_ERROR_CONTENT)
49
50 // ---- T6 htpl_healthy: good -> 1 ----
51 pass = pass + g_eq("T6 htpl_healthy(good page) -> 1\x00" as *u8, htpl_healthy(goodgal, ng, 200, gal_marker, gm), 1)
52
53 // ---- T7 htpl_healthy: the operator's 200+404 -> 0 (NOT healthy) ----
54 pass = pass + g_eq("T7 htpl_healthy(200 + 404 body) -> 0 (NOT up)\x00" as *u8, htpl_healthy(body404, n404, 200, gal_marker, gm), 0)
55
56 // ---- T8 the OLD naive check would PASS this (200 + non-empty) -> proves content-check is the fix ----
57 var old_naive: i64 = 0
58 if n404 > 0 { old_naive = 1 }
59 var t8: i64 = 0
60 if old_naive == 1 { if htpl_healthy(body404, n404, 200, gal_marker, gm) == 0 { t8 = 1 } }
61 pass = pass + g_row("T8 OLD '200+non-empty' = healthy(WRONG); content-check = DOWN (the fix, demonstrated)\x00" as *u8, t8)
62
63 if pass == total {
64 let lg: i64 = sys_openat_append("knowledge/status/health_template_gate.log" as *u8, 0x1a4)
65 if lg >= 0 { sys_write(lg, "HEALTH-TEMPLATE-GATE pass=8/8 verdict=GREEN\n" as *u8, 43); sys_close(lg) }
66 g_w("HEALTH-TEMPLATE GATE GREEN 8/8 (200-with-error-content CAUGHT; known-good-template required)\n" as *u8)
67 sys_exit(0)
68 }
69 g_w("HEALTH-TEMPLATE GATE RED\n" as *u8)
70 sys_exit(1)
71 return 1
72}