code wiki / _hdl_build / nx_hostop_obs_gate.nx
nx_hostop_obs_gate.nx source
↩ module page · 46 lines · 3218 B
1// nx_hostop_obs_gate.nx -- R9 PROOF: host observability -- apply-ledger history + DORA + notify.
2// Seeds a host-apply ledger with known events; asserts history (latest sha per dest), DORA metrics, notify channel.
3// File-based. license_tier: ORIGINAL expect_exit: 0
4import "nx_syscalls.nx"
5import "nx_hostop.nx"
6import "nx_runpath.nx"
7
8func 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 }
9func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
10func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" " as *u8); g_w(id); g_w(": " as *u8); if ok==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } return 0 }
11func g_unlink(path: *u8) -> i64 { __syscall(87, path as i64, 0, 0, 0, 0, 0); return 0 }
12
13func main() -> i64 {
14 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
15 g_w("=== NX-HOSTOP-OBS GATE (host apply-ledger history + DORA + notify) ===\n" as *u8)
16 let wsid: *u8 = sys_mmap(64); rp_wsid(wsid); rp_ensure(wsid)
17 let D: *u8 = sys_mmap(512); rp_path(wsid, "hob" as *u8, D); __syscall(83, D as i64, 493, 0, 0, 0, 0)
18 let hl: *u8 = sys_mmap(700); pub_join(D, "hostlog.tsv" as *u8, hl); g_unlink(hl)
19 let nf: *u8 = sys_mmap(700); pub_join(D, "notify.tsv" as *u8, nf); g_unlink(nf)
20
21 // seed host-apply events with known ts (a.html applied twice -> latest = shaA2)
22 pub_record_outcome(hl, "shaA1" as *u8, "a.html" as *u8, "h1" as *u8, "PUBLISHED" as *u8, 100, 0)
23 pub_record_outcome(hl, "shaB" as *u8, "b.html" as *u8, "h1" as *u8, "PUBLISHED" as *u8, 200, 0)
24 pub_record_outcome(hl, "shaA2" as *u8, "a.html" as *u8, "h1" as *u8, "PUBLISHED" as *u8, 300, 0)
25
26 let outsha: *u8 = sys_mmap(256)
27 let hq: i64 = hostop_history(hl, "a.html" as *u8, outsha)
28 let hist_ok: i64 = ((hq==1) as i64) & (pub_streq(outsha, "shaA2" as *u8))
29 let m: *i64 = sys_mmap(128) as *i64
30 hostop_metrics(hl, m)
31 let metrics_ok: i64 = ((m[0]==3) as i64) & ((m[4]==200) as i64) // deploys=3, span=300-100=200
32
33 hostop_notify(nf, "HOST-APPLIED" as *u8, "a.html" as *u8, "shaA2" as *u8)
34 let np: *i64 = sys_mmap(8) as *i64; let nd: *u8 = sys_read_file(nf, np)
35 var notify_ok: i64 = 0
36 if (nd as i64)!=0 { if pub_substr(nd, np[0], "HOST-APPLIED" as *u8)==1 { if pub_substr(nd, np[0], "a.html" as *u8)==1 { notify_ok = 1 } } }
37
38 g_w(" history a.html='" as *u8); g_w(outsha); g_w("' DORA deploys=" as *u8); g_n(m[0]); g_w(" span=" as *u8); g_n(m[4]); g_w(" notify=" as *u8); g_n(notify_ok); g_w("\n" as *u8)
39 g_row("HISTORY: latest applied sha per host path (a.html -> shaA2)" as *u8, hist_ok, pass)
40 g_row("METRICS: host DORA from the apply-ledger (deploys=3, span=200)" as *u8, metrics_ok, pass)
41 g_row("NOTIFY: a host deploy event is logged to the channel" as *u8, notify_ok, pass)
42
43 g_w("NX-HOSTOP-OBS rows=3 pass=" as *u8); g_n(pass[0])
44 if pass[0]==3 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
45 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
46}