@blackbelt-technology/pi-dashboard-flows-plugin 0.7.0 → 0.9.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 (54) hide show
  1. package/package.json +18 -7
  2. package/src/bridge/flow-files-reporter.ts +113 -0
  3. package/src/bridge/index.ts +5 -1
  4. package/src/client/FlowAgentCard.tsx +82 -213
  5. package/src/client/FlowAgentDetail.tsx +1 -1
  6. package/src/client/FlowDashboard.tsx +428 -66
  7. package/src/client/FlowInputWiring.tsx +2 -2
  8. package/src/client/FlowSummary.tsx +22 -16
  9. package/src/client/FlowYamlPopoverButton.tsx +27 -92
  10. package/src/client/FlowsCommandRoutes.tsx +13 -5
  11. package/src/client/FlowsSessionStateContext.tsx +40 -4
  12. package/src/client/FlowsSettings.tsx +4 -4
  13. package/src/client/SessionFlowActions.tsx +80 -6
  14. package/src/client/flow-attach-store.ts +140 -0
  15. package/src/client/flow-card-grid.ts +36 -0
  16. package/src/client/flow-files.ts +152 -0
  17. package/src/client/flow-idle-state.ts +230 -0
  18. package/src/client/format-cost.ts +21 -0
  19. package/src/client/send-safe.ts +19 -0
  20. package/src/flow-files-contract.ts +21 -0
  21. package/src/flow-reducer.ts +4 -0
  22. package/src/i18n.ts +28 -0
  23. package/src/server/automation-actions.ts +3 -0
  24. package/src/server/flow-files.ts +264 -0
  25. package/src/server/index.ts +15 -0
  26. package/src/AGENTS.md +0 -8
  27. package/src/__tests__/FlowGraph.test.ts +0 -305
  28. package/src/__tests__/FlowInputWiring.test.tsx +0 -97
  29. package/src/__tests__/FlowSummary.test.tsx +0 -331
  30. package/src/__tests__/FlowYamlPreview.test.tsx +0 -75
  31. package/src/__tests__/FlowsSessionStateContext.test.tsx +0 -223
  32. package/src/__tests__/FlowsUiStateContext.test.tsx +0 -140
  33. package/src/__tests__/authoring-renderers.test.tsx +0 -190
  34. package/src/__tests__/automation-actions.test.ts +0 -117
  35. package/src/__tests__/flow-agent-card-code-source.test.tsx +0 -190
  36. package/src/__tests__/flow-agent-cost.test.tsx +0 -160
  37. package/src/__tests__/flow-agent-error.test.ts +0 -60
  38. package/src/__tests__/flow-collapse-storage.test.ts +0 -90
  39. package/src/__tests__/flow-edges.test.ts +0 -195
  40. package/src/__tests__/flow-inputs.test.ts +0 -69
  41. package/src/__tests__/flow-reducer-bridge-contract.test.ts +0 -108
  42. package/src/__tests__/flow-reducer-seed-on-start.test.ts +0 -61
  43. package/src/__tests__/flow-yaml-parse.test.ts +0 -124
  44. package/src/__tests__/flows-for-cwd.test.ts +0 -51
  45. package/src/__tests__/flowsAvailability.test.ts +0 -79
  46. package/src/__tests__/manifest-discoverability.test.ts +0 -97
  47. package/src/__tests__/node-kind-reducer.test.ts +0 -135
  48. package/src/__tests__/plugin-action-handler.test.ts +0 -54
  49. package/src/__tests__/reducer-parity.test.ts +0 -106
  50. package/src/__tests__/render-actions.test.ts +0 -63
  51. package/src/__tests__/session-flow-actions-edit.test.tsx +0 -98
  52. package/src/bridge/AGENTS.md +0 -8
  53. package/src/client/AGENTS.md +0 -32
  54. package/src/server/AGENTS.md +0 -10
