@blackbelt-technology/pi-dashboard-flows-plugin 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -5
- package/src/client/FlowAgentCard.tsx +24 -17
- package/src/client/FlowAgentDetail.tsx +1 -1
- package/src/client/FlowDashboard.tsx +6 -2
- package/src/client/FlowInputWiring.tsx +2 -2
- package/src/client/FlowsCommandRoutes.tsx +13 -5
- package/src/client/FlowsSettings.tsx +4 -4
- package/src/client/SessionFlowActions.tsx +9 -4
- package/src/client/format-cost.ts +21 -0
- package/src/client/send-safe.ts +19 -0
- package/src/AGENTS.md +0 -8
- package/src/__tests__/FlowGraph.test.ts +0 -305
- package/src/__tests__/FlowInputWiring.test.tsx +0 -97
- package/src/__tests__/FlowSummary.test.tsx +0 -331
- package/src/__tests__/FlowYamlPreview.test.tsx +0 -75
- package/src/__tests__/FlowsSessionStateContext.test.tsx +0 -223
- package/src/__tests__/FlowsUiStateContext.test.tsx +0 -140
- package/src/__tests__/authoring-renderers.test.tsx +0 -190
- package/src/__tests__/automation-actions.test.ts +0 -117
- package/src/__tests__/flow-agent-card-code-source.test.tsx +0 -154
- package/src/__tests__/flow-agent-cost.test.tsx +0 -160
- package/src/__tests__/flow-agent-error.test.ts +0 -60
- package/src/__tests__/flow-collapse-storage.test.ts +0 -90
- package/src/__tests__/flow-edges.test.ts +0 -195
- package/src/__tests__/flow-inputs.test.ts +0 -69
- package/src/__tests__/flow-reducer-bridge-contract.test.ts +0 -108
- package/src/__tests__/flow-reducer-seed-on-start.test.ts +0 -61
- package/src/__tests__/flow-yaml-parse.test.ts +0 -124
- package/src/__tests__/flows-for-cwd.test.ts +0 -51
- package/src/__tests__/flowsAvailability.test.ts +0 -79
- package/src/__tests__/manifest-discoverability.test.ts +0 -97
- package/src/__tests__/node-kind-reducer.test.ts +0 -135
- package/src/__tests__/plugin-action-handler.test.ts +0 -54
- package/src/__tests__/reducer-parity.test.ts +0 -106
- package/src/__tests__/render-actions.test.ts +0 -63
- package/src/__tests__/session-flow-actions-edit.test.tsx +0 -98
- package/src/bridge/AGENTS.md +0 -8
- package/src/client/AGENTS.md +0 -32
- package/src/server/AGENTS.md +0 -10
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createUiPrimitiveRegistry,
|
|
3
|
-
registerUiPrimitive,
|
|
4
|
-
UiPrimitiveProvider,
|
|
5
|
-
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
6
|
-
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
7
|
-
import { cleanup, render } from "@testing-library/react";
|
|
8
|
-
import { createElement } from "react";
|
|
9
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
10
|
-
import { computeLayout, FlowGraph, type FlowGraphStep, mapStepType } from "../client/FlowGraph.js";
|
|
11
|
-
|
|
12
|
-
const registry = createUiPrimitiveRegistry();
|
|
13
|
-
registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.zoomControls, ((() => null) as never));
|
|
14
|
-
|
|
15
|
-
afterEach(() => cleanup());
|
|
16
|
-
|
|
17
|
-
describe("FlowGraph render: on_complete label suppression", () => {
|
|
18
|
-
it("renders branch labels but never the on_complete label", () => {
|
|
19
|
-
// See change: fix-flow-ui-graph-zoom-summary — on_complete is the happy-path
|
|
20
|
-
// default and renders as a plain arrow; branch labels stay visible.
|
|
21
|
-
const steps: FlowGraphStep[] = [
|
|
22
|
-
{ id: "load", label: "load", status: "complete", blockedBy: [], type: "code", onComplete: "gate" },
|
|
23
|
-
{ id: "gate", label: "gate", status: "complete", blockedBy: [], type: "code-decision", branches: { go: "done" } },
|
|
24
|
-
{ id: "done", label: "done", status: "pending", blockedBy: [] },
|
|
25
|
-
];
|
|
26
|
-
const { container } = render(
|
|
27
|
-
createElement(UiPrimitiveProvider, {
|
|
28
|
-
value: registry,
|
|
29
|
-
children: createElement(FlowGraph, { steps }),
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
const text = container.textContent ?? "";
|
|
33
|
-
expect(text).toContain("go"); // branch label rendered
|
|
34
|
-
expect(text).not.toContain("on_complete"); // route happy-path label suppressed
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe("mapStepType (canonical node set)", () => {
|
|
39
|
-
it("maps the new code node kinds", () => {
|
|
40
|
-
expect(mapStepType("code")).toBe("code");
|
|
41
|
-
expect(mapStepType("code-decision")).toBe("code-decision");
|
|
42
|
-
});
|
|
43
|
-
it("maps fork + agent-decision to fork shape", () => {
|
|
44
|
-
expect(mapStepType("fork")).toBe("fork");
|
|
45
|
-
expect(mapStepType("agent-decision")).toBe("fork");
|
|
46
|
-
});
|
|
47
|
-
it("agent and removed legacy types (incl. flow-ref) map to default (undefined)", () => {
|
|
48
|
-
expect(mapStepType("agent")).toBeUndefined();
|
|
49
|
-
expect(mapStepType("conditional")).toBeUndefined();
|
|
50
|
-
expect(mapStepType("agent-loop-decision")).toBeUndefined();
|
|
51
|
-
expect(mapStepType("flow-ref")).toBeUndefined();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("computeLayout", () => {
|
|
56
|
-
it("lays out a linear flow A→B→C left-to-right", () => {
|
|
57
|
-
const steps: FlowGraphStep[] = [
|
|
58
|
-
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
59
|
-
{ id: "b", label: "step-b", status: "running", blockedBy: ["a"] },
|
|
60
|
-
{ id: "c", label: "step-c", status: "pending", blockedBy: ["b"] },
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
const result = computeLayout(steps);
|
|
64
|
-
|
|
65
|
-
expect(result.nodes).toHaveLength(3);
|
|
66
|
-
expect(result.edges).toHaveLength(2);
|
|
67
|
-
|
|
68
|
-
// Nodes should be left-to-right: a.x < b.x < c.x
|
|
69
|
-
const nodeA = result.nodes.find(n => n.id === "a")!;
|
|
70
|
-
const nodeB = result.nodes.find(n => n.id === "b")!;
|
|
71
|
-
const nodeC = result.nodes.find(n => n.id === "c")!;
|
|
72
|
-
expect(nodeA.x).toBeLessThan(nodeB.x);
|
|
73
|
-
expect(nodeB.x).toBeLessThan(nodeC.x);
|
|
74
|
-
|
|
75
|
-
// All nodes at same y (linear flow, same rank)
|
|
76
|
-
expect(nodeA.y).toBe(nodeB.y);
|
|
77
|
-
expect(nodeB.y).toBe(nodeC.y);
|
|
78
|
-
|
|
79
|
-
// Edges should have points
|
|
80
|
-
for (const edge of result.edges) {
|
|
81
|
-
expect(edge.points.length).toBeGreaterThanOrEqual(2);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Width and height should be positive
|
|
85
|
-
expect(result.width).toBeGreaterThan(0);
|
|
86
|
-
expect(result.height).toBeGreaterThan(0);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("lays out a branching flow A→B, A→C, B→D, C→D with vertical stacking", () => {
|
|
90
|
-
const steps: FlowGraphStep[] = [
|
|
91
|
-
{ id: "a", label: "start", status: "complete", blockedBy: [] },
|
|
92
|
-
{ id: "b", label: "branch-1", status: "running", blockedBy: ["a"] },
|
|
93
|
-
{ id: "c", label: "branch-2", status: "running", blockedBy: ["a"] },
|
|
94
|
-
{ id: "d", label: "merge", status: "pending", blockedBy: ["b", "c"] },
|
|
95
|
-
];
|
|
96
|
-
|
|
97
|
-
const result = computeLayout(steps);
|
|
98
|
-
|
|
99
|
-
expect(result.nodes).toHaveLength(4);
|
|
100
|
-
expect(result.edges).toHaveLength(4); // a→b, a→c, b→d, c→d
|
|
101
|
-
|
|
102
|
-
const nodeA = result.nodes.find(n => n.id === "a")!;
|
|
103
|
-
const nodeB = result.nodes.find(n => n.id === "b")!;
|
|
104
|
-
const nodeC = result.nodes.find(n => n.id === "c")!;
|
|
105
|
-
const nodeD = result.nodes.find(n => n.id === "d")!;
|
|
106
|
-
|
|
107
|
-
// A and D should be at different x positions (different ranks)
|
|
108
|
-
expect(nodeA.x).toBeLessThan(nodeB.x);
|
|
109
|
-
expect(nodeB.x).toBeLessThan(nodeD.x);
|
|
110
|
-
|
|
111
|
-
// B and C should be at the same x (same rank) but different y (stacked)
|
|
112
|
-
expect(nodeB.x).toBe(nodeC.x);
|
|
113
|
-
expect(nodeB.y).not.toBe(nodeC.y);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("places no-blockedBy parallel roots in the same rank (no false serialization)", () => {
|
|
117
|
-
// Two roots, no blockedBy, no separator between them. The engine runs both
|
|
118
|
-
// in wave 1 (parallel); the layout must NOT synthesize an impl→docs edge that
|
|
119
|
-
// pushes them into consecutive ranks (would read as sequential).
|
|
120
|
-
const steps: FlowGraphStep[] = [
|
|
121
|
-
{ id: "impl", label: "impl", status: "running", blockedBy: [] },
|
|
122
|
-
{ id: "docs", label: "docs", status: "running", blockedBy: [] },
|
|
123
|
-
];
|
|
124
|
-
const result = computeLayout(steps);
|
|
125
|
-
expect(result.edges).toHaveLength(0);
|
|
126
|
-
const impl = result.nodes.find(n => n.id === "impl")!;
|
|
127
|
-
const docs = result.nodes.find(n => n.id === "docs")!;
|
|
128
|
-
expect(impl.x).toBe(docs.x); // same rank
|
|
129
|
-
expect(impl.y).not.toBe(docs.y); // stacked vertically = parallel
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("handles single-step flow", () => {
|
|
133
|
-
const steps: FlowGraphStep[] = [
|
|
134
|
-
{ id: "solo", label: "solo-step", status: "running", blockedBy: [] },
|
|
135
|
-
];
|
|
136
|
-
|
|
137
|
-
const result = computeLayout(steps);
|
|
138
|
-
expect(result.nodes).toHaveLength(1);
|
|
139
|
-
expect(result.edges).toHaveLength(0);
|
|
140
|
-
expect(result.width).toBeGreaterThan(0);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("marks a returning on_error route as a red loop-styled edge (isError + isReturning)", () => {
|
|
144
|
-
const steps: FlowGraphStep[] = [
|
|
145
|
-
{ id: "validate", label: "validate", status: "complete", blockedBy: [], type: "code-decision", onError: "fixup" },
|
|
146
|
-
{ id: "transform", label: "transform", status: "running", blockedBy: ["validate"] },
|
|
147
|
-
{ id: "fixup", label: "fixup", status: "pending", blockedBy: [], onComplete: "validate" },
|
|
148
|
-
];
|
|
149
|
-
const result = computeLayout(steps);
|
|
150
|
-
const e = result.edges.find(ed => ed.source === "validate" && ed.target === "fixup");
|
|
151
|
-
expect(e).toBeTruthy();
|
|
152
|
-
expect(e!.isError).toBe(true);
|
|
153
|
-
expect(e!.isReturning).toBe(true);
|
|
154
|
-
// dagre-routed: multi-segment polyline (does not cross the band naively)
|
|
155
|
-
expect(e!.points.length).toBeGreaterThanOrEqual(2);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("collapses terminal on_error handlers into a single sink node", () => {
|
|
159
|
-
const steps: FlowGraphStep[] = [
|
|
160
|
-
{ id: "a", label: "a", status: "complete", blockedBy: [], onError: "notify" },
|
|
161
|
-
{ id: "b", label: "b", status: "running", blockedBy: ["a"], onError: "notify" },
|
|
162
|
-
{ id: "notify", label: "notify", status: "pending", blockedBy: [] },
|
|
163
|
-
];
|
|
164
|
-
const result = computeLayout(steps);
|
|
165
|
-
expect(result.errorSink).toBeTruthy();
|
|
166
|
-
expect(result.errorSink!.handlers).toEqual(["notify"]);
|
|
167
|
-
// the terminal handler is NOT laid out as a normal node
|
|
168
|
-
expect(result.nodes.some(n => n.id === "notify")).toBe(false);
|
|
169
|
-
// both terminal routes are present as error edges (routed to the sink)
|
|
170
|
-
expect(result.edges.filter(e => e.isError).map(e => e.source).sort()).toEqual(["a", "b"]);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("removes error routes from layout when showErrorRoutes is false (zero footprint)", () => {
|
|
174
|
-
const withErr: FlowGraphStep[] = [
|
|
175
|
-
{ id: "a", label: "a", status: "complete", blockedBy: [], onError: "notify" },
|
|
176
|
-
{ id: "b", label: "b", status: "running", blockedBy: ["a"] },
|
|
177
|
-
{ id: "notify", label: "notify", status: "pending", blockedBy: [] },
|
|
178
|
-
];
|
|
179
|
-
const baseline: FlowGraphStep[] = [
|
|
180
|
-
{ id: "a", label: "a", status: "complete", blockedBy: [] },
|
|
181
|
-
{ id: "b", label: "b", status: "running", blockedBy: ["a"] },
|
|
182
|
-
];
|
|
183
|
-
const off = computeLayout(withErr, { showErrorRoutes: false });
|
|
184
|
-
const base = computeLayout(baseline);
|
|
185
|
-
expect(off.errorSink).toBeUndefined();
|
|
186
|
-
expect(off.edges.some(e => e.isError)).toBe(false);
|
|
187
|
-
expect(off.nodes.some(n => n.id === "notify")).toBe(false);
|
|
188
|
-
expect(off.height).toBe(base.height);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("handles empty steps array", () => {
|
|
192
|
-
const result = computeLayout([]);
|
|
193
|
-
// Should return empty layout without throwing
|
|
194
|
-
expect(result.nodes).toHaveLength(0);
|
|
195
|
-
expect(result.edges).toHaveLength(0);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("uses consistent node dimensions", () => {
|
|
199
|
-
const steps: FlowGraphStep[] = [
|
|
200
|
-
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
201
|
-
{ id: "b", label: "step-b", status: "pending", blockedBy: ["a"] },
|
|
202
|
-
];
|
|
203
|
-
|
|
204
|
-
const result = computeLayout(steps);
|
|
205
|
-
// All nodes should have same width and height
|
|
206
|
-
expect(result.nodes[0].width).toBe(result.nodes[1].width);
|
|
207
|
-
expect(result.nodes[0].height).toBe(result.nodes[1].height);
|
|
208
|
-
expect(result.nodes[0].width).toBeGreaterThan(0);
|
|
209
|
-
expect(result.nodes[0].height).toBeGreaterThan(0);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("preserves status on positioned nodes", () => {
|
|
213
|
-
const steps: FlowGraphStep[] = [
|
|
214
|
-
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
215
|
-
{ id: "b", label: "step-b", status: "error", blockedBy: ["a"] },
|
|
216
|
-
];
|
|
217
|
-
|
|
218
|
-
const result = computeLayout(steps);
|
|
219
|
-
expect(result.nodes.find(n => n.id === "a")!.status).toBe("complete");
|
|
220
|
-
expect(result.nodes.find(n => n.id === "b")!.status).toBe("error");
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("edges carry source/target status for styling", () => {
|
|
224
|
-
const steps: FlowGraphStep[] = [
|
|
225
|
-
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
226
|
-
{ id: "b", label: "step-b", status: "running", blockedBy: ["a"] },
|
|
227
|
-
];
|
|
228
|
-
|
|
229
|
-
const result = computeLayout(steps);
|
|
230
|
-
expect(result.edges).toHaveLength(1);
|
|
231
|
-
expect(result.edges[0].sourceStatus).toBe("complete");
|
|
232
|
-
expect(result.edges[0].targetStatus).toBe("running");
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("layout dimensions are consistent regardless of step count", () => {
|
|
236
|
-
// Single node
|
|
237
|
-
const single = computeLayout([
|
|
238
|
-
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
239
|
-
]);
|
|
240
|
-
// Many nodes
|
|
241
|
-
const many = computeLayout([
|
|
242
|
-
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
243
|
-
{ id: "b", label: "step-b", status: "pending", blockedBy: ["a"] },
|
|
244
|
-
{ id: "c", label: "step-c", status: "pending", blockedBy: ["b"] },
|
|
245
|
-
{ id: "d", label: "step-d", status: "pending", blockedBy: ["c"] },
|
|
246
|
-
]);
|
|
247
|
-
// Nodes should have identical dimensions in both layouts (fixed-scale)
|
|
248
|
-
expect(single.nodes[0].width).toBe(many.nodes[0].width);
|
|
249
|
-
expect(single.nodes[0].height).toBe(many.nodes[0].height);
|
|
250
|
-
// Multi-node layout should be wider
|
|
251
|
-
expect(many.width).toBeGreaterThan(single.width);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("ignores blockedBy references to non-existent steps", () => {
|
|
255
|
-
const steps: FlowGraphStep[] = [
|
|
256
|
-
{ id: "a", label: "step-a", status: "pending", blockedBy: ["nonexistent"] },
|
|
257
|
-
];
|
|
258
|
-
|
|
259
|
-
const result = computeLayout(steps);
|
|
260
|
-
expect(result.nodes).toHaveLength(1);
|
|
261
|
-
expect(result.edges).toHaveLength(0); // no edge for missing dep
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it("preserves type field on positioned nodes", () => {
|
|
265
|
-
const steps: FlowGraphStep[] = [
|
|
266
|
-
{ id: "a", label: "agent-step", status: "pending", blockedBy: [], type: "agent" },
|
|
267
|
-
{ id: "b", label: "decision-step", status: "pending", blockedBy: ["a"], type: "code-decision" },
|
|
268
|
-
];
|
|
269
|
-
|
|
270
|
-
const result = computeLayout(steps);
|
|
271
|
-
expect(result.nodes.find(n => n.id === "a")!.type).toBe("agent");
|
|
272
|
-
expect(result.nodes.find(n => n.id === "b")!.type).toBe("code-decision");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("renders forward decision-branch edges with labels while running", () => {
|
|
276
|
-
const steps: FlowGraphStep[] = [
|
|
277
|
-
{ id: "choose", label: "choose", status: "running", blockedBy: [], type: "fork", branches: { PathA: "a", PathB: "b" } },
|
|
278
|
-
{ id: "a", label: "a", status: "pending", blockedBy: [] },
|
|
279
|
-
{ id: "b", label: "b", status: "pending", blockedBy: [] },
|
|
280
|
-
];
|
|
281
|
-
const result = computeLayout(steps);
|
|
282
|
-
const labels = result.edges.map(e => e.label).sort();
|
|
283
|
-
expect(result.edges).toHaveLength(2);
|
|
284
|
-
expect(labels).toEqual(["PathA", "PathB"]);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it("marks a backward branch as a loop edge, routed by dagre (not a hand-arc)", () => {
|
|
288
|
-
const steps: FlowGraphStep[] = [
|
|
289
|
-
{ id: "work", label: "work", status: "complete", blockedBy: [] },
|
|
290
|
-
{ id: "gate", label: "gate", status: "running", blockedBy: ["work"], type: "code-decision", branches: { again: "work", go: "done" } },
|
|
291
|
-
{ id: "done", label: "done", status: "pending", blockedBy: [] },
|
|
292
|
-
];
|
|
293
|
-
const result = computeLayout(steps);
|
|
294
|
-
// Backward branch gate->work is a loop-styled edge (isLoop), routed by dagre.
|
|
295
|
-
const loop = result.edges.find(e => e.source === "gate" && e.target === "work");
|
|
296
|
-
expect(loop).toBeTruthy();
|
|
297
|
-
expect(loop!.isLoop).toBe(true);
|
|
298
|
-
expect(loop!.label).toBe("again");
|
|
299
|
-
expect(loop!.points.length).toBeGreaterThanOrEqual(2);
|
|
300
|
-
// forward branch gate->done carries its label and is not a loop.
|
|
301
|
-
const fwd = result.edges.find(e => e.source === "gate" && e.target === "done");
|
|
302
|
-
expect(fwd?.label).toBe("go");
|
|
303
|
-
expect(fwd?.isLoop).toBeFalsy();
|
|
304
|
-
});
|
|
305
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Group 6 (wire-flow-inputs-in-automation) — FlowInputWiring: reads a flow's
|
|
3
|
-
* declared inputs, binds each to a literal or the trigger value, writes only
|
|
4
|
-
* payload.inputs, and drops orphan keys when the selected flow changes.
|
|
5
|
-
*/
|
|
6
|
-
import React, { useState } from "react";
|
|
7
|
-
import { describe, it, expect, afterEach, beforeEach, vi } from "vitest";
|
|
8
|
-
import { render, cleanup, fireEvent, waitFor } from "@testing-library/react";
|
|
9
|
-
import { FlowInputWiring } from "../client/FlowInputWiring.js";
|
|
10
|
-
|
|
11
|
-
const INPUTS: Record<string, Array<{ name: string; type: string; required: boolean }>> = {
|
|
12
|
-
"ns:a": [
|
|
13
|
-
{ name: "invoice", type: "string", required: true },
|
|
14
|
-
{ name: "priority", type: "number", required: false },
|
|
15
|
-
],
|
|
16
|
-
"ns:b": [{ name: "region", type: "string", required: false }],
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
global.fetch = vi.fn((url: string) => {
|
|
21
|
-
const flow = new URL(url, "http://x").searchParams.get("flow") ?? "";
|
|
22
|
-
return Promise.resolve({
|
|
23
|
-
ok: true,
|
|
24
|
-
json: () => Promise.resolve({ inputs: INPUTS[flow] ?? [] }),
|
|
25
|
-
}) as unknown as Promise<Response>;
|
|
26
|
-
}) as unknown as typeof fetch;
|
|
27
|
-
});
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
cleanup();
|
|
30
|
-
vi.restoreAllMocks();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/** Controlled harness so onChange feeds back into payload (real re-render loop). */
|
|
34
|
-
function Harness({ startFlow }: { startFlow: string }) {
|
|
35
|
-
const [payload, setPayload] = useState<Record<string, unknown>>({ flow: startFlow });
|
|
36
|
-
return (
|
|
37
|
-
<div>
|
|
38
|
-
<button data-testid="switch-b" onClick={() => setPayload((p) => ({ ...p, flow: "ns:b" }))}>
|
|
39
|
-
switch
|
|
40
|
-
</button>
|
|
41
|
-
<FlowInputWiring payload={payload} onChange={setPayload} cwd="/repo" />
|
|
42
|
-
<pre data-testid="payload">{JSON.stringify(payload)}</pre>
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function payloadOf(getByTestId: (id: string) => HTMLElement): Record<string, unknown> {
|
|
48
|
-
return JSON.parse(getByTestId("payload").textContent || "{}");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
describe("FlowInputWiring", () => {
|
|
52
|
-
it("renders one row per declared flow input", async () => {
|
|
53
|
-
const { getByTestId } = render(<Harness startFlow="ns:a" />);
|
|
54
|
-
await waitFor(() => expect(getByTestId("flow-input-invoice")).toBeTruthy());
|
|
55
|
-
expect(getByTestId("flow-input-priority")).toBeTruthy();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("binding a row to the trigger writes ${{trigger}} into payload.inputs", async () => {
|
|
59
|
-
const { getByTestId } = render(<Harness startFlow="ns:a" />);
|
|
60
|
-
await waitFor(() => expect(getByTestId("flow-input-invoice-mode-trigger")).toBeTruthy());
|
|
61
|
-
fireEvent.click(getByTestId("flow-input-invoice-mode-trigger"));
|
|
62
|
-
await waitFor(() => {
|
|
63
|
-
const inputs = payloadOf(getByTestId).inputs as Record<string, unknown>;
|
|
64
|
-
expect(inputs.invoice).toBe("${{trigger}}");
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("a typed number literal persists as a number", async () => {
|
|
69
|
-
const { getByTestId } = render(<Harness startFlow="ns:a" />);
|
|
70
|
-
await waitFor(() => expect(getByTestId("flow-input-priority")).toBeTruthy());
|
|
71
|
-
fireEvent.change(getByTestId("flow-input-priority"), { target: { value: "5" } });
|
|
72
|
-
await waitFor(() => {
|
|
73
|
-
const inputs = payloadOf(getByTestId).inputs as Record<string, unknown>;
|
|
74
|
-
expect(inputs.priority).toBe(5);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("dropping to a new flow prunes orphan wired keys", async () => {
|
|
79
|
-
const { getByTestId } = render(<Harness startFlow="ns:a" />);
|
|
80
|
-
await waitFor(() => expect(getByTestId("flow-input-invoice-mode-trigger")).toBeTruthy());
|
|
81
|
-
fireEvent.click(getByTestId("flow-input-invoice-mode-trigger"));
|
|
82
|
-
await waitFor(() => expect((payloadOf(getByTestId).inputs as any).invoice).toBe("${{trigger}}"));
|
|
83
|
-
// Switch to a flow that does not declare `invoice`.
|
|
84
|
-
fireEvent.click(getByTestId("switch-b"));
|
|
85
|
-
await waitFor(() => {
|
|
86
|
-
const inputs = (payloadOf(getByTestId).inputs as Record<string, unknown>) ?? {};
|
|
87
|
-
expect(inputs.invoice).toBeUndefined();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("renders nothing for a flow with no declared inputs", async () => {
|
|
92
|
-
const { queryByTestId } = render(<Harness startFlow="ns:none" />);
|
|
93
|
-
await waitFor(() => expect(global.fetch).toHaveBeenCalled());
|
|
94
|
-
await Promise.resolve();
|
|
95
|
-
expect(queryByTestId("flow-input-wiring")).toBeNull();
|
|
96
|
-
});
|
|
97
|
-
});
|