@blackbelt-technology/pi-dashboard-flows-plugin 0.5.4 → 0.6.1
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 +25 -16
- package/src/AGENTS.md +8 -0
- package/src/__tests__/FlowGraph.test.ts +151 -5
- package/src/__tests__/FlowInputWiring.test.tsx +97 -0
- package/src/__tests__/FlowSummary.test.tsx +331 -0
- package/src/__tests__/FlowYamlPreview.test.tsx +75 -0
- package/src/__tests__/FlowsSessionStateContext.test.tsx +2 -39
- package/src/__tests__/authoring-renderers.test.tsx +190 -0
- package/src/__tests__/automation-actions.test.ts +117 -0
- package/src/__tests__/flow-agent-card-code-source.test.tsx +154 -0
- package/src/__tests__/flow-agent-cost.test.tsx +160 -0
- package/src/__tests__/flow-agent-error.test.ts +60 -0
- package/src/__tests__/flow-collapse-storage.test.ts +90 -0
- package/src/__tests__/flow-edges.test.ts +195 -0
- package/src/__tests__/flow-inputs.test.ts +69 -0
- package/src/__tests__/flow-reducer-bridge-contract.test.ts +108 -0
- package/src/__tests__/flow-reducer-seed-on-start.test.ts +61 -0
- package/src/__tests__/flow-yaml-parse.test.ts +124 -0
- package/src/__tests__/flows-for-cwd.test.ts +51 -0
- package/src/__tests__/flowsAvailability.test.ts +51 -64
- package/src/__tests__/node-kind-reducer.test.ts +135 -0
- package/src/__tests__/plugin-action-handler.test.ts +54 -0
- package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
- package/src/bridge/AGENTS.md +8 -0
- package/src/client/AGENTS.md +32 -0
- package/src/client/FlowActivityBadge.tsx +8 -5
- package/src/client/FlowAgentCard.tsx +231 -110
- package/src/client/FlowAgentDetail.tsx +20 -12
- package/src/client/FlowAgentsToolRenderer.tsx +228 -0
- package/src/client/FlowAuthorPromptDialog.tsx +92 -0
- package/src/client/FlowDashboard.tsx +88 -23
- package/src/client/FlowGraph.tsx +420 -275
- package/src/client/FlowInputWiring.tsx +243 -0
- package/src/client/FlowLaunchDialog.tsx +48 -54
- package/src/client/FlowQuestionCard.tsx +6 -3
- package/src/client/FlowSummary.tsx +252 -69
- package/src/client/FlowWriteToolRenderer.tsx +127 -0
- package/src/client/FlowYamlPopoverButton.tsx +26 -25
- package/src/client/FlowYamlPreview.tsx +9 -7
- package/src/client/FlowsSessionStateContext.tsx +14 -33
- package/src/client/FlowsSettings.tsx +68 -0
- package/src/client/SessionFlowActions.tsx +92 -76
- package/src/client/flow-collapse-storage.ts +79 -0
- package/src/client/flow-edges.ts +173 -0
- package/src/client/flow-yaml-parse.ts +140 -0
- package/src/client/flowsAvailability.ts +28 -87
- package/src/client/index.tsx +27 -32
- package/src/client/shouldRender.ts +24 -12
- package/src/configSchema.json +14 -0
- package/src/flow-reducer.ts +94 -13
- package/src/i18n.ts +90 -0
- package/src/reducer.ts +5 -5
- package/src/server/AGENTS.md +10 -0
- package/src/server/automation-actions.ts +162 -0
- package/src/server/flow-inputs.ts +58 -0
- package/src/server/index.ts +93 -9
- package/src/server/state-store.ts +3 -14
- package/src/__tests__/ArchitectInputPrompt.test.tsx +0 -81
- package/src/__tests__/architect-reducer.test.ts +0 -307
- package/src/architect-reducer.ts +0 -386
- package/src/client/FlowAgentPopoutClaim.tsx +0 -66
- package/src/client/FlowAgentPopoutPage.tsx +0 -177
- package/src/client/FlowArchitect.tsx +0 -699
- package/src/client/FlowArchitectPopoutClaim.tsx +0 -52
- package/src/client/FlowArchitectPopoutPage.tsx +0 -133
- package/src/client/popout-url.ts +0 -59
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for expandable per-agent rows in FlowSummary.
|
|
3
|
+
* Collapsed rows show a truncated peek; expanding reveals full summary
|
|
4
|
+
* (markdown), typed-output chips, and the file list. Failed steps
|
|
5
|
+
* auto-expand. Rows without detail are not interactive. Per-row state
|
|
6
|
+
* is independent. See change: expandable-flow-summary-rows.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { cleanup, fireEvent, render, within } from "@testing-library/react";
|
|
10
|
+
import type React from "react";
|
|
11
|
+
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
12
|
+
|
|
13
|
+
// jsdom does not implement scrollIntoView; the selection effect calls it.
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
Element.prototype.scrollIntoView = () => {};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
createUiPrimitiveRegistry,
|
|
20
|
+
registerUiPrimitive,
|
|
21
|
+
UiPrimitiveProvider,
|
|
22
|
+
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
23
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
24
|
+
import type { FlowAgentState, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
25
|
+
import { FlowSummary } from "../client/FlowSummary.js";
|
|
26
|
+
|
|
27
|
+
const registry = createUiPrimitiveRegistry();
|
|
28
|
+
registerUiPrimitive(
|
|
29
|
+
registry,
|
|
30
|
+
UI_PRIMITIVE_KEYS.markdownContent,
|
|
31
|
+
(({ content }: { content: string }) => <div data-testid="md">{content}</div>) as never,
|
|
32
|
+
);
|
|
33
|
+
registerUiPrimitive(
|
|
34
|
+
registry,
|
|
35
|
+
UI_PRIMITIVE_KEYS.formatDuration,
|
|
36
|
+
(((ms: number) => `${ms}ms`) as never),
|
|
37
|
+
);
|
|
38
|
+
// FlowGraph (rendered inside FlowSummary) consumes the zoom-controls primitive.
|
|
39
|
+
registerUiPrimitive(
|
|
40
|
+
registry,
|
|
41
|
+
UI_PRIMITIVE_KEYS.zoomControls,
|
|
42
|
+
((() => null) as never),
|
|
43
|
+
);
|
|
44
|
+
// FlowAgentCard (frozen cards) primitives. See change: show-flow-cards-in-summary.
|
|
45
|
+
registerUiPrimitive(
|
|
46
|
+
registry,
|
|
47
|
+
UI_PRIMITIVE_KEYS.agentCard,
|
|
48
|
+
(({ children, selected, onClick }: { children?: React.ReactNode; selected?: boolean; onClick?: () => void }) => (
|
|
49
|
+
<div data-testid="agent-card" data-selected={selected ? "true" : "false"} onClick={onClick}>{children}</div>
|
|
50
|
+
)) as never,
|
|
51
|
+
);
|
|
52
|
+
// ui:dialog is required by FlowAgentCard (detail) + FlowSummary (graph expand).
|
|
53
|
+
registerUiPrimitive(
|
|
54
|
+
registry,
|
|
55
|
+
UI_PRIMITIVE_KEYS.dialog,
|
|
56
|
+
(({ open, children, title, size }: { open: boolean; children?: React.ReactNode; title?: string; size?: string }) =>
|
|
57
|
+
open ? <div data-testid="dialog" data-size={size}>{title}{children}</div> : null) as never,
|
|
58
|
+
);
|
|
59
|
+
registerUiPrimitive(
|
|
60
|
+
registry,
|
|
61
|
+
UI_PRIMITIVE_KEYS.formatTokens,
|
|
62
|
+
(((n: number) => `${n}`) as never),
|
|
63
|
+
);
|
|
64
|
+
registerUiPrimitive(
|
|
65
|
+
registry,
|
|
66
|
+
UI_PRIMITIVE_KEYS.popover,
|
|
67
|
+
(({ children }: { children?: React.ReactNode }) => <>{children}</>) as never,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
function agent(over: Partial<FlowAgentState>): FlowAgentState {
|
|
71
|
+
return {
|
|
72
|
+
agentName: over.stepId ?? "a",
|
|
73
|
+
stepId: over.stepId ?? "a",
|
|
74
|
+
status: "complete",
|
|
75
|
+
blockedBy: [],
|
|
76
|
+
recentTools: [],
|
|
77
|
+
detailHistory: [],
|
|
78
|
+
...over,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function makeState(agents: FlowAgentState[]): FlowState {
|
|
83
|
+
return {
|
|
84
|
+
flowName: "demo-flow",
|
|
85
|
+
task: "t",
|
|
86
|
+
status: "success",
|
|
87
|
+
autonomousMode: false,
|
|
88
|
+
agents: new Map(agents.map((a) => [a.stepId, a])),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function renderSummary(state: FlowState) {
|
|
93
|
+
return render(
|
|
94
|
+
<UiPrimitiveProvider value={registry}>
|
|
95
|
+
<FlowSummary flowState={state} onDismiss={() => {}} sessionId="s1" />
|
|
96
|
+
</UiPrimitiveProvider>,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
afterEach(() => cleanup());
|
|
101
|
+
|
|
102
|
+
describe("FlowSummary frozen cards (show-flow-cards-in-summary)", () => {
|
|
103
|
+
it("renders one frozen agent card per agent, above the collapsible summary section", () => {
|
|
104
|
+
const state = makeState([
|
|
105
|
+
agent({ stepId: "one", label: "step-one", status: "complete", summary: "S1" }),
|
|
106
|
+
agent({ stepId: "two", label: "step-two", status: "complete", summary: "S2" }),
|
|
107
|
+
]);
|
|
108
|
+
const { getAllByTestId, getByTestId } = renderSummary(state);
|
|
109
|
+
const cards = getAllByTestId("agent-card");
|
|
110
|
+
expect(cards).toHaveLength(2);
|
|
111
|
+
// Cards precede the collapsible summaries section in DOM order.
|
|
112
|
+
const section = getByTestId("flow-summaries");
|
|
113
|
+
expect(cards[0].compareDocumentPosition(section) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("collapsing the summary section keeps the cards visible", () => {
|
|
117
|
+
const state = makeState([
|
|
118
|
+
agent({ stepId: "one", label: "step-one", status: "complete", summary: "S1" }),
|
|
119
|
+
]);
|
|
120
|
+
const { getByTestId, getAllByTestId, queryByTestId } = renderSummary(state);
|
|
121
|
+
expect(getByTestId("flow-summaries")).toBeTruthy();
|
|
122
|
+
fireEvent.click(getByTestId("flow-summary-toggle"));
|
|
123
|
+
// Collapsing removes the summaries rows; cards stay visible.
|
|
124
|
+
expect(queryByTestId("flow-summaries")).toBeNull();
|
|
125
|
+
expect(getAllByTestId("agent-card")).toHaveLength(1);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("FlowSummary fit-window scroll box (improve-flow-graph-fidelity)", () => {
|
|
130
|
+
it("wraps cards + summaries in one bounded, scrollable box so the panel fits the viewport", () => {
|
|
131
|
+
const state = makeState([
|
|
132
|
+
agent({ stepId: "one", label: "step-one", status: "complete", summary: "S1" }),
|
|
133
|
+
]);
|
|
134
|
+
const { getByTestId } = renderSummary(state);
|
|
135
|
+
const box = getByTestId("flow-summary-scrollbox");
|
|
136
|
+
expect(box.style.maxHeight).toBe("48vh");
|
|
137
|
+
expect(box.className).toMatch(/overflow-y-auto/);
|
|
138
|
+
// cards + summaries live INSIDE the scroll box
|
|
139
|
+
expect(box.querySelector("[data-testid='flow-summaries']")).toBeTruthy();
|
|
140
|
+
expect(box.querySelector("[data-testid='agent-card']")).toBeTruthy();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe("FlowSummary whole-panel collapse (improve-flow-graph-fidelity)", () => {
|
|
145
|
+
it("collapses the whole panel to its header bar, hiding the body but keeping the name", () => {
|
|
146
|
+
const state = makeState([
|
|
147
|
+
agent({ stepId: "one", label: "step-one", status: "complete", summary: "S1" }),
|
|
148
|
+
]);
|
|
149
|
+
const { getByTestId, queryByTestId, queryAllByTestId, getByText } = renderSummary(state);
|
|
150
|
+
// Body present initially (cards + summaries footer).
|
|
151
|
+
expect(queryAllByTestId("agent-card")).toHaveLength(1);
|
|
152
|
+
expect(queryByTestId("flow-summaries")).toBeTruthy();
|
|
153
|
+
// Collapse the whole panel.
|
|
154
|
+
fireEvent.click(getByTestId("flow-summary-panel-toggle"));
|
|
155
|
+
// Body gone; header (flow name) still shown — shrink-to-header, not dismiss.
|
|
156
|
+
expect(queryAllByTestId("agent-card")).toHaveLength(0);
|
|
157
|
+
expect(queryByTestId("flow-summaries")).toBeNull();
|
|
158
|
+
expect(getByText(/demo-flow/)).toBeTruthy();
|
|
159
|
+
// Toggling back restores the body.
|
|
160
|
+
fireEvent.click(getByTestId("flow-summary-panel-toggle"));
|
|
161
|
+
expect(queryAllByTestId("agent-card")).toHaveLength(1);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe("FlowSummary graph⇄card selection (improve-flow-graph-dialog-and-card-interaction)", () => {
|
|
166
|
+
function selectionState() {
|
|
167
|
+
return makeState([
|
|
168
|
+
agent({ stepId: "one", label: "step-one", status: "complete", summary: "S1" }),
|
|
169
|
+
agent({ stepId: "two", label: "step-two", status: "complete", summary: "S2" }),
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
it("clicking a graph node selects the matching card", () => {
|
|
174
|
+
const { container } = renderSummary(selectionState());
|
|
175
|
+
const node = container.querySelector("[data-node='one']") as SVGGElement;
|
|
176
|
+
expect(node).toBeTruthy();
|
|
177
|
+
fireEvent.click(node);
|
|
178
|
+
const card = container.querySelector("[data-step='one'] [data-testid='agent-card']");
|
|
179
|
+
expect(card?.getAttribute("data-selected")).toBe("true");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("clicking a card selects the matching graph node", () => {
|
|
183
|
+
const { container } = renderSummary(selectionState());
|
|
184
|
+
const card = container.querySelector("[data-step='two'] [data-testid='agent-card']") as HTMLElement;
|
|
185
|
+
fireEvent.click(card);
|
|
186
|
+
const node = container.querySelector("[data-node='two']");
|
|
187
|
+
expect(node?.getAttribute("class") ?? "").toContain("flow-node-selected");
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("re-clicking the selected node clears selection", () => {
|
|
191
|
+
const { container } = renderSummary(selectionState());
|
|
192
|
+
const node = container.querySelector("[data-node='one']") as SVGGElement;
|
|
193
|
+
fireEvent.click(node);
|
|
194
|
+
fireEvent.click(node);
|
|
195
|
+
const card = container.querySelector("[data-step='one'] [data-testid='agent-card']");
|
|
196
|
+
expect(card?.getAttribute("data-selected")).toBe("false");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("Esc clears selection", () => {
|
|
200
|
+
const { container } = renderSummary(selectionState());
|
|
201
|
+
fireEvent.click(container.querySelector("[data-node='one']") as SVGGElement);
|
|
202
|
+
expect(container.querySelector("[data-step='one'] [data-testid='agent-card']")?.getAttribute("data-selected")).toBe("true");
|
|
203
|
+
fireEvent.keyDown(document, { key: "Escape" });
|
|
204
|
+
expect(container.querySelector("[data-step='one'] [data-testid='agent-card']")?.getAttribute("data-selected")).toBe("false");
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe("FlowSummary graph expand dialog (full size)", () => {
|
|
209
|
+
it("⤢ Expand opens the graph dialog at size=full", () => {
|
|
210
|
+
const state = makeState([agent({ stepId: "one", label: "step-one", status: "complete" })]);
|
|
211
|
+
const { container, getByText, queryByTestId } = renderSummary(state);
|
|
212
|
+
expect(queryByTestId("dialog")).toBeNull();
|
|
213
|
+
fireEvent.click(getByText(/Expand/));
|
|
214
|
+
const dialog = container.querySelector("[data-testid='dialog']");
|
|
215
|
+
expect(dialog).toBeTruthy();
|
|
216
|
+
expect(dialog?.getAttribute("data-size")).toBe("full");
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe("FlowAgentCard detail dialog (replaces popover)", () => {
|
|
221
|
+
it("clicking Details opens a dialog and there is no Popout button", () => {
|
|
222
|
+
const state = makeState([agent({ stepId: "one", label: "step-one", status: "complete" })]);
|
|
223
|
+
const { queryByText, queryByTestId, getAllByText } = renderSummary(state);
|
|
224
|
+
expect(queryByText("Popout")).toBeNull();
|
|
225
|
+
expect(queryByTestId("dialog")).toBeNull();
|
|
226
|
+
// "Details" appears once per card; click the card's detail button.
|
|
227
|
+
fireEvent.click(getAllByText("Details")[0]);
|
|
228
|
+
const dialog = queryByTestId("dialog");
|
|
229
|
+
expect(dialog).toBeTruthy();
|
|
230
|
+
expect(dialog?.textContent).toContain("step-one"); // dialog title = displayName
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe("FlowSummary expandable rows", () => {
|
|
235
|
+
it("collapsed complete row shows truncated peek; clicking reveals full summary, chips, files", () => {
|
|
236
|
+
const state = makeState([
|
|
237
|
+
agent({
|
|
238
|
+
stepId: "classify",
|
|
239
|
+
label: "classify-intent",
|
|
240
|
+
status: "complete",
|
|
241
|
+
summary: "Decided the request was a refactor of the reducer module.",
|
|
242
|
+
files: ["flow-reducer.ts", "flow-reducer.test.ts"],
|
|
243
|
+
typedOutputs: { intent: "refactor", branch: "refactor" },
|
|
244
|
+
}),
|
|
245
|
+
]);
|
|
246
|
+
const { container } = renderSummary(state);
|
|
247
|
+
// Scope row assertions to the collapsible summary section (the frozen cards
|
|
248
|
+
// above also surface summary/outputs, so global queries are ambiguous now).
|
|
249
|
+
const section = within(container.querySelector("[data-testid='flow-summaries']") as HTMLElement);
|
|
250
|
+
|
|
251
|
+
// Collapsed: full summary not yet rendered through markdown primitive.
|
|
252
|
+
expect(section.queryByTestId("md")).toBeNull();
|
|
253
|
+
|
|
254
|
+
fireEvent.click(section.getByText("classify-intent", { selector: "span" }));
|
|
255
|
+
|
|
256
|
+
// Expanded: full summary via markdown primitive.
|
|
257
|
+
expect(section.getByTestId("md").textContent).toContain("refactor of the reducer module");
|
|
258
|
+
// Typed-output chip (branch filtered out, intent shown).
|
|
259
|
+
expect(section.getByText("intent")).toBeTruthy();
|
|
260
|
+
// File list rendered.
|
|
261
|
+
expect(section.getByText(/flow-reducer\.test\.ts/)).toBeTruthy();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("failed step renders expanded on mount", () => {
|
|
265
|
+
const state = makeState([
|
|
266
|
+
agent({
|
|
267
|
+
stepId: "verify",
|
|
268
|
+
label: "verify-change",
|
|
269
|
+
status: "error",
|
|
270
|
+
outcome: "hard",
|
|
271
|
+
summary: "Coverage gate failed on the new branch path.",
|
|
272
|
+
}),
|
|
273
|
+
]);
|
|
274
|
+
const { getByTestId } = renderSummary(state);
|
|
275
|
+
// Auto-expanded → markdown primitive rendered without any click.
|
|
276
|
+
expect(getByTestId("md").textContent).toContain("Coverage gate failed");
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("row without summary text is omitted from the list; section hidden when it is the only agent", () => {
|
|
280
|
+
const state = makeState([
|
|
281
|
+
agent({ stepId: "bare", label: "bare-step", status: "complete" }),
|
|
282
|
+
]);
|
|
283
|
+
const { queryByText, queryByTestId, getAllByTestId } = renderSummary(state);
|
|
284
|
+
// The bare step has no summary text → not listed, and as the only agent the
|
|
285
|
+
// whole Summaries subsection is hidden.
|
|
286
|
+
expect(queryByTestId("flow-summaries")).toBeNull();
|
|
287
|
+
expect(queryByTestId("flow-summary-toggle")).toBeNull();
|
|
288
|
+
expect(queryByText("bare-step", { selector: "span" })).toBeNull();
|
|
289
|
+
// Frozen agent card still present (the filter only affects the Summaries list).
|
|
290
|
+
expect(getAllByTestId("agent-card")).toHaveLength(1);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("Summaries count reflects only summary-bearing agents", () => {
|
|
294
|
+
const state = makeState([
|
|
295
|
+
agent({ stepId: "one", label: "step-one", status: "complete", summary: "S1" }),
|
|
296
|
+
agent({ stepId: "two", label: "step-two", status: "complete" }),
|
|
297
|
+
agent({ stepId: "three", label: "step-three", status: "complete", summary: "S3" }),
|
|
298
|
+
]);
|
|
299
|
+
const { getByText, queryByText } = renderSummary(state);
|
|
300
|
+
expect(getByText("Summaries (2)")).toBeTruthy();
|
|
301
|
+
// The summary-less middle step is not rendered as a row.
|
|
302
|
+
expect(queryByText("step-two", { selector: "span" })).toBeNull();
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("hides the whole Summaries section when no agent has summary text", () => {
|
|
306
|
+
const state = makeState([
|
|
307
|
+
agent({ stepId: "a", label: "a", status: "complete", typedOutputs: { verdict: "pass" } }),
|
|
308
|
+
agent({ stepId: "b", label: "b", status: "complete" }),
|
|
309
|
+
]);
|
|
310
|
+
const { queryByTestId, getAllByTestId } = renderSummary(state);
|
|
311
|
+
expect(queryByTestId("flow-summaries")).toBeNull();
|
|
312
|
+
expect(queryByTestId("flow-summary-toggle")).toBeNull();
|
|
313
|
+
// Both still appear as frozen cards.
|
|
314
|
+
expect(getAllByTestId("agent-card")).toHaveLength(2);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("expanding one row leaves siblings collapsed", () => {
|
|
318
|
+
const state = makeState([
|
|
319
|
+
agent({ stepId: "one", label: "step-one", status: "complete", summary: "Summary one." }),
|
|
320
|
+
agent({ stepId: "two", label: "step-two", status: "complete", summary: "Summary two." }),
|
|
321
|
+
]);
|
|
322
|
+
const { getByText, getAllByTestId, queryAllByTestId } = renderSummary(state);
|
|
323
|
+
|
|
324
|
+
expect(queryAllByTestId("md")).toHaveLength(0);
|
|
325
|
+
fireEvent.click(getByText("step-one", { selector: "span" }));
|
|
326
|
+
|
|
327
|
+
const mds = getAllByTestId("md");
|
|
328
|
+
expect(mds).toHaveLength(1);
|
|
329
|
+
expect(mds[0].textContent).toContain("Summary one.");
|
|
330
|
+
});
|
|
331
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the flow YAML preview content-view claim's dismissal contract.
|
|
3
|
+
*
|
|
4
|
+
* The claim overlays the chat at the current /session/:id URL, gated by the
|
|
5
|
+
* plugin UI-state predicate. On back it MUST clear its own UI state (revealing
|
|
6
|
+
* the chat) AND invoke the shell-provided onClose. The shell wires onClose to a
|
|
7
|
+
* no-op so dismissal stays on the session instead of navigating to "/".
|
|
8
|
+
*
|
|
9
|
+
* See change: fix-settings-back-to-launching-route.
|
|
10
|
+
*/
|
|
11
|
+
import React from "react";
|
|
12
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
13
|
+
import { render, act, cleanup, fireEvent } from "@testing-library/react";
|
|
14
|
+
import {
|
|
15
|
+
UiPrimitiveProvider,
|
|
16
|
+
createUiPrimitiveRegistry,
|
|
17
|
+
registerUiPrimitive,
|
|
18
|
+
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
19
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
20
|
+
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
21
|
+
import { FlowYamlPreviewClaim } from "../client/FlowYamlPreview.js";
|
|
22
|
+
import {
|
|
23
|
+
useFlowsUiActions,
|
|
24
|
+
getFlowsUiStateSnapshot,
|
|
25
|
+
__resetFlowsUiStateForTests,
|
|
26
|
+
} from "../client/FlowsUiStateContext.js";
|
|
27
|
+
|
|
28
|
+
const registry = createUiPrimitiveRegistry();
|
|
29
|
+
// Stub markdownContent primitive — the preview body renders through it.
|
|
30
|
+
registerUiPrimitive(
|
|
31
|
+
registry,
|
|
32
|
+
UI_PRIMITIVE_KEYS.markdownContent,
|
|
33
|
+
(({ content }: { content: string }) => <div data-testid="md">{content}</div>) as never,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const session = { id: "abc" } as unknown as DashboardSession;
|
|
37
|
+
|
|
38
|
+
function Harness({ onClose }: { onClose: () => void }) {
|
|
39
|
+
const actions = useFlowsUiActions();
|
|
40
|
+
// Seed the preview content so the claim renders.
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
actions.setFlowYamlPreview({ content: "name: demo", title: "demo.yaml" });
|
|
43
|
+
}, [actions]);
|
|
44
|
+
return (
|
|
45
|
+
<UiPrimitiveProvider value={registry}>
|
|
46
|
+
<FlowYamlPreviewClaim session={session} routeParams={{}} onClose={onClose} />
|
|
47
|
+
</UiPrimitiveProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe("FlowYamlPreviewClaim dismissal", () => {
|
|
52
|
+
beforeEach(() => __resetFlowsUiStateForTests());
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
cleanup();
|
|
55
|
+
__resetFlowsUiStateForTests();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("back clears UI state AND calls the shell onClose", () => {
|
|
59
|
+
const onClose = vi.fn();
|
|
60
|
+
const { getByTitle } = render(<Harness onClose={onClose} />);
|
|
61
|
+
|
|
62
|
+
// Preview is active before back.
|
|
63
|
+
expect(getFlowsUiStateSnapshot().flowYamlPreview).not.toBeNull();
|
|
64
|
+
|
|
65
|
+
act(() => {
|
|
66
|
+
fireEvent.click(getByTitle("Back"));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Plugin cleared its own state → predicate goes false → chat reappears.
|
|
70
|
+
expect(getFlowsUiStateSnapshot().flowYamlPreview).toBeNull();
|
|
71
|
+
expect(getFlowsUiStateSnapshot().sourceOpenAgent).toBeNull();
|
|
72
|
+
// Shell onClose invoked (wired to a no-op in App; never navigates to "/").
|
|
73
|
+
expect(onClose).toHaveBeenCalledOnce();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -59,20 +59,6 @@ function flowSummaryDismissedEvent(seq: number): DashboardEvent {
|
|
|
59
59
|
} as any;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function architectStartedEvent(seq: number): DashboardEvent {
|
|
63
|
-
return {
|
|
64
|
-
seq,
|
|
65
|
-
timestamp: new Date(seq * 1000).toISOString(),
|
|
66
|
-
eventType: "architect_started",
|
|
67
|
-
data: {
|
|
68
|
-
mode: "new",
|
|
69
|
-
iteration: 1,
|
|
70
|
-
resolvedModel: "claude-sonnet-4",
|
|
71
|
-
},
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
} as any;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
62
|
function unrelatedEvent(seq: number): DashboardEvent {
|
|
77
63
|
return {
|
|
78
64
|
seq,
|
|
@@ -91,17 +77,15 @@ describe("reduceFlowsSessionState (pure)", () => {
|
|
|
91
77
|
const b = reduceFlowsSessionState([]);
|
|
92
78
|
expect(a).toBe(b);
|
|
93
79
|
expect(a.flowState).toBeNull();
|
|
94
|
-
expect(a.architectState).toBeNull();
|
|
95
80
|
expect(a.flowStates.size).toBe(0);
|
|
96
81
|
});
|
|
97
82
|
|
|
98
|
-
it("returns EMPTY_STATE when no flow
|
|
83
|
+
it("returns EMPTY_STATE when no flow events are present", () => {
|
|
99
84
|
const result = reduceFlowsSessionState([
|
|
100
85
|
unrelatedEvent(1),
|
|
101
86
|
unrelatedEvent(2),
|
|
102
87
|
]);
|
|
103
88
|
expect(result.flowState).toBeNull();
|
|
104
|
-
expect(result.architectState).toBeNull();
|
|
105
89
|
});
|
|
106
90
|
|
|
107
91
|
it("derives flowState from a flow_started event", () => {
|
|
@@ -122,26 +106,6 @@ describe("reduceFlowsSessionState (pure)", () => {
|
|
|
122
106
|
expect(result.flowStates.size).toBe(0);
|
|
123
107
|
});
|
|
124
108
|
|
|
125
|
-
it("derives architectState from architect_started", () => {
|
|
126
|
-
const result = reduceFlowsSessionState([architectStartedEvent(1)]);
|
|
127
|
-
expect(result.architectState).not.toBeNull();
|
|
128
|
-
// architect_started doesn't carry flowName — that's filled in by
|
|
129
|
-
// later events (architect_preview / architect_complete). What
|
|
130
|
-
// architect_started DOES set is phase + architectMode + iteration.
|
|
131
|
-
expect(result.architectState!.phase).toBe("designing");
|
|
132
|
-
expect(result.architectState!.architectMode).toBe("new");
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("derives both flow and architect state when events of both kinds are present", () => {
|
|
136
|
-
const result = reduceFlowsSessionState([
|
|
137
|
-
architectStartedEvent(1),
|
|
138
|
-
flowStartedEvent(2, "build"),
|
|
139
|
-
]);
|
|
140
|
-
expect(result.architectState).not.toBeNull();
|
|
141
|
-
expect(result.flowState).not.toBeNull();
|
|
142
|
-
expect(result.flowState!.flowName).toBe("build");
|
|
143
|
-
});
|
|
144
|
-
|
|
145
109
|
it("ignores unrelated events between flow events", () => {
|
|
146
110
|
const result = reduceFlowsSessionState([
|
|
147
111
|
flowStartedEvent(1, "build"),
|
|
@@ -162,7 +126,7 @@ function Probe({ sessionId, onSnapshot }: {
|
|
|
162
126
|
onSnapshot(state);
|
|
163
127
|
return (
|
|
164
128
|
<div data-testid="probe">
|
|
165
|
-
flow={state.flowState?.flowName ?? "(none)"}
|
|
129
|
+
flow={state.flowState?.flowName ?? "(none)"}
|
|
166
130
|
</div>
|
|
167
131
|
);
|
|
168
132
|
}
|
|
@@ -179,7 +143,6 @@ describe("useFlowsSessionState (hook)", () => {
|
|
|
179
143
|
</PluginContextProvider>,
|
|
180
144
|
);
|
|
181
145
|
expect(snaps[0].flowState).toBeNull();
|
|
182
|
-
expect(snaps[0].architectState).toBeNull();
|
|
183
146
|
});
|
|
184
147
|
|
|
185
148
|
it("re-renders with derived state when a flow event arrives", () => {
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
});
|