code wiki / _hdl_build / nx_apistack_slo_gate.nx
nx_apistack_slo_gate.nx source
↩ module page · 40 lines · 1775 B
1// nx_apistack_slo_gate.nx -- hermetic gate for CAP-API-SLO. Proves allowed-errors, budget, breach detection, and
2// availability permil. expect_exit: 0
3//
4// MIGRATED 2026-07-31 onto nx_gate_verdict (D001, ws=gate-dry-d001). Teeth UNCHANGED -- same four checks,
5// same predicates, same constants, same exit contract. Retired: the private gp/gn printers and the private
6// pass/fail counters, plus the else-ladders that existed only to print a bespoke failure string. The check
7// names are carried into gv_check so no domain detail is lost (rule 25: rewrite better, never strip).
8// Proven by nx_gate_migrate verify (judge-equivalence), not by byte-equality.
9import "nx_syscalls.nx"
10import "nx_apistack_slo.nx"
11import "nx_gate_verdict.nx"
12
13func main(argc: i64, argv: *i64) -> i64 {
14 let ctr: *i64 = gv_ctr()
15 gv_head("=== nx_apistack_slo_gate (error budget + availability) ===" as *u8)
16
17 var t1: i64 = 0
18 if slo_allowed_errors(10000, 999) == 10 { t1 = 1 }
19 gv_check("T1 99.9pct target over 10000 -> 10 allowed errors" as *u8, t1, ctr)
20
21 var t2: i64 = 0
22 if slo_error_budget(10000, 5, 999) == 5 {
23 if slo_breached(10000, 5, 999) == 0 { t2 = 1 }
24 }
25 gv_check("T2 5 errors -> budget 5, not breached" as *u8, t2, ctr)
26
27 var t3: i64 = 0
28 if slo_error_budget(10000, 15, 999) == (0 - 5) {
29 if slo_breached(10000, 15, 999) == 1 { t3 = 1 }
30 }
31 gv_check("T3 15 errors -> budget -5, BREACHED" as *u8, t3, ctr)
32
33 var t4: i64 = 0
34 if slo_availability_permil(10000, 5) == 999 { t4 = 1 }
35 gv_check("T4 availability 9995/10000 = 999permil" as *u8, t4, ctr)
36
37 let rc: i64 = gv_verdict("APISTACK-SLO-GATE" as *u8, ctr, "error budget + breach detection + availability permil all exact" as *u8)
38 sys_exit(rc)
39 return rc
40}