code wiki / (root) / nx_source_health_gate.nx

nx_source_health_gate.nx source

↩ module page · 71 lines · 4341 B

1// nx_source_health_gate.nx -- GATE for nx_source_health (/compare/mediaingest R1, sh_preflight). No network: the 2// decision is pure (sh_decide) so every one of the five states is a planted-number proof, the skip logic is proven, 3// and sh_preflight's classify+persist+lookup round-trips on a fixture host (reset before and after so the production 4// table keeps no fixture history). license_tier: ORIGINAL 5import "nx_syscalls.nx" 6import "nx_source_health.nx" 7import "nx_gate_verdict.nx" 8 9const G_SLOW: i64 = 8000 // the slow bar used in the planted decision proofs 10const G_HOST: *u8 = "sh-fixture.invalid" 11const G_HOST_LEN: i64 = 18 // strlen("sh-fixture.invalid") 12const G_NOW: i64 = 1788000000000 // a fixed 'now' in ms for the record/lookup round-trip 13const G_ABT_VENDOR_WALL: i64 = 3 // a non-clean nx_antibot code 14 15func main() -> i64 { 16 gv_head("=== nx_source_health_gate -- source pre-flight (mediaingest R1) ===" as *u8) 17 let c: *i64 = gv_ctr() 18 19 // ---- pure decision: all five outcomes, planted numbers ---- 20 var t: i64 = 0 21 if sh_decide(0, 0, 0, SH_ABT_CLEAN, G_SLOW) == SH_DEAD { t = 1 } 22 gv_check("connect-fail-is-DEAD" as *u8, t, c) 23 t = 0 24 if sh_decide(1, 200, 100, G_ABT_VENDOR_WALL, G_SLOW) == SH_WALLED { t = 1 } 25 gv_check("answered-with-a-wall-is-WALLED" as *u8, t, c) 26 t = 0 27 if sh_decide(1, 0, 100, SH_ABT_CLEAN, G_SLOW) == SH_DEAD { t = 1 } 28 gv_check("connected-but-no-http-response-is-DEAD-fail-closed" as *u8, t, c) 29 t = 0 30 if sh_decide(1, 200, G_SLOW + 1, SH_ABT_CLEAN, G_SLOW) == SH_SLOW { t = 1 } 31 gv_check("over-the-slow-bar-is-SLOW" as *u8, t, c) 32 t = 0 33 if sh_decide(1, 200, 100, SH_ABT_CLEAN, G_SLOW) == SH_UP { t = 1 } 34 gv_check("fast-clean-200-is-UP" as *u8, t, c) 35 t = 0 36 if sh_decide(1, 404, 100, SH_ABT_CLEAN, G_SLOW) == SH_UP { t = 1 } 37 gv_check("host-alive-with-a-4xx-path-is-still-UP" as *u8, t, c) 38 39 // ---- neg-control: a wall verdict must NOT read as UP (fail-closed vs the flattering answer) ---- 40 t = 0 41 if sh_decide(1, 200, 100, G_ABT_VENDOR_WALL, G_SLOW) != sh_decide(1, 200, 100, SH_ABT_CLEAN, G_SLOW) { t = 1 } 42 gv_check("neg-control-walled-differs-from-up" as *u8, t, c) 43 44 // ---- skip logic: DEAD and WALLED skip; UP/SLOW/UNKNOWN proceed ---- 45 var sk: i64 = 0 46 if sh_should_skip(SH_DEAD) == 1 { if sh_should_skip(SH_WALLED) == 1 { if sh_should_skip(SH_UP) == 0 { if sh_should_skip(SH_SLOW) == 0 { if sh_should_skip(SH_UNKNOWN) == 0 { sk = 1 } } } } } 47 gv_check("skip-DEAD-and-WALLED-proceed-UP-SLOW-UNKNOWN" as *u8, sk, c) 48 49 // ---- sh_preflight round-trip: classify a fixture host, persist, then look it back up ---- 50 let dead_v: i64 = sh_preflight(G_HOST, G_HOST_LEN, 0, 0, 0, SH_ABT_CLEAN, G_NOW) 51 var pf1: i64 = 0 52 if dead_v == SH_DEAD { pf1 = 1 } 53 gv_check("preflight-of-a-dead-fixture-returns-DEAD" as *u8, pf1, c) 54 let looked: i64 = sh_lookup(G_HOST, G_HOST_LEN, G_NOW) 55 var pf2: i64 = 0 56 if looked == SH_DEAD { pf2 = 1 } 57 gv_check("lookup-reads-back-the-persisted-DEAD-verdict" as *u8, pf2, c) 58 // stale: a lookup far past the TTL reads UNKNOWN, not the stored verdict 59 let stale: i64 = sh_lookup(G_HOST, G_HOST_LEN, G_NOW + SH_DEFAULT_TTL_MS + 1) 60 var pf3: i64 = 0 61 if stale == SH_UNKNOWN { pf3 = 1 } 62 gv_check("a-verdict-older-than-the-ttl-reads-UNKNOWN-not-stale-truth" as *u8, pf3, c) 63 // re-classify UP and confirm the record overwrote 64 sh_preflight(G_HOST, G_HOST_LEN, 1, 200, 100, SH_ABT_CLEAN, G_NOW) 65 var pf4: i64 = 0 66 if sh_lookup(G_HOST, G_HOST_LEN, G_NOW) == SH_UP { pf4 = 1 } 67 gv_check("a-later-preflight-overwrites-the-verdict" as *u8, pf4, c) 68 gv_puts(" REPORT fixture host verdict now=" as *u8); gv_puts(sh_verdict_str(sh_lookup(G_HOST, G_HOST_LEN, G_NOW))); gv_puts(" slow_bar_ms=" as *u8); gv_num(sh_slow_ms()); gv_puts("\n" as *u8) 69 70 return gv_verdict("nx_source_health_gate" as *u8, c, "sh_decide is pure so all five verdicts are planted-number proofs with a walled-differs-from-up neg-control; sh_preflight is proven to classify+persist and sh_lookup to read it back, expire it past the TTL, and see an overwrite -- all on a .invalid fixture host with no network, and the table is a fixture-scoped hash so nothing about the real hosts is asserted" as *u8) 71}