code wiki / _hdl_build / nx_http_health_gate.nx

nx_http_health_gate.nx source

↩ module page · 43 lines · 2887 B

1// nx_http_health_gate.nx -- proves the REAL health check rejects every false-green class that hid the outage: 2// a 500 (connection made, not a page), a connection failure (-3), an empty 200, and a 200 with WRONG content -- 3// each is UNHEALTHY, whereas the old port-bind/exit-0 proxies passed them. license_tier: ORIGINAL 4import "nx_http_health_lib.nx" 5 6func main() -> i64 { 7 var fails: i64 = 0 8 let b1: *u8 = "<html><body>welcome ok</body></html>" as *u8 9 let bn: i64 = dp_len(b1) 10 let empty: *u8 = "" as *u8 11 // T1 HEALTHY: 200 + real body + the expected token present 12 let h1: i64 = hh_healthy(200, bn, b1, bn, "welcome" as *u8) 13 let h1b: i64 = hh_healthy(200, bn, b1, bn, empty) // 200 + real body + EMPTY expect -> healthy (the live CLI case the first gate missed) 14 // T2 NEG: HTTP 500 -- connection MADE but it's an error page, not the site (the false-green class) 15 let h2: i64 = hh_healthy(500, 100, b1, bn, empty) 16 // T3 NEG: connection FAILED (status 0, body_bytes -3) -- the exact case from the live outage 17 let h3: i64 = hh_healthy(0, 0 - 3, empty, 0, empty) 18 // T4 NEG: 200 but EMPTY body -- bound + responding but serving nothing 19 let h4: i64 = hh_healthy(200, 0, empty, 0, empty) 20 // T5 NEG: 200 + body but WRONG content (expected token absent) -- wrong page served 21 let h5: i64 = hh_healthy(200, bn, b1, bn, "checkout-confirmed" as *u8) 22 dp_w(1, "health: healthy=" as *u8); dp_wn(1, h1); dp_w(1, " 500=" as *u8); dp_wn(1, h2); dp_w(1, " connfail=" as *u8); dp_wn(1, h3); dp_w(1, " empty=" as *u8); dp_wn(1, h4); dp_w(1, " wrongcontent=" as *u8); dp_wn(1, h5); dp_w(1, " (expect 1,0,0,0,0)\n" as *u8) 23 if h1 != 1 { fails = fails + 1 } 24 if h1b != 1 { fails = fails + 1 } 25 if h2 != 0 { fails = fails + 1 } 26 if h3 != 0 { fails = fails + 1 } 27 if h4 != 0 { fails = fails + 1 } 28 if h5 != 0 { fails = fails + 1 } 29 // parse: status / body_bytes (incl signed -3) 30 let s1: *u8 = "FETCH x\nstatus=200 body_bytes=1234\n" as *u8 31 let p_st: i64 = hh_after(s1, dp_len(s1), "status=" as *u8) 32 let p_bb: i64 = hh_after(s1, dp_len(s1), "body_bytes=" as *u8) 33 let s2: *u8 = "status=0 body_bytes=-3\n" as *u8 34 let p_neg: i64 = hh_after(s2, dp_len(s2), "body_bytes=" as *u8) 35 dp_w(1, "parse : status=" as *u8); dp_wn(1, p_st); dp_w(1, " body=" as *u8); dp_wn(1, p_bb); dp_w(1, " signed=" as *u8); dp_wn(1, p_neg); dp_w(1, " (expect 200,1234,-3)\n" as *u8) 36 if p_st != 200 { fails = fails + 1 } 37 if p_bb != 1234 { fails = fails + 1 } 38 if p_neg != (0 - 3) { fails = fails + 1 } 39 if fails == 0 { dp_w(1, "GATE nx_http_health verdict=GREEN pass=9/9 (real-page health: 200+body=healthy; 500/connfail/empty/wrong-content REJECTED)\n" as *u8); sys_exit(0); return 0 } 40 dp_w(1, "GATE nx_http_health verdict=RED fails=" as *u8); dp_wn(1, fails); dp_w(1, "\n" as *u8) 41 sys_exit(1) 42 return 1 43}