@blackbelt-technology/pi-dashboard-flows-plugin 0.7.0 → 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.
Files changed (39) hide show
  1. package/package.json +13 -5
  2. package/src/client/FlowAgentCard.tsx +4 -8
  3. package/src/client/FlowAgentDetail.tsx +1 -1
  4. package/src/client/FlowDashboard.tsx +6 -2
  5. package/src/client/FlowInputWiring.tsx +2 -2
  6. package/src/client/FlowsCommandRoutes.tsx +13 -5
  7. package/src/client/FlowsSettings.tsx +4 -4
  8. package/src/client/SessionFlowActions.tsx +9 -4
  9. package/src/client/format-cost.ts +21 -0
  10. package/src/client/send-safe.ts +19 -0
  11. package/src/AGENTS.md +0 -8
  12. package/src/__tests__/FlowGraph.test.ts +0 -305
  13. package/src/__tests__/FlowInputWiring.test.tsx +0 -97
  14. package/src/__tests__/FlowSummary.test.tsx +0 -331
  15. package/src/__tests__/FlowYamlPreview.test.tsx +0 -75
  16. package/src/__tests__/FlowsSessionStateContext.test.tsx +0 -223
  17. package/src/__tests__/FlowsUiStateContext.test.tsx +0 -140
  18. package/src/__tests__/authoring-renderers.test.tsx +0 -190
  19. package/src/__tests__/automation-actions.test.ts +0 -117
  20. package/src/__tests__/flow-agent-card-code-source.test.tsx +0 -190
  21. package/src/__tests__/flow-agent-cost.test.tsx +0 -160
  22. package/src/__tests__/flow-agent-error.test.ts +0 -60
  23. package/src/__tests__/flow-collapse-storage.test.ts +0 -90
  24. package/src/__tests__/flow-edges.test.ts +0 -195
  25. package/src/__tests__/flow-inputs.test.ts +0 -69
  26. package/src/__tests__/flow-reducer-bridge-contract.test.ts +0 -108
  27. package/src/__tests__/flow-reducer-seed-on-start.test.ts +0 -61
  28. package/src/__tests__/flow-yaml-parse.test.ts +0 -124
  29. package/src/__tests__/flows-for-cwd.test.ts +0 -51
  30. package/src/__tests__/flowsAvailability.test.ts +0 -79
  31. package/src/__tests__/manifest-discoverability.test.ts +0 -97
  32. package/src/__tests__/node-kind-reducer.test.ts +0 -135
  33. package/src/__tests__/plugin-action-handler.test.ts +0 -54
  34. package/src/__tests__/reducer-parity.test.ts +0 -106
  35. package/src/__tests__/render-actions.test.ts +0 -63
  36. package/src/__tests__/session-flow-actions-edit.test.tsx +0 -98
  37. package/src/bridge/AGENTS.md +0 -8
  38. package/src/client/AGENTS.md +0 -32
  39. package/src/server/AGENTS.md +0 -10
