code wiki / _hdl_build / nx_wflow_capture_gate.nx
nx_wflow_capture_gate.nx source
↩ module page · 109 lines · 4823 B
1// nx_wflow_capture_gate.nx -- R8b STDOUT-CAPTURE gate: exec-organ channel `connector>varname` pipes the
2// child organ's stdout (bounded 480B, newlines to spaces, trailing space trim, LOUD over-cap) into the run
3// variable plane -- a step's OUTPUT becomes later steps' INPUT (the full Zapier dataflow shape). Proves:
4// captured value lands as WFVAR and substitutes into the next step's arg; capture only on exit 0; plain
5// connector (no >) captures nothing (back-compat); load refuses empty connector or empty var. TWO forks.
6// license_tier: ORIGINAL expect_exit: 0
7import "nx_wflow_engine.nx"
8import "nx_gate_verdict.nx"
9
10func pg_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}
16func pg_row(conf: *u8, name: *u8, elf: *u8, flag: *u8) -> i64 {
17 let ln: *u8 = sys_mmap(600)
18 var o: i64 = 0
19 o = wf_cat(ln, o, name)
20 ln[o] = 9 as u8
21 o = o + 1
22 o = wf_cat(ln, o, elf)
23 ln[o] = 9 as u8
24 o = o + 1
25 o = wf_cat(ln, o, flag)
26 ln[o] = 10 as u8
27 ln[o+1] = 0 as u8
28 return wf_append(conf, ln)
29}
30
31func main() -> i64 {
32 p("=== NX-WFLOW-CAPTURE GATE (R8b: organ stdout -> run variable -> next step arg) ===\n" as *u8)
33 var ok: i64 = 1
34 let now: i64 = wf_now()
35 let led: *u8 = sys_mmap(128)
36 var lo: i64 = 0
37 lo = wf_cat(led, lo, "/tmp/wfcap_" as *u8)
38 lo = wf_catn(led, lo, now)
39 lo = wf_cat(led, lo, ".log" as *u8)
40 led[lo] = 0 as u8
41 let conf: *u8 = sys_mmap(128)
42 var co: i64 = 0
43 co = wf_cat(conf, co, "/tmp/wfcap_" as *u8)
44 co = wf_catn(conf, co, now)
45 co = wf_cat(conf, co, ".conf" as *u8)
46 conf[co] = 0 as u8
47 pg_row(conf, "argecho" as *u8, "./_offc/nx_tool_argecho.elf" as *u8, "GREEN" as *u8)
48
49 let flows: *i64 = sys_mmap(8 * 4) as *i64
50 flows[0] = "fc1|cap|-" as *u8 as i64
51 flows[1] = "fc2|nocap|-" as *u8 as i64
52 let steps: *i64 = sys_mmap(8 * 4) as *i64
53 steps[0] = "fc1|1|exec-organ|argecho>echoed|{word}~two|1" as *u8 as i64
54 steps[1] = "fc1|2|notify|-|Got {echoed}|1" as *u8 as i64
55 steps[2] = "fc2|1|exec-organ|argecho|solo|1" as *u8 as i64
56 let cx: *i64 = sys_mmap(32) as *i64
57 cx[0] = steps as i64
58 cx[1] = 3
59 cx[2] = led as i64
60 cx[3] = conf as i64
61
62 // T0 load: capture spec valid; empty connector or empty var refused
63 let l0: i64 = wf_load(steps, 3)
64 let bad1: *i64 = sys_mmap(16) as *i64
65 bad1[0] = "f9|1|exec-organ|>v|x|1" as *u8 as i64
66 let lb1: i64 = wf_load(bad1, 1)
67 let bad2: *i64 = sys_mmap(16) as *i64
68 bad2[0] = "f9|1|exec-organ|argecho>|x|1" as *u8 as i64
69 let lb2: i64 = wf_load(bad2, 1)
70 p(" T0 load=" as *u8); pn(l0); p(" emptyConn=" as *u8); pn(lb1); p(" emptyVar=" as *u8); pn(lb2); p("\n" as *u8)
71 if l0 != 3 { ok = 0 }
72 if lb1 != (0 - 1) { ok = 0 }
73 if lb2 != (0 - 1) { ok = 0 }
74
75 // T1 THE DATAFLOW CLOSE: organ stdout captured into {echoed}, substituted into the NEXT step's arg
76 let r1: i64 = wf_fire(cx, flows, 2, "cap~word=alpha~id=X1" as *u8)
77 let d1: i64 = pg_n(led, " rid=X1.fc1 " as *u8, "status=DONE" as *u8)
78 let cv: i64 = pg_n(led, " rid=X1.fc1 " as *u8, "k=echoed v=NX_TOOL_ARGECHO_OK alpha two" as *u8)
79 let s2: i64 = pg_n(led, " rid=X1.fc1 " as *u8, " step=2 status=OK" as *u8)
80 p(" T1 capture started=" as *u8); pn(r1); p(" done=" as *u8); pn(d1); p(" capturedVar=" as *u8); pn(cv); p(" nextStepUsedIt=" as *u8); pn(s2); p("\n" as *u8)
81 if r1 != 1 { ok = 0 }
82 if d1 != 1 { ok = 0 }
83 if cv != 1 { ok = 0 }
84 if s2 != 1 { ok = 0 }
85
86 // T2 back-compat: plain connector captures nothing
87 wf_fire(cx, flows, 2, "nocap~id=X2" as *u8)
88 let d2: i64 = pg_n(led, " rid=X2.fc2 " as *u8, "status=DONE" as *u8)
89 let nv: i64 = pg_n(led, " rid=X2.fc2 " as *u8, "k=echoed" as *u8)
90 p(" T2 nocap done=" as *u8); pn(d2); p(" strayVar=" as *u8); pn(nv); p("\n" as *u8)
91 if d2 != 1 { ok = 0 }
92 if nv != 0 { ok = 0 }
93
94 // T3 negctl
95 let ban: i64 = pg_n(led, "WFVAR" as *u8, "v=BANANA" as *u8)
96 p(" T3 negctl nonsense=" as *u8); pn(ban); p("\n" as *u8)
97 if ban != 0 { ok = 0 }
98
99 p("NX-WFLOW-CAPTURE-GATE ledger=" as *u8); p(led); p(" forks=2 " as *u8)
100 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
101 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
102 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
103 let ctr__dry: *i64 = gv_ctr()
104 ctr__dry[0] = ok
105 ctr__dry[1] = 1
106 let rc__dry: i64 = gv_verdict("WFLOW-CAPTURE-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
107 sys_exit(rc__dry)
108 return rc__dry
109}