@@ -1,223 +0,0 @@
1
- /**
2
- * Tests for `reduceFlowsSessionState` and `useFlowsSessionState`.
3
- *
4
- * The pure reducer is tested with synthesized event sequences to verify
5
- * it matches the shell's pre-deletion behavior (event-reducer.ts:1292-1313)
6
- * exactly. The hook is smoke-tested via React rendering with a live
7
- * `useSessionEvents` subscription and direct calls to
8
- * `publishSessionEvent` to drive the event stream.
9
- *
10
- * See change: pluginize-flows-via-registry.
11
- */
12
- import React from "react";
13
- import { describe, it, expect, afterEach } from "vitest";
14
- import { render, act, cleanup } from "@testing-library/react";
15
- import {
16
- PluginContextProvider,
17
- publishSessionEvent,
18
- clearSessionEvents,
19
- } from "@blackbelt-technology/dashboard-plugin-runtime";
20
-
21
- // We don't import __resetSessionEventsStoreForTests across the package
22
- // boundary (it's marked @internal). Each test scopes events to a unique
23
- // session id, so isolation comes from the session-id namespace itself.
24
- let __testCounter = 0;
25
- function nextSessionId(): string { return `S-${++__testCounter}`; }
26
- import type { DashboardEvent } from "@blackbelt-technology/pi-dashboard-shared/types.js";
27
- import {
28
- reduceFlowsSessionState,
29
- useFlowsSessionState,
30
- type FlowsSessionState,
31
- } from "../client/FlowsSessionStateContext.js";
32
-
33
- // ── Event factories matching the real protocol shapes ──────────────
34
-
35
- function flowStartedEvent(seq: number, flowName = "build"): DashboardEvent {
36
- return {
37
- seq,
38
- timestamp: new Date(seq * 1000).toISOString(),
39
- eventType: "flow_started",
40
- data: {
41
- flowName,
42
- task: "test task",
43
- steps: [
44
- { id: "s1", stepType: "agent", agent: "alpha", blockedBy: [] },
45
- { id: "s2", stepType: "agent", agent: "beta", blockedBy: ["s1"] },
46
- ],
47
- },
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- } as any;
50
- }
51
-
52
- function flowSummaryDismissedEvent(seq: number): DashboardEvent {
53
- return {
54
- seq,
55
- timestamp: new Date(seq * 1000).toISOString(),
56
- eventType: "flow_summary_dismissed",
57
- data: {},
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- } as any;
60
- }
61
-
62
- function unrelatedEvent(seq: number): DashboardEvent {
63
- return {
64
- seq,
65
- timestamp: new Date(seq * 1000).toISOString(),
66
- eventType: "tool_start",
67
- data: { toolName: "Read" },
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- } as any;
70
- }
71
-
72
- // ── Pure reducer tests ─────────────────────────────────────────────
73
-
74
- describe("reduceFlowsSessionState (pure)", () => {
75
- it("returns the same EMPTY_STATE reference for empty input", () => {
76
- const a = reduceFlowsSessionState([]);
77
- const b = reduceFlowsSessionState([]);
78
- expect(a).toBe(b);
79
- expect(a.flowState).toBeNull();
80
- expect(a.flowStates.size).toBe(0);
81
- });
82
-
83
- it("returns EMPTY_STATE when no flow events are present", () => {
84
- const result = reduceFlowsSessionState([
85
- unrelatedEvent(1),
86
- unrelatedEvent(2),
87
- ]);
88
- expect(result.flowState).toBeNull();
89
- });
90
-
91
- it("derives flowState from a flow_started event", () => {
92
- const result = reduceFlowsSessionState([flowStartedEvent(1, "build")]);
93
- expect(result.flowState).not.toBeNull();
94
- expect(result.flowState!.flowName).toBe("build");
95
- expect(result.flowStates.size).toBe(1);
96
- expect(result.flowStates.get("build")).toBe(result.flowState);
97
- });
98
-
99
- it("clears flowStates on flow_summary_dismissed", () => {
100
- const result = reduceFlowsSessionState([
101
- flowStartedEvent(1, "build"),
102
- flowSummaryDismissedEvent(2),
103
- ]);
104
- // flow_summary_dismissed clears flowStates per
105
- // event-reducer.ts:1298-1300 behavior.
106
- expect(result.flowStates.size).toBe(0);
107
- });
108
-
109
- it("ignores unrelated events between flow events", () => {
110
- const result = reduceFlowsSessionState([
111
- flowStartedEvent(1, "build"),
112
- unrelatedEvent(2),
113
- unrelatedEvent(3),
114
- ]);
115
- expect(result.flowState!.flowName).toBe("build");
116
- });
117
- });
118
-
119
- // ── Hook tests (live useSessionEvents subscription) ────────────────
120
-
121
- function Probe({ sessionId, onSnapshot }: {
122
- sessionId: string;
123
- onSnapshot: (state: FlowsSessionState) => void;
124
- }) {
125
- const state = useFlowsSessionState(sessionId);
126
- onSnapshot(state);
127
- return (
128
- <div data-testid="probe">
129
- flow={state.flowState?.flowName ?? "(none)"}
130
- </div>
131
- );
132
- }
133
-
134
- describe("useFlowsSessionState (hook)", () => {
135
- afterEach(() => cleanup());
136
-
137
- it("returns EMPTY_STATE for a session with no events", () => {
138
- const snaps: FlowsSessionState[] = [];
139
- const sid = nextSessionId();
140
- render(
141
- <PluginContextProvider>
142
- <Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
143
- </PluginContextProvider>,
144
- );
145
- expect(snaps[0].flowState).toBeNull();
146
- });
147
-
148
- it("re-renders with derived state when a flow event arrives", () => {
149
- const snaps: FlowsSessionState[] = [];
150
- const sid = nextSessionId();
151
- const { getByTestId } = render(
152
- <PluginContextProvider>
153
- <Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
154
- </PluginContextProvider>,
155
- );
156
- expect(getByTestId("probe").textContent).toContain("flow=(none)");
157
-
158
- act(() => publishSessionEvent(sid, flowStartedEvent(1, "build")));
159
- expect(getByTestId("probe").textContent).toContain("flow=build");
160
- });
161
-
162
- it("scopes derived state per session", () => {
163
- const snapsA: FlowsSessionState[] = [];
164
- const snapsB: FlowsSessionState[] = [];
165
- const sidA = nextSessionId();
166
- const sidB = nextSessionId();
167
- render(
168
- <PluginContextProvider>
169
- <Probe sessionId={sidA} onSnapshot={(s) => snapsA.push(s)} />
170
- <Probe sessionId={sidB} onSnapshot={(s) => snapsB.push(s)} />
171
- </PluginContextProvider>,
172
- );
173
-
174
- act(() => publishSessionEvent(sidA, flowStartedEvent(1, "alpha-flow")));
175
- act(() => publishSessionEvent(sidB, flowStartedEvent(2, "beta-flow")));
176
-
177
- const lastA = snapsA[snapsA.length - 1];
178
- const lastB = snapsB[snapsB.length - 1];
179
- expect(lastA.flowState!.flowName).toBe("alpha-flow");
180
- expect(lastB.flowState!.flowName).toBe("beta-flow");
181
- });
182
-
183
- it("returns a stable state reference across renders that don't change events", () => {
184
- const snaps: FlowsSessionState[] = [];
185
- const sid = nextSessionId();
186
- const { rerender } = render(
187
- <PluginContextProvider>
188
- <Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
189
- </PluginContextProvider>,
190
- );
191
-
192
- act(() => publishSessionEvent(sid, flowStartedEvent(1, "build")));
193
- const refAfterPublish = snaps[snaps.length - 1];
194
-
195
- // Force re-render without publishing.
196
- rerender(
197
- <PluginContextProvider>
198
- <Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
199
- </PluginContextProvider>,
200
- );
201
- const refAfterRerender = snaps[snaps.length - 1];
202
-
203
- expect(refAfterRerender).toBe(refAfterPublish);
204
- });
205
-
206
- it("clears flowStates when the events store is cleared", () => {
207
- const snaps: FlowsSessionState[] = [];
208
- const sid = nextSessionId();
209
- render(
210
- <PluginContextProvider>
211
- <Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
212
- </PluginContextProvider>,
213
- );
214
-
215
- act(() => publishSessionEvent(sid, flowStartedEvent(1, "build")));
216
- expect(snaps[snaps.length - 1].flowState).not.toBeNull();
217
-
218
- act(() => clearSessionEvents(sid));
219
- const last = snaps[snaps.length - 1];
220
- expect(last.flowState).toBeNull();
221
- expect(last.flowStates.size).toBe(0);
222
- });
223
- });
@@ -1,140 +0,0 @@
1
- /**
2
- * Tests for the plugin-internal UI selection state. Verifies the
3
- * module-level store, setter semantics, no-op short-circuiting, and
4
- * the unified `dismissAll` cleanup. See change:
5
- * pluginize-flows-via-registry.
6
- */
7
- import React from "react";
8
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
9
- import { render, act, cleanup } from "@testing-library/react";
10
- import {
11
- useFlowsUiState,
12
- useFlowsUiActions,
13
- __resetFlowsUiStateForTests,
14
- type FlowsUiState,
15
- } from "../client/FlowsUiStateContext.js";
16
-
17
- function Probe({ onSnapshot }: { onSnapshot: (state: FlowsUiState) => void }) {
18
- const state = useFlowsUiState();
19
- onSnapshot(state);
20
- return (
21
- <div data-testid="probe">
22
- src={state.sourceOpenAgent ?? "(null)"} yaml={state.flowYamlPreview?.title ?? "(null)"}
23
- </div>
24
- );
25
- }
26
-
27
- describe("FlowsUiStateContext", () => {
28
- beforeEach(() => __resetFlowsUiStateForTests());
29
- afterEach(() => {
30
- cleanup();
31
- __resetFlowsUiStateForTests();
32
- });
33
-
34
- it("starts with the initial state (all nulls / false)", () => {
35
- const snaps: FlowsUiState[] = [];
36
- render(<Probe onSnapshot={(s) => snaps.push(s)} />);
37
- expect(snaps[0]).toEqual({
38
- sourceOpenAgent: null,
39
- flowYamlPreview: null,
40
- });
41
- });
42
-
43
- it("does not notify when a setter is called with the same value", () => {
44
- let renderCount = 0;
45
- function CountingProbe() {
46
- renderCount++;
47
- useFlowsUiState();
48
- return null;
49
- }
50
- function ActionsProbe() {
51
- actions = useFlowsUiActions();
52
- return null;
53
- }
54
- render(
55
- <>
56
- <ActionsProbe />
57
- <CountingProbe />
58
- </>,
59
- );
60
- const initial = renderCount;
61
-
62
- act(() => actions.setSourceOpenAgent(null)); // already null
63
- expect(renderCount).toBe(initial); // no extra render
64
-
65
- act(() => actions.setSourceOpenAgent("alpha")); // change
66
- expect(renderCount).toBe(initial + 1);
67
-
68
- act(() => actions.setSourceOpenAgent("alpha")); // same value
69
- expect(renderCount).toBe(initial + 1); // no extra render
70
- });
71
-
72
- it("dismissAll clears every field in one notify", () => {
73
- let renderCount = 0;
74
- function CountingProbe() {
75
- renderCount++;
76
- useFlowsUiState();
77
- return null;
78
- }
79
- function ActionsProbe() {
80
- actions = useFlowsUiActions();
81
- return null;
82
- }
83
- render(
84
- <>
85
- <ActionsProbe />
86
- <CountingProbe />
87
- </>,
88
- );
89
-
90
- // Set every field.
91
- act(() => {
92
- actions.setSourceOpenAgent("beta");
93
- actions.setFlowYamlPreview({ content: "x", title: "t" });
94
- });
95
- const beforeDismiss = renderCount;
96
-
97
- // dismissAll: single act → expect a single notify (one render).
98
- act(() => actions.dismissAll());
99
- expect(renderCount).toBe(beforeDismiss + 1);
100
-
101
- // All fields cleared.
102
- const probeText = (function readProbe() {
103
- const snaps: FlowsUiState[] = [];
104
- render(<Probe onSnapshot={(s) => snaps.push(s)} />);
105
- return snaps[0];
106
- })();
107
- expect(probeText).toEqual({
108
- sourceOpenAgent: null,
109
- flowYamlPreview: null,
110
- });
111
- });
112
-
113
- it("returns a stable actions reference across renders", () => {
114
- const seen = new Set<unknown>();
115
- function ActionsProbe() {
116
- const a = useFlowsUiActions();
117
- seen.add(a);
118
- return null;
119
- }
120
- const { rerender } = render(<ActionsProbe />);
121
- rerender(<ActionsProbe />);
122
- rerender(<ActionsProbe />);
123
- expect(seen.size).toBe(1);
124
- });
125
- });
126
-
127
- // Shared module-level holder so tests can call setters from outside
128
- // the rendered tree.
129
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
- let actions: any;
131
-
132
- function ActionsProbeWithUI() {
133
- actions = useFlowsUiActions();
134
- const state = useFlowsUiState();
135
- return (
136
- <div data-testid="probe">
137
- src={state.sourceOpenAgent ?? "(null)"} yaml={state.flowYamlPreview?.title ?? "(null)"}
138
- </div>
139
- );
140
- }
@@ -1,190 +0,0 @@
1
- /**
2
- * Tests for the flow_write / flow_agents authoring tool renderers.
3
- * Covers success, validation-failure, and list states + the args-backed
4
- * Mermaid snapshot. See change: rework-flows-plugin-for-new-pi-flows.
5
- */
6
- import React from "react";
7
- import { describe, it, expect, afterEach } from "vitest";
8
- import { render, cleanup, fireEvent } from "@testing-library/react";
9
- import {
10
- UiPrimitiveProvider,
11
- createUiPrimitiveRegistry,
12
- registerUiPrimitive,
13
- } from "@blackbelt-technology/dashboard-plugin-runtime";
14
- import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
15
- import { FlowWriteToolRenderer } from "../client/FlowWriteToolRenderer.js";
16
- import { FlowAgentsToolRenderer } from "../client/FlowAgentsToolRenderer.js";
17
-
18
- const registry = createUiPrimitiveRegistry();
19
- registerUiPrimitive(
20
- registry,
21
- UI_PRIMITIVE_KEYS.markdownContent,
22
- (({ content }: { content: string }) => <div data-testid="md">{content}</div>) as never,
23
- );
24
-
25
- function renderWrite(props: { toolInput: Record<string, unknown>; status?: "running" | "complete" | "error"; result?: string }) {
26
- return render(
27
- <UiPrimitiveProvider value={registry}>
28
- <FlowWriteToolRenderer toolName="flow_write" sessionId="s1" {...props} />
29
- </UiPrimitiveProvider>,
30
- );
31
- }
32
-
33
- const FLOW_YAML = `name: invoice
34
- steps:
35
- - id: extract
36
- type: agent
37
- agent: e
38
- blockedBy: []
39
- - id: validate
40
- type: code
41
- blockedBy: [extract]`;
42
-
43
- afterEach(() => cleanup());
44
-
45
- describe("FlowWriteToolRenderer", () => {
46
- it("success: shows command, counts, and a Mermaid snapshot from args", () => {
47
- const { getByText, getByTestId } = renderWrite({
48
- toolInput: { name: "invoice", content: FLOW_YAML },
49
- status: "complete",
50
- result: JSON.stringify({ written: true, name: "invoice", namespace: "custom", command: "custom:invoice", path: "/p/invoice.yaml", diagnostics: [] }),
51
- });
52
- expect(getByText("/custom:invoice")).toBeTruthy();
53
- expect(getByText("2 steps · 1 agents, 1 code")).toBeTruthy();
54
- expect(getByTestId("md").textContent).toContain("graph LR");
55
- });
56
-
57
- it("validation failure: renders diagnostics verbatim", () => {
58
- const { getByText } = renderWrite({
59
- toolInput: { name: "invoice", content: FLOW_YAML },
60
- status: "error",
61
- result: JSON.stringify({ written: false, diagnostics: [{ message: 'step "validate" missing' }] }),
62
- });
63
- expect(getByText(/step "validate" missing/)).toBeTruthy();
64
- });
65
-
66
- it("view-yaml toggle reveals the submitted args", () => {
67
- const { getByText, queryByText } = renderWrite({
68
- toolInput: { name: "invoice", content: FLOW_YAML },
69
- status: "complete",
70
- result: JSON.stringify({ written: true, command: "custom:invoice", diagnostics: [] }),
71
- });
72
- expect(queryByText(/type: code/)).toBeNull();
73
- fireEvent.click(getByText(/View flow YAML/));
74
- expect(getByText(/type: code/)).toBeTruthy();
75
- });
76
- });
77
-
78
- describe("FlowAgentsToolRenderer", () => {
79
- it("list: shows agent names + count (as rows)", () => {
80
- const { getByText } = render(
81
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
82
- toolInput={{ op: "list" }} status="complete"
83
- result={JSON.stringify([{ name: "reviewer" }, { name: "reader" }])} />,
84
- );
85
- expect(getByText("list · 2 agents")).toBeTruthy();
86
- expect(getByText("reviewer")).toBeTruthy();
87
- expect(getByText("reader")).toBeTruthy();
88
- });
89
-
90
- it("write success: shows saved name", () => {
91
- const { getByText } = render(
92
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
93
- toolInput={{ op: "write", content: "name: reviewer" }} status="complete"
94
- result={JSON.stringify({ written: true, name: "reviewer", path: "/a/reviewer.md", diagnostics: [] })} />,
95
- );
96
- expect(getByText("reviewer")).toBeTruthy();
97
- expect(getByText("saved")).toBeTruthy();
98
- });
99
-
100
- it("write failure: shows diagnostics", () => {
101
- const { getByText } = render(
102
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
103
- toolInput={{ op: "write", content: "bad" }} status="error"
104
- result={JSON.stringify({ written: false, error: "missing name" })} />,
105
- );
106
- expect(getByText("not written")).toBeTruthy();
107
- expect(getByText(/missing name/)).toBeTruthy();
108
- });
109
-
110
- const AGENTS_DETAILS = [
111
- { name: "test-analyzer", description: "Emits a one-line note", source_type: "local", tools: ["read"], inputs: ["focus"], outputs: ["notes"], use_when: "parallel analysis branch" },
112
- { name: "flow-decision", description: "Decides at forks", source_type: "built-in" },
113
- ];
114
-
115
- it("list truncated (no details): does not report zero, shows truncated indicator", () => {
116
- const { queryByText, getByText } = render(
117
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
118
- toolInput={{ op: "list" }} status="complete"
119
- result={'«76 earlier lines hidden»\n "source_type": "local"\n }\n]'} />,
120
- );
121
- expect(queryByText(/·\s*0 agents/)).toBeNull();
122
- expect(getByText(/truncated/i)).toBeTruthy();
123
- });
124
-
125
- it("list details present + truncated text: renders rows (name+description+badge), no truncated", () => {
126
- const { getByText, queryByText } = render(
127
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
128
- toolInput={{ op: "list" }} status="complete"
129
- toolDetails={{ count: 2, agents: AGENTS_DETAILS }}
130
- result={'«76 earlier lines hidden»\n]'} />,
131
- );
132
- expect(getByText("list · 2 agents")).toBeTruthy();
133
- expect(getByText("test-analyzer")).toBeTruthy();
134
- expect(getByText("Emits a one-line note")).toBeTruthy();
135
- expect(getByText("flow-decision")).toBeTruthy();
136
- // source badges present
137
- expect(getByText("local")).toBeTruthy();
138
- expect(getByText("built-in")).toBeTruthy();
139
- expect(queryByText(/truncated/i)).toBeNull();
140
- });
141
-
142
- it("list rows are collapsed by default (no detail block until expand)", () => {
143
- const { queryByText } = render(
144
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
145
- toolInput={{ op: "list" }} status="complete"
146
- toolDetails={{ count: 2, agents: AGENTS_DETAILS }} result={"[]"} />,
147
- );
148
- // detail-only field values must not be visible before expanding
149
- expect(queryByText("focus")).toBeNull();
150
- expect(queryByText("parallel analysis branch")).toBeNull();
151
- });
152
-
153
- it("expanding a row reveals present fields and omits absent ones", () => {
154
- const { getByText, queryByText } = render(
155
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
156
- toolInput={{ op: "list" }} status="complete"
157
- toolDetails={{ count: 2, agents: AGENTS_DETAILS }} result={"[]"} />,
158
- );
159
- fireEvent.click(getByText("test-analyzer"));
160
- expect(getByText("read")).toBeTruthy(); // tools
161
- expect(getByText("focus")).toBeTruthy(); // inputs
162
- expect(getByText("notes")).toBeTruthy(); // outputs
163
- expect(getByText("parallel analysis branch")).toBeTruthy(); // use_when
164
- // flow-decision (no tools/inputs/outputs) — expand shows no such fields
165
- fireEvent.click(getByText("flow-decision"));
166
- // its use_when falls back to description; but tools/inputs/outputs absent
167
- expect(queryByText("grep")).toBeNull();
168
- });
169
-
170
- it("list text fallback (no details): renders rows from parsed text catalog", () => {
171
- const { getByText } = render(
172
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
173
- toolInput={{ op: "list" }} status="complete"
174
- result={JSON.stringify([{ name: "x", description: "the x", source_type: "local" }, { name: "y", description: "the y", source_type: "package" }])} />,
175
- );
176
- expect(getByText("list · 2 agents")).toBeTruthy();
177
- expect(getByText("x")).toBeTruthy();
178
- expect(getByText("the x")).toBeTruthy();
179
- expect(getByText("y")).toBeTruthy();
180
- });
181
-
182
- it("list genuine empty array: reports 0 agents", () => {
183
- const { getByText, queryByText } = render(
184
- <FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
185
- toolInput={{ op: "list" }} status="complete" result={"[]"} />,
186
- );
187
- expect(getByText("list · 0 agents")).toBeTruthy();
188
- expect(queryByText(/truncated/i)).toBeNull();
189
- });
190
- });
@@ -1,117 +0,0 @@
1
- /**
2
- * Flows → automation action contribution (publish/collect): availability
3
- * gating + enum options from the injected live flows resolver, flow:run event
4
- * build, and pure-publisher wiring (provide, no consume).
5
- * See change: decouple-automation-action-registry, fix-automation-flow-detection.
6
- */
7
-
8
- import { describe, expect, it, vi } from "vitest";
9
- import {
10
- ACTION_CONTRIBUTION_KEY,
11
- type FlowsForCwd,
12
- flowsActionContributions,
13
- provideFlowsActions,
14
- summarizeFlowResult,
15
- } from "../server/automation-actions.js";
16
-
17
- /** Stub resolver: returns the flows configured for a given cwd. */
18
- function stubFlows(map: Record<string, string[]>): FlowsForCwd {
19
- return (cwd: string) => map[cwd] ?? [];
20
- }
21
-
22
- const noFlows: FlowsForCwd = () => [];
23
-
24
- describe("flowsActionContributions", () => {
25
- it("contributes flows.run only (no resume/cancel); gated on the live flows resolver; enum options resolve", () => {
26
- const flowsForCwd = stubFlows({ "/w/invoice-bot": ["invoicebot:pull"] });
27
- const contribs = flowsActionContributions(flowsForCwd);
28
- expect(contribs.map((c) => c.id)).toEqual(["flows.run"]);
29
-
30
- const run = contribs[0]!;
31
- expect(run.source).toBe("flows");
32
- // Package/event-registered flow, not on disk under .pi/flows/flows.
33
- expect(run.available!("/w/invoice-bot")).toBe(true);
34
- // No running session for this cwd → empty → unavailable.
35
- expect(run.available!("/w/other")).toBe(false);
36
-
37
- const flowField = run.payloadSchema!.find((f) => f.key === "flow")!;
38
- expect(flowField.type).toBe("enum");
39
- expect(flowField.options!("/w/invoice-bot")).toEqual(["invoicebot:pull"]);
40
- expect(flowField.options!("/w/other")).toEqual([]);
41
- });
42
-
43
- it("flows.run emits a flow:run event (flowName+task) and declares its completion", () => {
44
- const run = flowsActionContributions(noFlows)[0]!;
45
- const ev = run.buildEvent!({ payload: { flow: "test:capabilities", task: "do it" }, automation: {} });
46
- expect(ev).toMatchObject({ eventType: "flow:run", data: { flowName: "test:capabilities", task: "do it" } });
47
- // Event-dispatched flow runs emit no agent_end — the action declares how it
48
- // finishes so the automation engine can finalize generically.
49
- expect(ev!.completion!.eventType).toBe("flow_complete");
50
- expect(typeof ev!.completion!.summarize).toBe("function");
51
- // task optional
52
- expect(run.buildEvent!({ payload: { flow: "test:capabilities" }, automation: {} }))
53
- .toMatchObject({ eventType: "flow:run", data: { flowName: "test:capabilities" } });
54
- });
55
-
56
- it("flows.run emits data.inputs (per-fire resolved, types preserved), task optional", () => {
57
- const run = flowsActionContributions(noFlows)[0]!;
58
- // Every flows.run also declares its completion (merged from
59
- // finalize-event-dispatched-automation-runs).
60
- const completion = { eventType: "flow_complete", summarize: expect.any(Function) };
61
- // payload arrives already interpolated by the engine: ${{trigger}} resolved.
62
- expect(
63
- run.buildEvent!({
64
- payload: { flow: "invoicebot:process", inputs: { invoice: "/spool/inv-042.pdf", priority: 5, dry: true } },
65
- automation: {},
66
- }),
67
- ).toEqual({
68
- eventType: "flow:run",
69
- data: { flowName: "invoicebot:process", inputs: { invoice: "/spool/inv-042.pdf", priority: 5, dry: true } },
70
- completion,
71
- });
72
- // task + inputs coexist
73
- expect(
74
- run.buildEvent!({ payload: { flow: "a:b", task: "label", inputs: { x: 1 } }, automation: {} }),
75
- ).toEqual({ eventType: "flow:run", data: { flowName: "a:b", task: "label", inputs: { x: 1 } }, completion });
76
- // empty / non-object inputs omitted
77
- expect(run.buildEvent!({ payload: { flow: "a:b", inputs: {} }, automation: {} }))
78
- .toEqual({ eventType: "flow:run", data: { flowName: "a:b" }, completion });
79
- expect(run.buildEvent!({ payload: { flow: "a:b", inputs: "nope" }, automation: {} }))
80
- .toEqual({ eventType: "flow:run", data: { flowName: "a:b" }, completion });
81
- });
82
-
83
- it("flows.run rejects a malformed flow id (emits nothing)", () => {
84
- const run = flowsActionContributions(noFlows)[0]!;
85
- expect(run.buildEvent!({ payload: { flow: "test:cap x", task: "t" }, automation: {} })).toBeNull();
86
- expect(run.buildEvent!({ payload: { flow: "nocolon", task: "t" }, automation: {} })).toBeNull();
87
- expect(run.buildEvent!({ payload: { flow: "" }, automation: {} })).toBeNull();
88
- });
89
- });
90
-
91
- describe("summarizeFlowResult (flows owns the FlowResult shape)", () => {
92
- it("builds a line from status + flowName + summary", () => {
93
- expect(
94
- summarizeFlowResult({
95
- status: "success",
96
- flowName: "invoicebot:process",
97
- lastResult: { result: { summary: "done: exported" } },
98
- }),
99
- ).toBe("flow invoicebot:process success: done: exported");
100
- });
101
- it("tolerates a missing summary and missing fields", () => {
102
- expect(summarizeFlowResult({ status: "error", flowName: "x:y" })).toBe("flow x:y error");
103
- expect(summarizeFlowResult(undefined)).toBe("flow finished");
104
- });
105
- });
106
-
107
- describe("provideFlowsActions (pure publisher)", () => {
108
- it("publishes the contribution under automation.action.flows and consumes nothing", () => {
109
- const provide = vi.fn();
110
- provideFlowsActions(provide, () => {}, noFlows);
111
- expect(provide).toHaveBeenCalledTimes(1);
112
- const [key, value] = provide.mock.calls[0]!;
113
- expect(key).toBe(ACTION_CONTRIBUTION_KEY);
114
- expect(key).toBe("automation.action.flows");
115
- expect((value as Array<{ id: string }>).map((c) => c.id)).toEqual(["flows.run"]);
116
- });
117
- });