code wiki / _hdl_build / nx_wflow_tpl_gate.nx
nx_wflow_tpl_gate.nx source
↩ module page · 96 lines · 4201 B
1// nx_wflow_tpl_gate.nx -- R13 TEMPLATE GALLERY gate: gallery = <dir>/index (name|description) + per-name
2// .flows/.steps pairs. LIST prints every row with file-existence + version and counts USABLE pairs;
3// INSTANTIATE is fail-closed to indexed templates, byte-copies both files, then validates the COPY whole
4// (a broken template never lands silently) and reports its version. Negatives: unknown name, indexed row
5// with missing files, missing gallery. ZERO forks. license_tier: ORIGINAL expect_exit: 0
6import "nx_wflow_engine.nx"
7import "nx_gate_verdict.nx"
8
9func tg_has(path: *u8, needle: *u8) -> i64 {
10 let szp: *i64 = sys_mmap(8) as *i64
11 let b: *u8 = wf_readall(path, szp)
12 if (b as i64) == 0 { return 0 }
13 if szp[0] == 0 { return 0 }
14 return wf_lines_with2(b, szp[0], needle, needle)
15}
16
17func main() -> i64 {
18 p("=== NX-WFLOW-TPL GATE (R13: gallery index + instantiate fail-closed + validated copies) ===\n" as *u8)
19 var ok: i64 = 1
20 let now: i64 = wf_now()
21 let dir: *u8 = sys_mmap(128)
22 var dr: i64 = 0
23 dr = wf_cat(dir, dr, "/tmp/wftpl_" as *u8)
24 dr = wf_catn(dir, dr, now)
25 dir[dr] = 0 as u8
26 __syscall(83, dir as i64, 493, 0, 0, 0, 0)
27
28 let ip: *u8 = sys_mmap(512)
29 wf_tpl_index_path(dir, ip)
30 wf_append(ip, "good|A valid two-step template\n" as *u8)
31 wf_append(ip, "ghost|Indexed but its files are missing\n" as *u8)
32 let gf: *u8 = sys_mmap(512)
33 let gs: *u8 = sys_mmap(512)
34 wf_tpl_path(dir, "good" as *u8, ".flows" as *u8, gf)
35 wf_tpl_path(dir, "good" as *u8, ".steps" as *u8, gs)
36 wf_append(gf, "@version 1\n" as *u8)
37 wf_append(gf, "g1|go|-\n" as *u8)
38 wf_append(gs, "g1|1|notify|-|hi {name}|1\n" as *u8)
39
40 // T1 list: both rows printed, only the complete pair counts as usable
41 let c1: i64 = wf_tpl_list(dir)
42 p(" T1 usable=" as *u8); pn(c1); p("\n" as *u8)
43 if c1 != 1 { ok = 0 }
44
45 // T2 instantiate good -> dest copies byte-real, validated whole, version reported
46 let df: *u8 = sys_mmap(128)
47 var dfo: i64 = 0
48 dfo = wf_cat(df, dfo, "/tmp/wftpl_inst_" as *u8)
49 dfo = wf_catn(df, dfo, now)
50 dfo = wf_cat(df, dfo, ".flows" as *u8)
51 df[dfo] = 0 as u8
52 let dsp: *u8 = sys_mmap(128)
53 var dso: i64 = 0
54 dso = wf_cat(dsp, dso, "/tmp/wftpl_inst_" as *u8)
55 dso = wf_catn(dsp, dso, now)
56 dso = wf_cat(dsp, dso, ".steps" as *u8)
57 dsp[dso] = 0 as u8
58 let v: i64 = wf_tpl_instantiate(dir, "good" as *u8, df, dsp)
59 let hasFlow: i64 = tg_has(df, "g1|go|-" as *u8)
60 let hasStep: i64 = tg_has(dsp, "notify" as *u8)
61 p(" T2 instantiate ver=" as *u8); pn(v); p(" flowCopied=" as *u8); pn(hasFlow); p(" stepCopied=" as *u8); pn(hasStep); p("\n" as *u8)
62 if v != 1 { ok = 0 }
63 if hasFlow != 1 { ok = 0 }
64 if hasStep != 1 { ok = 0 }
65
66 // T3 unknown template -> fail-closed
67 let r3: i64 = wf_tpl_instantiate(dir, "nosuch" as *u8, df, dsp)
68 p(" T3 unknown rc=" as *u8); pn(r3); p("\n" as *u8)
69 if r3 != (0 - 1) { ok = 0 }
70
71 // T4 indexed but files missing -> loud refuse
72 let r4: i64 = wf_tpl_instantiate(dir, "ghost" as *u8, df, dsp)
73 p(" T4 ghost rc=" as *u8); pn(r4); p("\n" as *u8)
74 if r4 != (0 - 1) { ok = 0 }
75
76 // T5 missing gallery -> loud
77 let r5: i64 = wf_tpl_list("/tmp/wftpl_no_such_dir_ever" as *u8)
78 p(" T5 nogallery rc=" as *u8); pn(r5); p("\n" as *u8)
79 if r5 != (0 - 1) { ok = 0 }
80
81 // T6 negctl: instantiated copy carries no nonsense
82 let ban: i64 = tg_has(df, "BANANA" as *u8)
83 p(" T6 negctl nonsense=" as *u8); pn(ban); p("\n" as *u8)
84 if ban != 0 { ok = 0 }
85
86 p("NX-WFLOW-TPL-GATE dir=" as *u8); p(dir); p(" forks=0 " as *u8)
87 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
88 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
89 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
90 let ctr__dry: *i64 = gv_ctr()
91 ctr__dry[0] = ok
92 ctr__dry[1] = 1
93 let rc__dry: i64 = gv_verdict("WFLOW-TPL-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
94 sys_exit(rc__dry)
95 return rc__dry
96}