@@ -1,195 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { deriveFlowEdges, type FlowEdgeStep } from "../client/flow-edges.js";
3
-
4
- const key = (e: { from: string; to: string }) => `${e.from}->${e.to}`;
5
-
6
- describe("deriveFlowEdges", () => {
7
- it("derives the four edge classes", () => {
8
- const steps: FlowEdgeStep[] = [
9
- { id: "a", type: "agent", blockedBy: [] },
10
- { id: "b", type: "code", blockedBy: ["a"], onComplete: "d" }, // sequential a->b, route b->d
11
- { id: "d", type: "code-decision", blockedBy: ["b"], branches: { again: "b" } }, // branch d->b (back)
12
- { id: "sep", type: "fork", blockedBy: ["d"] },
13
- { id: "e", type: "agent", blockedBy: [] }, // implicit sep->e (no other incoming)
14
- ];
15
- const edges = deriveFlowEdges(steps);
16
- const byKey = new Map(edges.map((e) => [key(e), e]));
17
-
18
- expect(byKey.get("a->b")?.kind).toBe("sequential");
19
- expect(byKey.get("d->b")?.kind).toBe("branch");
20
- expect(byKey.get("d->b")?.label).toBe("again");
21
- expect(byKey.get("sep->e")?.kind).toBe("implicit");
22
- expect(byKey.get("b->d")?.kind).toBe("route");
23
- });
24
-
25
- it("does not serialize parallel siblings (no separator predecessor)", () => {
26
- // Three roots with no blockedBy and no separator between them: the engine
27
- // runs all three in wave 1 (parallel). No implicit chain should be drawn.
28
- const steps: FlowEdgeStep[] = [
29
- { id: "a", type: "agent", blockedBy: [] },
30
- { id: "impl", type: "agent", blockedBy: [] },
31
- { id: "docs", type: "agent", blockedBy: [] },
32
- ];
33
- const edges = deriveFlowEdges(steps);
34
- expect(edges).toHaveLength(0);
35
- });
36
-
37
- it("keeps the implicit edge across a separator boundary", () => {
38
- // A step with no blockedBy immediately after a separator falls through from it.
39
- const steps: FlowEdgeStep[] = [
40
- { id: "decide", type: "code-decision", blockedBy: [] },
41
- { id: "next", type: "agent", blockedBy: [] },
42
- ];
43
- const edges = deriveFlowEdges(steps);
44
- expect(edges.find((e) => key(e) === "decide->next")?.kind).toBe("implicit");
45
- });
46
-
47
- it("fans all no-blockedBy roots out from the preceding separator (parallel)", () => {
48
- // Two parallel roots after one separator: BOTH fall through from the
49
- // separator (parallel), not chained b->c.
50
- const steps: FlowEdgeStep[] = [
51
- { id: "sep", type: "fork", blockedBy: [] },
52
- { id: "b", type: "agent", blockedBy: [] },
53
- { id: "c", type: "agent", blockedBy: [] },
54
- ];
55
- const edges = deriveFlowEdges(steps);
56
- expect(edges.find((e) => key(e) === "sep->b")?.kind).toBe("implicit");
57
- expect(edges.find((e) => key(e) === "sep->c")?.kind).toBe("implicit");
58
- expect(edges.some((e) => key(e) === "b->c")).toBe(false);
59
- });
60
-
61
- it("flags backward edges", () => {
62
- const steps: FlowEdgeStep[] = [
63
- { id: "work", type: "agent", blockedBy: [] },
64
- { id: "gate", type: "code-decision", blockedBy: ["work"], branches: { again: "work", go: "done" } },
65
- { id: "done", type: "agent", blockedBy: [] },
66
- ];
67
- const edges = deriveFlowEdges(steps);
68
- const back = edges.find((e) => key(e) === "gate->work")!;
69
- const fwd = edges.find((e) => key(e) === "gate->done")!;
70
- expect(back.backward).toBe(true);
71
- expect(fwd.backward).toBe(false);
72
- });
73
-
74
- it("collapses duplicate {from,to}, preferring labeled branch", () => {
75
- const steps: FlowEdgeStep[] = [
76
- { id: "a", type: "fork", blockedBy: [], branches: { x: "b" } },
77
- { id: "b", type: "agent", blockedBy: ["a"] }, // sequential a->b AND branch a->b
78
- ];
79
- const edges = deriveFlowEdges(steps);
80
- const ab = edges.filter((e) => key(e) === "a->b");
81
- expect(ab).toHaveLength(1);
82
- expect(ab[0].kind).toBe("branch");
83
- expect(ab[0].label).toBe("x");
84
- });
85
-
86
- it("emits route edges only when onComplete/onError present", () => {
87
- const withRoute = deriveFlowEdges([
88
- { id: "a", type: "code", blockedBy: [], onComplete: "b" },
89
- { id: "b", type: "agent", blockedBy: [] },
90
- ]);
91
- expect(withRoute.find((e) => key(e) === "a->b")?.kind).toBe("route");
92
-
93
- const liveNoRoute = deriveFlowEdges([
94
- { id: "a", type: "code", blockedBy: [] },
95
- { id: "b", type: "agent", blockedBy: [] },
96
- ]);
97
- expect(liveNoRoute.some((e) => e.kind === "route")).toBe(false);
98
- });
99
-
100
- it("classifies an on_error route as returning when the handler rejoins the flow", () => {
101
- const steps: FlowEdgeStep[] = [
102
- { id: "validate", type: "code-decision", blockedBy: [], onError: "fixup" },
103
- { id: "transform", type: "agent", blockedBy: ["validate"] },
104
- { id: "fixup", type: "agent", blockedBy: [], onComplete: "validate" }, // rejoins the spine
105
- ];
106
- const r = deriveFlowEdges(steps).find((e) => key(e) === "validate->fixup")!;
107
- expect(r.kind).toBe("route");
108
- expect(r.label).toBe("on_error");
109
- expect(r.routeTopology).toBe("returning");
110
- });
111
-
112
- it("classifies an on_error route as terminal when the handler never rejoins", () => {
113
- const steps: FlowEdgeStep[] = [
114
- { id: "finalize", type: "agent", blockedBy: [], onError: "notify" },
115
- { id: "notify", type: "agent", blockedBy: [] }, // sink: no forward edge back to the flow
116
- ];
117
- const r = deriveFlowEdges(steps).find((e) => key(e) === "finalize->notify")!;
118
- expect(r.kind).toBe("route");
119
- expect(r.routeTopology).toBe("terminal");
120
- });
121
-
122
- it("leaves routeTopology unset on non-on_error routes", () => {
123
- const edges = deriveFlowEdges([
124
- { id: "a", type: "code", blockedBy: [], onComplete: "b" },
125
- { id: "b", type: "agent", blockedBy: [] },
126
- ]);
127
- const oc = edges.find((e) => key(e) === "a->b")!;
128
- expect(oc.kind).toBe("route");
129
- expect(oc.routeTopology).toBeUndefined();
130
- });
131
-
132
- it("skips edges with missing endpoints", () => {
133
- const edges = deriveFlowEdges([
134
- { id: "a", type: "agent", blockedBy: ["ghost"], branches: { x: "nowhere" } },
135
- ]);
136
- expect(edges).toHaveLength(0);
137
- });
138
-
139
- // Regression: a flow wired entirely via on_complete (no blockedBy), with a
140
- // routing step declared BEFORE any separator — the InvoiceBot `process` shape.
141
- // The pre-separator root must NOT be orphaned, and a routing target must not
142
- // also get a spurious implicit edge from the nearest separator.
143
- // See change: fix-flow-ui-graph-zoom-summary.
144
- it("on_complete-routed pre-separator root is connected (no orphan)", () => {
145
- const steps: FlowEdgeStep[] = [
146
- { id: "load-state", type: "code", blockedBy: [], onComplete: "resume-gate", onError: "hold" },
147
- { id: "resume-gate", type: "code-decision", blockedBy: [], branches: { new: "intake" } },
148
- { id: "intake", type: "code", blockedBy: [], onComplete: "hold" },
149
- { id: "hold", type: "code", blockedBy: [] },
150
- ];
151
- const edges = deriveFlowEdges(steps);
152
- const byKey = new Map(edges.map((e) => [key(e), e]));
153
- // load-state routes forward (not orphaned) and to its error sink.
154
- expect(byKey.get("load-state->resume-gate")?.kind).toBe("route");
155
- expect(byKey.get("load-state->hold")?.kind).toBe("route");
156
- // load-state has at least one outgoing edge.
157
- expect(edges.some((e) => e.from === "load-state")).toBe(true);
158
- });
159
-
160
- it("routing target suppresses a spurious implicit edge", () => {
161
- // `intake` has no blockedBy but is the on_complete target of `gate`; it must
162
- // get the route edge and NOT also an implicit edge from the separator.
163
- const steps: FlowEdgeStep[] = [
164
- { id: "gate", type: "code-decision", blockedBy: [], onComplete: "intake" },
165
- { id: "intake", type: "code", blockedBy: [] },
166
- ];
167
- const edges = deriveFlowEdges(steps);
168
- const incoming = edges.filter((e) => e.to === "intake");
169
- expect(incoming).toHaveLength(1);
170
- expect(incoming[0].kind).toBe("route");
171
- });
172
-
173
- it("omitting routing fields produces no route edges (backward compat)", () => {
174
- const steps: FlowEdgeStep[] = [
175
- { id: "a", type: "code", blockedBy: [] },
176
- { id: "b", type: "code", blockedBy: [] },
177
- ];
178
- const edges = deriveFlowEdges(steps);
179
- expect(edges.some((e) => e.kind === "route")).toBe(false);
180
- });
181
-
182
- it("live (branches only) and static (branches + routes) agree on shared classes", () => {
183
- const base: FlowEdgeStep[] = [
184
- { id: "a", type: "agent", blockedBy: [] },
185
- { id: "fork", type: "fork", blockedBy: ["a"], branches: { p: "b", q: "c" } },
186
- { id: "b", type: "agent", blockedBy: [] },
187
- { id: "c", type: "agent", blockedBy: [] },
188
- ];
189
- const live = deriveFlowEdges(base);
190
- const staticEdges = deriveFlowEdges(base.map((s) => ({ ...s, onError: s.id === "b" ? "c" : undefined })));
191
- const sharedLive = live.filter((e) => e.kind !== "route").map(key).sort();
192
- const sharedStatic = staticEdges.filter((e) => e.kind !== "route").map(key).sort();
193
- expect(sharedLive).toEqual(sharedStatic);
194
- });
195
- });
@@ -1,69 +0,0 @@
1
- /**
2
- * Read-only flow input-schema reader tests.
3
- * See change: wire-flow-inputs-in-automation.
4
- */
5
-
6
- import fs from "node:fs";
7
- import os from "node:os";
8
- import path from "node:path";
9
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
10
- import { flowYamlPath, readFlowInputs } from "../server/flow-inputs.js";
11
-
12
- function writeFlow(cwd: string, ns: string, name: string, yaml: string): void {
13
- const dir = path.join(cwd, ".pi", "flows", "flows", ns, name);
14
- fs.mkdirSync(dir, { recursive: true });
15
- fs.writeFileSync(path.join(dir, "flow.yaml"), yaml);
16
- }
17
-
18
- describe("readFlowInputs", () => {
19
- let cwd: string;
20
- beforeEach(() => {
21
- cwd = fs.mkdtempSync(path.join(os.tmpdir(), "flow-inputs-"));
22
- });
23
- afterEach(() => {
24
- fs.rmSync(cwd, { recursive: true, force: true });
25
- });
26
-
27
- it("returns declared typed inputs", () => {
28
- writeFlow(
29
- cwd,
30
- "invoicebot",
31
- "process",
32
- `name: invoicebot:process\ninputs:\n invoice: { type: string, required: true }\n priority: { type: number }\nsteps: []\n`,
33
- );
34
- expect(readFlowInputs(cwd, "invoicebot:process")).toEqual([
35
- { name: "invoice", type: "string", required: true },
36
- { name: "priority", type: "number", required: false },
37
- ]);
38
- });
39
-
40
- it("returns [] for a flow with no inputs", () => {
41
- writeFlow(cwd, "x", "y", `name: x:y\nsteps: []\n`);
42
- expect(readFlowInputs(cwd, "x:y")).toEqual([]);
43
- });
44
-
45
- it("returns [] for a missing flow / unparseable id", () => {
46
- expect(readFlowInputs(cwd, "no:such")).toEqual([]);
47
- expect(readFlowInputs(cwd, "malformed-id")).toEqual([]);
48
- });
49
-
50
- it("skips invalid input rows, keeps valid ones", () => {
51
- writeFlow(
52
- cwd,
53
- "a",
54
- "b",
55
- `name: a:b\ninputs:\n good: { type: boolean }\n bad: { type: nonsense }\n alsoBad: "notamapping"\nsteps: []\n`,
56
- );
57
- expect(readFlowInputs(cwd, "a:b")).toEqual([{ name: "good", type: "boolean", required: false }]);
58
- });
59
-
60
- it("does not write any flow file (read-only)", () => {
61
- writeFlow(cwd, "a", "b", `name: a:b\ninputs:\n f: { type: string }\nsteps: []\n`);
62
- const p = flowYamlPath(cwd, "a:b")!;
63
- const before = fs.statSync(p).mtimeMs;
64
- readFlowInputs(cwd, "a:b");
65
- expect(fs.statSync(p).mtimeMs).toBe(before);
66
- // no stray files created under the flow dir
67
- expect(fs.readdirSync(path.dirname(p))).toEqual(["flow.yaml"]);
68
- });
69
- });
@@ -1,108 +0,0 @@
1
- /**
2
- * L2 contract-pinned bridge-forward + reducer coverage.
3
- *
4
- * The dashboard bridge forwards pi-flows `flow:*` events to the dashboard
5
- * protocol via `FLOW_EVENT_MAP` (packages/extension/src/flow-event-wiring.ts);
6
- * the flows-plugin reducer consumes the mapped `flow_*` types. This test PINS
7
- * the reducer to that map: event types are read from `FLOW_EVENT_MAP` VALUES
8
- * (never hand-typed literals), so a pi-flows rename that updates the map
9
- * propagates here, and a reducer that stops handling a core lifecycle event
10
- * fails loudly.
11
- *
12
- * Hermetic by design (design D2): no browser, no network, no runtime
13
- * dependency on pi-flows. Real-engine event fidelity is covered at L3 (the
14
- * Docker harness), where pi-flows is genuinely installed.
15
- */
16
-
17
- import type { DashboardEvent, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
18
- import { describe, expect, it } from "vitest";
19
- // Relative import into the extension package source: vitest maps the `.js`
20
- // specifier to the `.ts` source. This is the CONTRACT PIN — the same map the
21
- // bridge forwards through at runtime.
22
- import { FLOW_EVENT_MAP } from "../../../extension/src/flow-event-wiring.js";
23
- import { reduceFlowEvent } from "../reducer.js";
24
-
25
- function ev(type: string, data: Record<string, unknown>): DashboardEvent {
26
- return { seq: 1, timestamp: 0, sessionId: "s1", eventType: type, data } as unknown as DashboardEvent;
27
- }
28
-
29
- // Event types resolved FROM the map (pin). If pi-flows renames an event and the
30
- // bridge map updates, these follow automatically.
31
- const T_STARTED = FLOW_EVENT_MAP["flow:flow-started"];
32
- const T_AGENT_STARTED = FLOW_EVENT_MAP["flow:agent-started"];
33
- const T_AGENT_COMPLETE = FLOW_EVENT_MAP["flow:agent-complete"];
34
- const T_COMPLETE = FLOW_EVENT_MAP["flow:complete"];
35
-
36
- describe("flow reducer × bridge FLOW_EVENT_MAP contract", () => {
37
- it("the map exposes the core lifecycle event types", () => {
38
- expect(T_STARTED).toBe("flow_started");
39
- expect(T_AGENT_STARTED).toBe("flow_agent_started");
40
- expect(T_AGENT_COMPLETE).toBe("flow_agent_complete");
41
- expect(T_COMPLETE).toBe("flow_complete");
42
- });
43
-
44
- it("a contract-pinned lifecycle reduces to a terminal flow + agent state", () => {
45
- let s: FlowState | null = null;
46
- s = reduceFlowEvent(s, ev(T_STARTED, {
47
- flowName: "contract",
48
- task: "t",
49
- steps: [{ id: "s1", stepType: "agent", agent: "a1", blockedBy: [] }],
50
- }));
51
- expect(s?.status).toBe("running");
52
- s = reduceFlowEvent(s, ev(T_AGENT_STARTED, { agentName: "a1", stepId: "s1" }));
53
- s = reduceFlowEvent(s, ev(T_AGENT_COMPLETE, {
54
- agentName: "a1",
55
- stepId: "s1",
56
- result: { success: true, status: "complete", tokens: { input: 1, output: 1 } },
57
- }));
58
- expect(s?.agents.get("s1")?.status).toBe("complete");
59
- s = reduceFlowEvent(s, ev(T_COMPLETE, { status: "success" }));
60
- expect(s?.status).toBe("success");
61
- });
62
-
63
- it("the reducer never throws on ANY mapped flow_* value (default passthrough)", () => {
64
- // Seed a state so post-start cases have something to fold into.
65
- const seeded = reduceFlowEvent(null, ev(T_STARTED, {
66
- flowName: "f",
67
- task: "t",
68
- steps: [{ id: "s1", stepType: "agent", agent: "a1", blockedBy: [] }],
69
- }));
70
- for (const mappedType of Object.values(FLOW_EVENT_MAP)) {
71
- expect(() => reduceFlowEvent(seeded, ev(mappedType, {}))).not.toThrow();
72
- }
73
- });
74
-
75
- it("a mapped event without a dedicated case leaves state unchanged", () => {
76
- const seeded = reduceFlowEvent(null, ev(T_STARTED, {
77
- flowName: "f",
78
- task: "t",
79
- steps: [{ id: "s1", stepType: "agent", agent: "a1", blockedBy: [] }],
80
- }));
81
- // flow_summary_started is mapped but intentionally has no reducer case.
82
- const passthrough = FLOW_EVENT_MAP["flow:summary-started"];
83
- expect(passthrough).toBe("flow_summary_started");
84
- expect(reduceFlowEvent(seeded, ev(passthrough, {}))).toBe(seeded);
85
- });
86
-
87
- it("each core lifecycle event produces an observable mutation (no silent drop)", () => {
88
- const started = reduceFlowEvent(null, ev(T_STARTED, {
89
- flowName: "f",
90
- task: "t",
91
- steps: [{ id: "s1", stepType: "agent", agent: "a1", blockedBy: [] }],
92
- }));
93
- expect(started).not.toBeNull(); // flow_started seeds
94
-
95
- const agentStarted = reduceFlowEvent(started, ev(T_AGENT_STARTED, { agentName: "a1", stepId: "s1" }));
96
- expect(agentStarted).not.toBe(started); // new state object
97
-
98
- const agentComplete = reduceFlowEvent(agentStarted, ev(T_AGENT_COMPLETE, {
99
- agentName: "a1",
100
- stepId: "s1",
101
- result: { success: true, status: "complete" },
102
- }));
103
- expect(agentComplete?.agents.get("s1")?.status).toBe("complete");
104
-
105
- const complete = reduceFlowEvent(agentComplete, ev(T_COMPLETE, { status: "success" }));
106
- expect(complete?.status).toBe("success");
107
- });
108
- });
@@ -1,61 +0,0 @@
1
- /**
2
- * Seed-on-start coverage for the flows-plugin reducer.
3
- *
4
- * Regression guard: FlowState is seeded ONLY by the initial `flow_started`
5
- * event. Every other event returns null when no start was observed, so a
6
- * client that connects mid-flow (missing the start) renders nothing rather
7
- * than fabricating state from a progression event. Once seeded, progression
8
- * events advance status and drive agents to a terminal state.
9
- */
10
-
11
- import type { DashboardEvent, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
12
- import { describe, expect, it } from "vitest";
13
- import { reduceFlowEvent } from "../reducer.js";
14
-
15
- function ev(type: string, data: Record<string, unknown>): DashboardEvent {
16
- return { seq: 1, timestamp: 0, sessionId: "s1", eventType: type, data } as unknown as DashboardEvent;
17
- }
18
-
19
- function fold(events: Array<[string, Record<string, unknown>]>): FlowState | null {
20
- let s: FlowState | null = null;
21
- for (const [t, d] of events) s = reduceFlowEvent(s, ev(t, d));
22
- return s;
23
- }
24
-
25
- describe("flow reducer seed-on-start", () => {
26
- it("returns null for a progression event with no prior start", () => {
27
- expect(reduceFlowEvent(null, ev("flow_agent_complete", { agentName: "a", stepId: "s1" }))).toBeNull();
28
- expect(reduceFlowEvent(null, ev("flow_agent_started", { agentName: "a", stepId: "s1" }))).toBeNull();
29
- });
30
-
31
- it("seeds state on flow_started and advances through progression", () => {
32
- const state = fold([
33
- ["flow_started", {
34
- flowName: "invoice",
35
- task: "validate",
36
- steps: [{ id: "s1", stepType: "agent", agent: "extractor", blockedBy: [] }],
37
- }],
38
- ["flow_agent_started", { agentName: "extractor", stepId: "s1" }],
39
- ["flow_agent_complete", { agentName: "extractor", stepId: "s1", status: "complete" }],
40
- ]);
41
- expect(state).not.toBeNull();
42
- expect(state?.flowName).toBe("invoice");
43
- const agent = state?.agents.get("s1");
44
- expect(agent).toBeDefined();
45
- expect(["complete", "error", "blocked"]).toContain(agent?.status);
46
- });
47
-
48
- it("drops events that arrive before the start even if a later start appears with no prior state", () => {
49
- // A stray progression event against null stays null; the subsequent start
50
- // still seeds cleanly (no residue from the dropped event).
51
- const afterStray = reduceFlowEvent(null, ev("flow_agent_started", { agentName: "x", stepId: "s1" }));
52
- expect(afterStray).toBeNull();
53
- const seeded = reduceFlowEvent(afterStray, ev("flow_started", {
54
- flowName: "f",
55
- task: "t",
56
- steps: [{ id: "s1", stepType: "agent", agent: "x", blockedBy: [] }],
57
- }));
58
- expect(seeded?.status).toBe("running");
59
- expect(seeded?.agents.get("s1")?.status).toBe("pending");
60
- });
61
- });
@@ -1,124 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { flowToMermaid, parseFlowYaml } from "../client/flow-yaml-parse.js";
3
-
4
- const YAML = `
5
- name: invoice-research
6
- steps:
7
- - id: extract
8
- type: agent
9
- agent: extractor
10
- blockedBy: []
11
- on_complete: validate-nav
12
- - id: validate-nav
13
- type: code
14
- blockedBy: [extract]
15
- on_error: park
16
- - id: approve
17
- type: code-decision
18
- blockedBy: [validate-nav]
19
- branches:
20
- auto: export
21
- rework: extract
22
- - id: export
23
- type: agent
24
- agent: exporter
25
- blockedBy: [approve]
26
- `;
27
-
28
- describe("parseFlowYaml", () => {
29
- it("parses steps + counts", () => {
30
- const flow = parseFlowYaml(YAML)!;
31
- expect(flow.name).toBe("invoice-research");
32
- expect(flow.counts.total).toBe(4);
33
- expect(flow.counts.agents).toBe(2); // extract, export
34
- expect(flow.counts.code).toBe(2); // validate-nav, approve
35
- expect(flow.steps.find((s) => s.id === "approve")?.branches).toEqual({ auto: "export", rework: "extract" });
36
- });
37
-
38
- it("returns null on invalid YAML / no steps", () => {
39
- expect(parseFlowYaml(":::not yaml:::")).toBeNull();
40
- expect(parseFlowYaml("name: x")).toBeNull();
41
- });
42
-
43
- it("defaults missing type to agent", () => {
44
- const flow = parseFlowYaml("steps:\n - id: a\n blockedBy: []")!;
45
- expect(flow.steps[0].type).toBe("agent");
46
- });
47
- });
48
-
49
- describe("flowToMermaid", () => {
50
- it("emits graph LR with node shapes + forward and backward edges", () => {
51
- const flow = parseFlowYaml(YAML)!;
52
- const m = flowToMermaid(flow);
53
- expect(m.startsWith("graph LR")).toBe(true);
54
- expect(m).toContain('validate-nav[["⌗ validate-nav"]]'); // code shape
55
- expect(m).toContain('approve{"◈ approve"}'); // code-decision shape
56
- expect(m).toContain("approve -->|auto| export"); // forward branch
57
- expect(m).toContain('approve -. "rework ↺" .-> extract'); // backward branch (loop)
58
- });
59
-
60
- it("renders on_complete routing edges UNLABELED (happy-path default)", () => {
61
- // Policy (change: fix-flow-ui-graph-zoom-summary): an `on_complete` route is
62
- // the happy path — render as a plain arrow, never `|on_complete|`, so an
63
- // on_complete-wired flow's spine isn't labelled on every edge.
64
- const flow = parseFlowYaml(YAML)!;
65
- const m = flowToMermaid(flow);
66
- // extract.on_complete=validate-nav AND validate-nav.blockedBy=[extract] -> one route edge, unlabeled
67
- expect(m).toContain("extract --> validate-nav");
68
- expect(m).not.toContain("extract -->|on_complete| validate-nav");
69
- expect(m).not.toContain("|on_complete|");
70
- // on_error -> park, but no `park` step exists -> edge skipped
71
- expect(m).not.toContain("park");
72
- });
73
-
74
- it("renders on_error routes topology-distinctly (returning ↺ vs terminal ⊗)", () => {
75
- const flow = parseFlowYaml(`
76
- name: topo
77
- steps:
78
- - id: validate
79
- type: code-decision
80
- blockedBy: []
81
- on_error: fixup
82
- - id: transform
83
- type: agent
84
- blockedBy: [validate]
85
- - id: fixup
86
- type: agent
87
- blockedBy: []
88
- on_complete: validate
89
- - id: finalize
90
- type: agent
91
- blockedBy: [transform]
92
- on_error: notify
93
- - id: notify
94
- type: agent
95
- blockedBy: []
96
- `)!;
97
- const m = flowToMermaid(flow);
98
- // returning handler (fixup rejoins validate) → dashed loop marker
99
- expect(m).toContain('validate -. "on_error ↺" .-> fixup');
100
- // terminal handler (notify is a sink) → dashed terminal marker
101
- expect(m).toContain('finalize -. "on_error ⊗" .-> notify');
102
- // an on_error route is never rendered as a solid labeled forward edge
103
- expect(m).not.toContain("-->|on_error|");
104
- });
105
-
106
- it("renders implicit-segment edges and emits no flow-ref shape", () => {
107
- const flow = parseFlowYaml(`
108
- name: seg
109
- steps:
110
- - id: decide
111
- type: fork
112
- branches: { go: end }
113
- - id: orphan
114
- type: agent
115
- - id: end
116
- type: agent
117
- `)!;
118
- const m = flowToMermaid(flow);
119
- // `orphan` has no blockedBy and no incoming edge -> implicit edge from the
120
- // preceding separator `decide`.
121
- expect(m).toContain("decide --> orphan");
122
- expect(m).not.toContain("[[\"orphan");
123
- });
124
- });
@@ -1,51 +0,0 @@
1
- /**
2
- * makeFlowsForCwd: resolves a folder cwd to the live per-session flows list
3
- * (stateStore, populated by the forwarded flows_list). Reflects package/event
4
- * flows a static disk scan would miss; empty with no matching running session.
5
- * See change: fix-automation-flow-detection.
6
- */
7
-
8
- import { describe, expect, it } from "vitest";
9
- import { makeFlowsForCwd } from "../server/index.js";
10
-
11
- function store(byId: Record<string, string[]>) {
12
- return {
13
- getState(id: string) {
14
- const names = byId[id];
15
- return names ? { flows: names.map((name) => ({ name })) } : undefined;
16
- },
17
- };
18
- }
19
-
20
- describe("makeFlowsForCwd", () => {
21
- it("returns the running session's flows for a matching cwd (package/event flows included)", () => {
22
- const sm = { listActive: () => [{ id: "s1", cwd: "/w/invoice-bot" }] };
23
- const resolve = makeFlowsForCwd(sm, store({ s1: ["invoicebot:pull", "invoicebot:process"] }));
24
- expect(resolve("/w/invoice-bot")).toEqual(["invoicebot:process", "invoicebot:pull"]);
25
- });
26
-
27
- it("returns [] when no active session matches the cwd", () => {
28
- const sm = { listActive: () => [{ id: "s1", cwd: "/w/other" }] };
29
- const resolve = makeFlowsForCwd(sm, store({ s1: ["a:b"] }));
30
- expect(resolve("/w/invoice-bot")).toEqual([]);
31
- });
32
-
33
- it("unions + de-dupes + sorts across multiple sessions in the same cwd", () => {
34
- const sm = {
35
- listActive: () => [
36
- { id: "s1", cwd: "/w/x" },
37
- { id: "s2", cwd: "/w/x" },
38
- ],
39
- };
40
- const resolve = makeFlowsForCwd(sm, store({ s1: ["ns:b", "ns:a"], s2: ["ns:a", "ns:c"] }));
41
- expect(resolve("/w/x")).toEqual(["ns:a", "ns:b", "ns:c"]);
42
- });
43
-
44
- it("tolerates malformed session entries and missing state", () => {
45
- const sm = {
46
- listActive: () => [null, { cwd: "/w/x" }, { id: 7, cwd: "/w/x" }, { id: "s1", cwd: "/w/x" }],
47
- };
48
- const resolve = makeFlowsForCwd(sm, store({})); // s1 has no state
49
- expect(resolve("/w/x")).toEqual([]);
50
- });
51
- });