code wiki / _hdl_build / nx_wflow_obs_gate.nx

nx_wflow_obs_gate.nx source

↩ module page · 112 lines · 5128 B

1// nx_wflow_obs_gate.nx -- R6 RUN OBSERVABILITY gate: the board + 0-JS HTML run page are derived ENTIRELY 2// by replaying the event-sourced run ledger (nothing self-reported). Builds a mixed ledger through REAL 3// engine calls (one DONE run, one FAILED run, one PARKED-on-approval run, one synthetic in-flight RUNNING), 4// then asserts the derived states, the totals, and the real page bytes (title + states present, zero 5// <script, DOCTYPE-led). Neg-controls: empty ledger reports 0 runs (no fabrication); nonsense state absent. 6// ZERO forks. license_tier: ORIGINAL expect_exit: 0 7import "nx_wflow_engine.nx" 8import "nx_gate_verdict.nx" 9 10func og_file_has(path: *u8, needle: *u8) -> i64 { 11 let szp: *i64 = sys_mmap(8) as *i64 12 let b: *u8 = wf_readall(path, szp) 13 if (b as i64) == 0 { return 0 } 14 if szp[0] == 0 { return 0 } 15 return wf_lines_with2(b, szp[0], needle, needle) 16} 17 18func main() -> i64 { 19 p("=== NX-WFLOW-OBS GATE (R6: run board + 0-JS HTML by ledger replay, nothing self-reported) ===\n" as *u8) 20 var ok: i64 = 1 21 let now: i64 = wf_now() 22 let led: *u8 = sys_mmap(128) 23 var lo: i64 = 0 24 lo = wf_cat(led, lo, "/tmp/wfobs_" as *u8) 25 lo = wf_catn(led, lo, now) 26 lo = wf_cat(led, lo, ".log" as *u8) 27 led[lo] = 0 as u8 28 let page: *u8 = sys_mmap(128) 29 var po: i64 = 0 30 po = wf_cat(page, po, "/tmp/wfobs_" as *u8) 31 po = wf_catn(page, po, now) 32 po = wf_cat(page, po, ".html" as *u8) 33 page[po] = 0 as u8 34 35 let flows: *i64 = sys_mmap(8 * 4) as *i64 36 flows[0] = "f1|deal|-" as *u8 as i64 37 flows[1] = "f3|ops|-" as *u8 as i64 38 flows[2] = "fa|expense|-" as *u8 as i64 39 let steps: *i64 = sys_mmap(8 * 8) as *i64 40 steps[0] = "f1|1|create-task|-|Prep|1" as *u8 as i64 41 steps[1] = "f1|2|notify|-|Advanced|1" as *u8 as i64 42 steps[2] = "f3|1|probe-fail|-|9|1" as *u8 as i64 43 steps[3] = "fa|1|approve|operator|Need signoff|1" as *u8 as i64 44 let cx: *i64 = sys_mmap(32) as *i64 45 cx[0] = steps as i64 46 cx[1] = 4 47 cx[2] = led as i64 48 cx[3] = 0 49 50 // build the mixed ledger through the REAL engine: DONE + FAILED + PARKED + synthetic RUNNING 51 wf_fire(cx, flows, 3, "deal~id=O1" as *u8) 52 wf_fire(cx, flows, 3, "ops~id=O2" as *u8) 53 wf_fire(cx, flows, 3, "expense~id=O3" as *u8) 54 wf_emit(led, "O4.f1" as *u8, "f1" as *u8, 0, "START" as *u8, 0) 55 56 // T1 board: 4 distinct runs, one of each derived state 57 let cnt: i64 = wf_obs_board(led) 58 p(" T1 board runs=" as *u8); pn(cnt); p("\n" as *u8) 59 if cnt != 4 { ok = 0 } 60 let szp: *i64 = sys_mmap(8) as *i64 61 let buf: *u8 = wf_readall(led, szp) 62 let tok: *u8 = sys_mmap(256) 63 wf_obs_tok(tok, "O1.f1" as *u8) 64 if wf_run_state(buf, szp[0], tok) != 3 { ok = 0 } 65 wf_obs_tok(tok, "O2.f3" as *u8) 66 if wf_run_state(buf, szp[0], tok) != 2 { ok = 0 } 67 wf_obs_tok(tok, "O3.fa" as *u8) 68 if wf_run_state(buf, szp[0], tok) != 1 { ok = 0 } 69 wf_obs_tok(tok, "O4.f1" as *u8) 70 if wf_run_state(buf, szp[0], tok) != 0 { ok = 0 } 71 p(" T1b states done/failed/parked/running all derived correctly=" as *u8); pn(ok); p("\n" as *u8) 72 73 // T2 the page: real bytes, DOCTYPE-led, all states named, run ids present, ZERO script tags 74 let pc: i64 = wf_obs_html(led, page) 75 let hasTitle: i64 = og_file_has(page, "Nishi Workflow Runs" as *u8) 76 let hasO2: i64 = og_file_has(page, "O2.f3" as *u8) 77 let hasParked: i64 = og_file_has(page, "PARKED" as *u8) 78 let hasScript: i64 = og_file_has(page, "<script" as *u8) 79 let hasDoc: i64 = og_file_has(page, "DOCTYPE html" as *u8) 80 p(" T2 page runs=" as *u8); pn(pc); p(" title=" as *u8); pn(hasTitle); p(" o2=" as *u8); pn(hasO2) 81 p(" parked=" as *u8); pn(hasParked); p(" script=" as *u8); pn(hasScript); p(" doctype=" as *u8); pn(hasDoc); p("\n" as *u8) 82 if pc != 4 { ok = 0 } 83 if hasTitle < 1 { ok = 0 } 84 if hasO2 < 1 { ok = 0 } 85 if hasParked < 1 { ok = 0 } 86 if hasScript != 0 { ok = 0 } 87 if hasDoc < 1 { ok = 0 } 88 89 // T3 neg-controls: empty ledger -> 0 runs (no fabrication); nonsense state never appears 90 let led2: *u8 = sys_mmap(128) 91 var l2: i64 = 0 92 l2 = wf_cat(led2, l2, "/tmp/wfobs_empty_" as *u8) 93 l2 = wf_catn(led2, l2, now) 94 l2 = wf_cat(led2, l2, ".log" as *u8) 95 led2[l2] = 0 as u8 96 let c0: i64 = wf_obs_board(led2) 97 let ban: i64 = og_file_has(page, "BANANA" as *u8) 98 p(" T3 negctl emptyRuns=" as *u8); pn(c0); p(" nonsense=" as *u8); pn(ban); p("\n" as *u8) 99 if c0 != 0 { ok = 0 } 100 if ban != 0 { ok = 0 } 101 102 p("NX-WFLOW-OBS-GATE page=" as *u8); p(page); p(" forks=0 " as *u8) 103 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 104 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 105 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 106 let ctr__dry: *i64 = gv_ctr() 107 ctr__dry[0] = ok 108 ctr__dry[1] = 1 109 let rc__dry: i64 = gv_verdict("WFLOW-OBS-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 110 sys_exit(rc__dry) 111 return rc__dry 112}