nx_wflow_branch_capacity_gate_t278.nx source
↩ module page · 102 lines · 5267 B
1// nx_wflow_branch_gate.nx -- R9 MID-FLOW BRANCHING gate: optional 7th step field `k=v` evaluated against
2// the run VARIABLE plane at execution. Match -> step runs; mismatch OR missing variable -> status=SKIP
3// recorded in the ledger and the flow continues (Zapier-filter semantics, event-sourced). Dash or absent
4// field = always run (every pre-R9 definition stays valid). Proves: the SAME flow branches on event data;
5// var-derived conditions (set-var then branch); load refuses garbage conditions. ZERO forks.
6// license_tier: ORIGINAL expect_exit: 0
7import "nx_wflow_engine_capacity_candidate_t278.nx"
8import "nx_gate_verdict.nx"
9
10func bg_n(led: *u8, ridtok: *u8, st: *u8) -> i64 {
11 let szp: *i64 = sys_mmap(8) as *i64
12 let b: *u8 = wf_readall(led, szp)
13 if (b as i64) == 0 { return 0 - 1 }
14 return wf_lines_with2(b, szp[0], ridtok, st)
15}
16
17func main() -> i64 {
18 p("=== NX-WFLOW-BRANCH GATE (R9: per-step k=v conditions vs the variable plane; SKIP recorded) ===\n" as *u8)
19 var ok: i64 = 1
20 let now: i64 = wf_now()
21 let led: *u8 = sys_mmap(128)
22 var lo: i64 = 0
23 lo = wf_cat(led, lo, "/tmp/wfbr_" as *u8)
24 lo = wf_catn(led, lo, now)
25 lo = wf_cat(led, lo, ".log" as *u8)
26 led[lo] = 0 as u8
27
28 let flows: *i64 = sys_mmap(8 * 4) as *i64
29 flows[0] = "fb1|order|-" as *u8 as i64
30 flows[1] = "fb2|deal|-" as *u8 as i64
31 let steps: *i64 = sys_mmap(8 * 8) as *i64
32 steps[0] = "fb1|1|set-var|-|tier=gold|1|-" as *u8 as i64
33 steps[1] = "fb1|2|notify|-|Gold perks for {name}|1|tier=gold" as *u8 as i64
34 steps[2] = "fb1|3|notify|-|Standard path|1|tier=silver" as *u8 as i64
35 steps[3] = "fb1|4|notify|-|Wrap up for {name}|1" as *u8 as i64
36 steps[4] = "fb2|1|notify|-|Big deal path|1|size=big" as *u8 as i64
37 steps[5] = "fb2|2|notify|-|Every deal path|1" as *u8 as i64
38 let cx: *i64 = sys_mmap(32) as *i64
39 cx[0] = steps as i64
40 cx[1] = 6
41 cx[2] = led as i64
42 cx[3] = 0
43
44 // T0 load: 7-field rows valid; garbage condition refused
45 let l0: i64 = wf_load(steps, 6)
46 let bad: *i64 = sys_mmap(16) as *i64
47 bad[0] = "f9|1|notify|-|x|1|garbage" as *u8 as i64
48 let lb: i64 = wf_load(bad, 1)
49 p(" T0 load=" as *u8); pn(l0); p(" badCond=" as *u8); pn(lb); p("\n" as *u8)
50 if l0 != 6 { ok = 0 }
51 if lb != (0 - 1) { ok = 0 }
52
53 // T1 var-derived branch: set-var tier=gold -> gold step RUNS, silver step SKIPs, unconditional runs
54 wf_fire(cx, flows, 2, "order~name=Rose~id=B1" as *u8)
55 let d1: i64 = bg_n(led, " rid=B1.fb1 " as *u8, "status=DONE" as *u8)
56 let o1: i64 = bg_n(led, " rid=B1.fb1 " as *u8, "status=OK" as *u8)
57 let s3: i64 = bg_n(led, " rid=B1.fb1 " as *u8, " step=3 status=SKIP" as *u8)
58 let s2: i64 = bg_n(led, " rid=B1.fb1 " as *u8, " step=2 status=SKIP" as *u8)
59 p(" T1 goldrun done=" as *u8); pn(d1); p(" okSteps=" as *u8); pn(o1); p(" silverSkipped=" as *u8); pn(s3); p(" goldSkipped=" as *u8); pn(s2); p("\n" as *u8)
60 if d1 != 1 { ok = 0 }
61 if o1 != 3 { ok = 0 }
62 if s3 != 1 { ok = 0 }
63 if s2 != 0 { ok = 0 }
64
65 // T2 the SAME flow branches on EVENT data: size=big runs the branch, size=small skips it
66 wf_fire(cx, flows, 2, "deal~size=big~id=B3" as *u8)
67 wf_fire(cx, flows, 2, "deal~size=small~id=B4" as *u8)
68 let bigOk: i64 = bg_n(led, " rid=B3.fb2 " as *u8, " step=1 status=OK" as *u8)
69 let smallSkip: i64 = bg_n(led, " rid=B4.fb2 " as *u8, " step=1 status=SKIP" as *u8)
70 let d3: i64 = bg_n(led, " rid=B3.fb2 " as *u8, "status=DONE" as *u8)
71 let d4: i64 = bg_n(led, " rid=B4.fb2 " as *u8, "status=DONE" as *u8)
72 p(" T2 branch bigRan=" as *u8); pn(bigOk); p(" smallSkipped=" as *u8); pn(smallSkip); p(" bothDone=" as *u8); pn(d3 + d4); p("\n" as *u8)
73 if bigOk != 1 { ok = 0 }
74 if smallSkip != 1 { ok = 0 }
75 if d3 + d4 != 2 { ok = 0 }
76
77 // T3 missing variable -> SKIP recorded, run still completes (data-dependent, never a crash)
78 wf_fire(cx, flows, 2, "deal~id=B5" as *u8)
79 let s5: i64 = bg_n(led, " rid=B5.fb2 " as *u8, " step=1 status=SKIP" as *u8)
80 let d5: i64 = bg_n(led, " rid=B5.fb2 " as *u8, "status=DONE" as *u8)
81 p(" T3 missingVar skipped=" as *u8); pn(s5); p(" done=" as *u8); pn(d5); p("\n" as *u8)
82 if s5 != 1 { ok = 0 }
83 if d5 != 1 { ok = 0 }
84
85 // T4 negctl: nonsense status absent; unconditional step never skipped
86 let ban: i64 = bg_n(led, "WFRUN" as *u8, "status=BANANA" as *u8)
87 let s4u: i64 = bg_n(led, " rid=B1.fb1 " as *u8, " step=4 status=SKIP" as *u8)
88 p(" T4 negctl nonsense=" as *u8); pn(ban); p(" wrapSkipped=" as *u8); pn(s4u); p("\n" as *u8)
89 if ban != 0 { ok = 0 }
90 if s4u != 0 { ok = 0 }
91
92 p("NX-WFLOW-BRANCH-GATE ledger=" as *u8); p(led); p(" forks=0 " as *u8)
93 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
94 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
95 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
96 let ctr__dry: *i64 = gv_ctr()
97 ctr__dry[0] = ok
98 ctr__dry[1] = 1
99 let rc__dry: i64 = gv_verdict("WFLOW-BRANCH-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
100 sys_exit(rc__dry)
101 return rc__dry
102}