@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.
- package/package.json +18 -7
- package/src/bridge/flow-files-reporter.ts +113 -0
- package/src/bridge/index.ts +5 -1
- package/src/client/FlowAgentCard.tsx +82 -213
- package/src/client/FlowAgentDetail.tsx +1 -1
- package/src/client/FlowDashboard.tsx +428 -66
- package/src/client/FlowInputWiring.tsx +2 -2
- package/src/client/FlowSummary.tsx +22 -16
- package/src/client/FlowYamlPopoverButton.tsx +27 -92
- package/src/client/FlowsCommandRoutes.tsx +13 -5
- package/src/client/FlowsSessionStateContext.tsx +40 -4
- package/src/client/FlowsSettings.tsx +4 -4
- package/src/client/SessionFlowActions.tsx +80 -6
- package/src/client/flow-attach-store.ts +140 -0
- package/src/client/flow-card-grid.ts +36 -0
- package/src/client/flow-files.ts +152 -0
- package/src/client/flow-idle-state.ts +230 -0
- package/src/client/format-cost.ts +21 -0
- package/src/client/send-safe.ts +19 -0
- package/src/flow-files-contract.ts +21 -0
- package/src/flow-reducer.ts +4 -0
- package/src/i18n.ts +28 -0
- package/src/server/automation-actions.ts +3 -0
- package/src/server/flow-files.ts +264 -0
- package/src/server/index.ts +15 -0
- package/src/AGENTS.md +0 -8
- package/src/__tests__/FlowGraph.test.ts +0 -305
- package/src/__tests__/FlowInputWiring.test.tsx +0 -97
- package/src/__tests__/FlowSummary.test.tsx +0 -331
- package/src/__tests__/FlowYamlPreview.test.tsx +0 -75
- package/src/__tests__/FlowsSessionStateContext.test.tsx +0 -223
- package/src/__tests__/FlowsUiStateContext.test.tsx +0 -140
- package/src/__tests__/authoring-renderers.test.tsx +0 -190
- package/src/__tests__/automation-actions.test.ts +0 -117
- package/src/__tests__/flow-agent-card-code-source.test.tsx +0 -190
- package/src/__tests__/flow-agent-cost.test.tsx +0 -160
- package/src/__tests__/flow-agent-error.test.ts +0 -60
- package/src/__tests__/flow-collapse-storage.test.ts +0 -90
- package/src/__tests__/flow-edges.test.ts +0 -195
- package/src/__tests__/flow-inputs.test.ts +0 -69
- package/src/__tests__/flow-reducer-bridge-contract.test.ts +0 -108
- package/src/__tests__/flow-reducer-seed-on-start.test.ts +0 -61
- package/src/__tests__/flow-yaml-parse.test.ts +0 -124
- package/src/__tests__/flows-for-cwd.test.ts +0 -51
- package/src/__tests__/flowsAvailability.test.ts +0 -79
- package/src/__tests__/manifest-discoverability.test.ts +0 -97
- package/src/__tests__/node-kind-reducer.test.ts +0 -135
- package/src/__tests__/plugin-action-handler.test.ts +0 -54
- package/src/__tests__/reducer-parity.test.ts +0 -106
- package/src/__tests__/render-actions.test.ts +0 -63
- package/src/__tests__/session-flow-actions-edit.test.tsx +0 -98
- package/src/bridge/AGENTS.md +0 -8
- package/src/client/AGENTS.md +0 -32
- package/src/server/AGENTS.md +0 -10
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FlowAgentCard code-handler source open.
|
|
3
|
-
*
|
|
4
|
-
* Code / code-decision nodes carry `codeTarget` (the resolved .ts handler path,
|
|
5
|
-
* emitted absolute by the flow runtime). The card renders an mdiCodeBraces
|
|
6
|
-
* button that opens a ui:dialog, fetches the handler via
|
|
7
|
-
* /api/pi-resource-file, and renders it wrapped in a fenced ```ts block.
|
|
8
|
-
* See change: open-code-handler-from-flow-card.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
createUiPrimitiveRegistry,
|
|
13
|
-
registerUiPrimitive,
|
|
14
|
-
UiPrimitiveProvider,
|
|
15
|
-
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
16
|
-
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
17
|
-
import type { FlowAgentState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
18
|
-
import { cleanup, fireEvent, render, waitFor } from "@testing-library/react";
|
|
19
|
-
import type React from "react";
|
|
20
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
21
|
-
import { FlowAgentCard } from "../client/FlowAgentCard.js";
|
|
22
|
-
|
|
23
|
-
const registry = createUiPrimitiveRegistry();
|
|
24
|
-
|
|
25
|
-
// AgentCardShell: render headerRight + children + forward onClick.
|
|
26
|
-
registerUiPrimitive(
|
|
27
|
-
registry,
|
|
28
|
-
UI_PRIMITIVE_KEYS.agentCard,
|
|
29
|
-
(({ children, headerRight, onClick }: { children: React.ReactNode; headerRight?: React.ReactNode; onClick?: () => void }) => (
|
|
30
|
-
<div data-testid="card" onClick={onClick}>
|
|
31
|
-
<div>{headerRight}</div>
|
|
32
|
-
{children}
|
|
33
|
-
</div>
|
|
34
|
-
)) as never,
|
|
35
|
-
);
|
|
36
|
-
registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.formatTokens, ((n: number) => String(n)) as never);
|
|
37
|
-
registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.formatDuration, ((n: number) => String(n)) as never);
|
|
38
|
-
// Dialog: render children only when open.
|
|
39
|
-
registerUiPrimitive(
|
|
40
|
-
registry,
|
|
41
|
-
UI_PRIMITIVE_KEYS.dialog,
|
|
42
|
-
(({ open, title, children }: { open: boolean; title?: string; children: React.ReactNode }) =>
|
|
43
|
-
open ? (
|
|
44
|
-
<div data-testid="dialog">
|
|
45
|
-
<div data-testid="dialog-title">{title}</div>
|
|
46
|
-
{children}
|
|
47
|
-
</div>
|
|
48
|
-
) : null) as never,
|
|
49
|
-
);
|
|
50
|
-
// MarkdownContent: surface the raw content for fence assertions.
|
|
51
|
-
registerUiPrimitive(
|
|
52
|
-
registry,
|
|
53
|
-
UI_PRIMITIVE_KEYS.markdownContent,
|
|
54
|
-
(({ content }: { content: string }) => <pre data-testid="md">{content}</pre>) as never,
|
|
55
|
-
);
|
|
56
|
-
// LogBlock: preview mode surfaces last-N lines + a copy button carrying the
|
|
57
|
-
// FULL text so the code-node preview's copy/expand affordances are testable.
|
|
58
|
-
registerUiPrimitive(
|
|
59
|
-
registry,
|
|
60
|
-
UI_PRIMITIVE_KEYS.logBlock,
|
|
61
|
-
(({ label, text, previewLines = 3 }: { label: string; text: string; previewLines?: number }) => (
|
|
62
|
-
<div data-testid="log-block">
|
|
63
|
-
<span>{label}</span>
|
|
64
|
-
<button type="button" data-testid="log-block-copy" data-full={text}>copy</button>
|
|
65
|
-
<pre data-testid="log-block-body">{text.split("\n").slice(-previewLines).join("\n")}</pre>
|
|
66
|
-
</div>
|
|
67
|
-
)) as never,
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
function makeAgent(over: Partial<FlowAgentState>): FlowAgentState {
|
|
71
|
-
return {
|
|
72
|
-
agentName: "verify",
|
|
73
|
-
stepId: "verify",
|
|
74
|
-
status: "complete",
|
|
75
|
-
blockedBy: [],
|
|
76
|
-
recentTools: [],
|
|
77
|
-
detailHistory: [],
|
|
78
|
-
...over,
|
|
79
|
-
} as FlowAgentState;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function renderCard(agent: FlowAgentState) {
|
|
83
|
-
return render(
|
|
84
|
-
<UiPrimitiveProvider value={registry}>
|
|
85
|
-
<FlowAgentCard agent={agent} />
|
|
86
|
-
</UiPrimitiveProvider>,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const HANDLER_PATH = "/home/u/proj/.pi/flows/flows/custom/test-flow/verify.ts";
|
|
91
|
-
|
|
92
|
-
afterEach(() => {
|
|
93
|
-
cleanup();
|
|
94
|
-
vi.unstubAllGlobals();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("FlowAgentCard code-handler source", () => {
|
|
98
|
-
it("3.1 renders the code button only for code nodes with a target", () => {
|
|
99
|
-
const { queryByTitle, unmount } = renderCard(
|
|
100
|
-
makeAgent({ nodeKind: "code", codeTarget: HANDLER_PATH }),
|
|
101
|
-
);
|
|
102
|
-
expect(queryByTitle("View handler source")).not.toBeNull();
|
|
103
|
-
unmount();
|
|
104
|
-
|
|
105
|
-
// agent node — no code button
|
|
106
|
-
const agentCard = renderCard(makeAgent({ nodeKind: "agent" }));
|
|
107
|
-
expect(agentCard.queryByTitle("View handler source")).toBeNull();
|
|
108
|
-
agentCard.unmount();
|
|
109
|
-
|
|
110
|
-
// code node without target — no code button
|
|
111
|
-
const noTarget = renderCard(makeAgent({ nodeKind: "code", codeTarget: undefined }));
|
|
112
|
-
expect(noTarget.queryByTitle("View handler source")).toBeNull();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("3.2 clicking the code button opens a dialog and fetches the handler path", async () => {
|
|
116
|
-
const fetchMock = vi.fn(async () => ({
|
|
117
|
-
json: async () => ({ success: true, data: { type: "file", content: "export const x = 1;" } }),
|
|
118
|
-
}));
|
|
119
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
120
|
-
|
|
121
|
-
const { getByTitle, findByTestId } = renderCard(
|
|
122
|
-
makeAgent({ nodeKind: "code", codeTarget: HANDLER_PATH }),
|
|
123
|
-
);
|
|
124
|
-
fireEvent.click(getByTitle("View handler source"));
|
|
125
|
-
|
|
126
|
-
await findByTestId("dialog");
|
|
127
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
128
|
-
`/api/pi-resource-file?path=${encodeURIComponent(HANDLER_PATH)}`,
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("3.3 loaded handler content is wrapped in a ```ts fence", async () => {
|
|
133
|
-
vi.stubGlobal(
|
|
134
|
-
"fetch",
|
|
135
|
-
vi.fn(async () => ({
|
|
136
|
-
json: async () => ({ success: true, data: { type: "file", content: "export const x = 1;" } }),
|
|
137
|
-
})),
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
const { getByTitle, findByTestId } = renderCard(
|
|
141
|
-
makeAgent({ nodeKind: "code-decision", codeTarget: HANDLER_PATH }),
|
|
142
|
-
);
|
|
143
|
-
fireEvent.click(getByTitle("View handler source"));
|
|
144
|
-
|
|
145
|
-
const md = await findByTestId("md");
|
|
146
|
-
expect(md.textContent).toBe("```ts\nexport const x = 1;\n```");
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("3.5 code-node log preview renders via LogBlock with copy carrying the FULL log", () => {
|
|
150
|
-
const agent = makeAgent({
|
|
151
|
-
nodeKind: "code",
|
|
152
|
-
codeTarget: HANDLER_PATH,
|
|
153
|
-
detailHistory: [
|
|
154
|
-
{ kind: "text", text: "line-1" },
|
|
155
|
-
{ kind: "text", text: "line-2" },
|
|
156
|
-
{ kind: "text", text: "line-3" },
|
|
157
|
-
{ kind: "text", text: "line-4" },
|
|
158
|
-
],
|
|
159
|
-
} as Partial<FlowAgentState>);
|
|
160
|
-
const { getByTestId } = renderCard(agent);
|
|
161
|
-
const body = getByTestId("log-block-body");
|
|
162
|
-
// Preview shows the last 3 lines.
|
|
163
|
-
expect(body.textContent).toContain("line-4");
|
|
164
|
-
expect(body.textContent).not.toContain("line-1");
|
|
165
|
-
// Copy carries the FULL log (all 4 lines).
|
|
166
|
-
expect(getByTestId("log-block-copy").getAttribute("data-full")).toBe(
|
|
167
|
-
"line-1\nline-2\nline-3\nline-4",
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("3.4 fetch error surfaces in the dialog", async () => {
|
|
172
|
-
vi.stubGlobal(
|
|
173
|
-
"fetch",
|
|
174
|
-
vi.fn(async () => ({
|
|
175
|
-
json: async () => ({ success: false, error: "path not in allowed resource location" }),
|
|
176
|
-
})),
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
const { getByTitle, findByTestId } = renderCard(
|
|
180
|
-
makeAgent({ nodeKind: "code", codeTarget: HANDLER_PATH }),
|
|
181
|
-
);
|
|
182
|
-
fireEvent.click(getByTitle("View handler source"));
|
|
183
|
-
|
|
184
|
-
const dialog = await findByTestId("dialog");
|
|
185
|
-
await waitFor(() =>
|
|
186
|
-
expect(dialog.textContent).toContain("path not in allowed resource location"),
|
|
187
|
-
);
|
|
188
|
-
expect(dialog.querySelector('[data-testid="md"]')).toBeNull();
|
|
189
|
-
});
|
|
190
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-agent USD cost surfacing (change surface-flow-agent-cost).
|
|
3
|
-
*
|
|
4
|
-
* Pins: reducer stores `result.cost` verbatim onto `FlowAgentState.cost`
|
|
5
|
-
* (undefined when absent), the `formatCost` precision rule (>= 1 → 2dp,
|
|
6
|
-
* < 1 → 4dp), the card stats-line `$` segment (shown when > 0, suppressed
|
|
7
|
-
* when 0/undefined), and the detail header cost value.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
createUiPrimitiveRegistry,
|
|
12
|
-
registerUiPrimitive,
|
|
13
|
-
UiPrimitiveProvider,
|
|
14
|
-
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
15
|
-
import { withUiPrimitiveProvider } from "@blackbelt-technology/dashboard-plugin-runtime/test-support";
|
|
16
|
-
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
17
|
-
import type {
|
|
18
|
-
DashboardEvent,
|
|
19
|
-
FlowAgentState,
|
|
20
|
-
FlowState,
|
|
21
|
-
} from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
22
|
-
import { cleanup, render } from "@testing-library/react";
|
|
23
|
-
import type React from "react";
|
|
24
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
25
|
-
import { FlowAgentCard, formatCost } from "../client/FlowAgentCard.js";
|
|
26
|
-
import { FlowAgentDetail } from "../client/FlowAgentDetail.js";
|
|
27
|
-
import { reduceFlowEvent } from "../reducer.js";
|
|
28
|
-
|
|
29
|
-
function ev(type: string, data: Record<string, unknown>): DashboardEvent {
|
|
30
|
-
return { seq: 1, timestamp: 0, sessionId: "s1", eventType: type, data } as unknown as DashboardEvent;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function fold(events: Array<[string, Record<string, unknown>]>): FlowState | null {
|
|
34
|
-
let s: FlowState | null = null;
|
|
35
|
-
for (const [t, d] of events) s = reduceFlowEvent(s, ev(t, d));
|
|
36
|
-
return s;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const started: Array<[string, Record<string, unknown>]> = [
|
|
40
|
-
["flow_started", {
|
|
41
|
-
flowName: "f", task: "t",
|
|
42
|
-
steps: [{ id: "a", stepType: "agent", agent: "a", blockedBy: [] }],
|
|
43
|
-
}],
|
|
44
|
-
["flow_agent_started", { agentName: "a", stepId: "a", nodeKind: "agent" }],
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
describe("cost reducer (task 1.1, 1.2)", () => {
|
|
48
|
-
it("stores result.cost verbatim onto FlowAgentState.cost", () => {
|
|
49
|
-
const s = fold([
|
|
50
|
-
...started,
|
|
51
|
-
["flow_agent_complete", { agentName: "a", stepId: "a", result: { success: true, cost: 0.0142 } }],
|
|
52
|
-
])!;
|
|
53
|
-
expect(s.agents.get("a")?.cost).toBe(0.0142);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("leaves cost undefined when the completion event omits it", () => {
|
|
57
|
-
const s = fold([
|
|
58
|
-
...started,
|
|
59
|
-
["flow_agent_complete", { agentName: "a", stepId: "a", result: { success: true } }],
|
|
60
|
-
])!;
|
|
61
|
-
expect(s.agents.get("a")?.cost).toBeUndefined();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("formatCost helper (task 1.3)", () => {
|
|
66
|
-
it("uses two decimals at or above $1", () => {
|
|
67
|
-
expect(formatCost(1.2)).toBe("$1.20");
|
|
68
|
-
expect(formatCost(12)).toBe("$12.00");
|
|
69
|
-
expect(formatCost(1)).toBe("$1.00"); // exact >= 1 boundary
|
|
70
|
-
});
|
|
71
|
-
it("uses four decimals below $1", () => {
|
|
72
|
-
expect(formatCost(0.0142)).toBe("$0.0142");
|
|
73
|
-
expect(formatCost(0.5)).toBe("$0.5000");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// --- Card render (task 1.4) ---
|
|
78
|
-
const cardRegistry = createUiPrimitiveRegistry();
|
|
79
|
-
registerUiPrimitive(
|
|
80
|
-
cardRegistry,
|
|
81
|
-
UI_PRIMITIVE_KEYS.agentCard,
|
|
82
|
-
(({ children, stats }: { children: React.ReactNode; stats?: React.ReactNode }) => (
|
|
83
|
-
<div data-testid="card"><div data-testid="stats">{stats}</div>{children}</div>
|
|
84
|
-
)) as never,
|
|
85
|
-
);
|
|
86
|
-
registerUiPrimitive(cardRegistry, UI_PRIMITIVE_KEYS.formatTokens, ((n: number) => String(n)) as never);
|
|
87
|
-
registerUiPrimitive(cardRegistry, UI_PRIMITIVE_KEYS.formatDuration, ((n: number) => `${n}ms`) as never);
|
|
88
|
-
registerUiPrimitive(cardRegistry, UI_PRIMITIVE_KEYS.dialog, (() => null) as never);
|
|
89
|
-
registerUiPrimitive(cardRegistry, UI_PRIMITIVE_KEYS.markdownContent, (() => null) as never);
|
|
90
|
-
|
|
91
|
-
function makeAgent(over: Partial<FlowAgentState>): FlowAgentState {
|
|
92
|
-
return {
|
|
93
|
-
agentName: "a", stepId: "a", status: "complete", blockedBy: [],
|
|
94
|
-
recentTools: [], detailHistory: [],
|
|
95
|
-
tokens: { input: 12000, output: 3000 }, duration: 4200,
|
|
96
|
-
...over,
|
|
97
|
-
} as FlowAgentState;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function renderCard(agent: FlowAgentState) {
|
|
101
|
-
return render(
|
|
102
|
-
<UiPrimitiveProvider value={cardRegistry}>
|
|
103
|
-
<FlowAgentCard agent={agent} />
|
|
104
|
-
</UiPrimitiveProvider>,
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
describe("FlowAgentCard cost segment (task 1.4)", () => {
|
|
109
|
-
afterEach(cleanup);
|
|
110
|
-
|
|
111
|
-
it("shows a $ segment when cost > 0", () => {
|
|
112
|
-
const { getByTestId } = renderCard(makeAgent({ cost: 0.0142 }));
|
|
113
|
-
expect(getByTestId("stats").textContent).toContain("$0.0142");
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("omits the segment when cost is 0 (no $, no dangling separator)", () => {
|
|
117
|
-
const { getByTestId } = renderCard(makeAgent({ cost: 0 }));
|
|
118
|
-
const text = getByTestId("stats").textContent ?? "";
|
|
119
|
-
expect(text).not.toContain("$");
|
|
120
|
-
expect(text).toContain("12000");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("omits the segment when cost is undefined", () => {
|
|
124
|
-
const { getByTestId } = renderCard(makeAgent({ cost: undefined }));
|
|
125
|
-
expect(getByTestId("stats").textContent ?? "").not.toContain("$");
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// --- Detail header (task 1.5) ---
|
|
130
|
-
function renderDetail(agent: FlowAgentState) {
|
|
131
|
-
return render(
|
|
132
|
-
withUiPrimitiveProvider(
|
|
133
|
-
{
|
|
134
|
-
"ui:markdown-content": (({ content }: { content: string }) => <div>{content}</div>) as never,
|
|
135
|
-
"ui:format-tokens": ((n: number) => String(n)) as never,
|
|
136
|
-
"ui:format-duration": ((n: number) => `${n}ms`) as never,
|
|
137
|
-
},
|
|
138
|
-
<FlowAgentDetail agent={agent} />,
|
|
139
|
-
),
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
describe("FlowAgentDetail cost in header (task 1.5)", () => {
|
|
144
|
-
afterEach(cleanup);
|
|
145
|
-
|
|
146
|
-
it("shows cost when present and > 0", () => {
|
|
147
|
-
const { container } = renderDetail(makeAgent({ cost: 0.0142 }));
|
|
148
|
-
expect(container.textContent).toContain("$0.0142");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("omits cost when 0", () => {
|
|
152
|
-
const { container } = renderDetail(makeAgent({ cost: 0 }));
|
|
153
|
-
expect(container.textContent).not.toContain("$");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("omits cost when absent", () => {
|
|
157
|
-
const { container } = renderDetail(makeAgent({ cost: undefined }));
|
|
158
|
-
expect(container.textContent).not.toContain("$");
|
|
159
|
-
});
|
|
160
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* flow_agent_error reducer case (change: replay-persisted-flow-runs).
|
|
3
|
-
* pi-flows now emits flow:agent-error { agentName, stepId, text } for
|
|
4
|
-
* step-level agent failures. The reducer appends { kind:"error", text } to
|
|
5
|
-
* the agent's detailHistory. The error variant of FlowDetailEntry already
|
|
6
|
-
* exists; this pins its producer case. Status stays owned by
|
|
7
|
-
* flow_agent_complete — the error case does not change it.
|
|
8
|
-
*/
|
|
9
|
-
import { describe, it, expect } from "vitest";
|
|
10
|
-
import { reduceFlowEvent } from "../reducer.js";
|
|
11
|
-
import type { DashboardEvent, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
12
|
-
|
|
13
|
-
function ev(type: string, data: Record<string, unknown>): DashboardEvent {
|
|
14
|
-
return { seq: 1, timestamp: 0, sessionId: "s1", eventType: type, data } as unknown as DashboardEvent;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function startedWithAgent(): FlowState {
|
|
18
|
-
const s = reduceFlowEvent(
|
|
19
|
-
null,
|
|
20
|
-
ev("flow_started", { flowName: "f", task: "t", steps: [{ id: "research", agent: "researcher", blockedBy: [] }] }),
|
|
21
|
-
);
|
|
22
|
-
return reduceFlowEvent(s, ev("flow_agent_started", { agentName: "researcher", stepId: "research" }))!;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("reduceFlowEvent — flow_agent_error", () => {
|
|
26
|
-
it("appends an { kind: 'error', text } entry to the agent detailHistory", () => {
|
|
27
|
-
const s = startedWithAgent();
|
|
28
|
-
const next = reduceFlowEvent(
|
|
29
|
-
s,
|
|
30
|
-
ev("flow_agent_error", { agentName: "researcher", stepId: "research", text: "tool quota exceeded" }),
|
|
31
|
-
);
|
|
32
|
-
const agent = next!.agents.get("research")!;
|
|
33
|
-
const last = agent.detailHistory[agent.detailHistory.length - 1];
|
|
34
|
-
expect(last).toEqual({ kind: "error", text: "tool quota exceeded" });
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("ignores events with empty text (no-op)", () => {
|
|
38
|
-
const s = startedWithAgent();
|
|
39
|
-
const before = s.agents.get("research")!.detailHistory.length;
|
|
40
|
-
const next = reduceFlowEvent(s, ev("flow_agent_error", { agentName: "researcher", stepId: "research", text: "" }));
|
|
41
|
-
expect(next!.agents.get("research")!.detailHistory.length).toBe(before);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("does not change the agent status (status owned by flow_agent_complete)", () => {
|
|
45
|
-
const s = startedWithAgent();
|
|
46
|
-
const statusBefore = s.agents.get("research")!.status;
|
|
47
|
-
const next = reduceFlowEvent(
|
|
48
|
-
s,
|
|
49
|
-
ev("flow_agent_error", { agentName: "researcher", stepId: "research", text: "boom" }),
|
|
50
|
-
);
|
|
51
|
-
expect(next!.agents.get("research")!.status).toBe(statusBefore);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("locates the agent by agentName when stepId is absent", () => {
|
|
55
|
-
const s = startedWithAgent();
|
|
56
|
-
const next = reduceFlowEvent(s, ev("flow_agent_error", { agentName: "researcher", text: "boom" }));
|
|
57
|
-
const agent = next!.agents.get("research")!;
|
|
58
|
-
expect(agent.detailHistory.some((e) => e.kind === "error" && e.text === "boom")).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-session collapse persistence. See change: fix-flow-ui-graph-zoom-summary.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { act, renderHook } from "@testing-library/react";
|
|
6
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
7
|
-
import { FLOW_SHOW_ERROR_ROUTES_KEY, flowCollapseKey, useFlowCollapsePersisted, usePersistedToggle } from "../client/flow-collapse-storage.js";
|
|
8
|
-
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
localStorage.clear();
|
|
11
|
-
vi.restoreAllMocks();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("useFlowCollapsePersisted", () => {
|
|
15
|
-
it("defaults to expanded (false) for an untouched session", () => {
|
|
16
|
-
const { result } = renderHook(() => useFlowCollapsePersisted("sess-A", "summary"));
|
|
17
|
-
expect(result.current[0]).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("persists the collapse across remounts for the same session", () => {
|
|
21
|
-
const first = renderHook(() => useFlowCollapsePersisted("sess-A", "summary"));
|
|
22
|
-
act(() => first.result.current[1]()); // toggle → collapsed
|
|
23
|
-
expect(first.result.current[0]).toBe(true);
|
|
24
|
-
expect(localStorage.getItem(flowCollapseKey("summary", "sess-A"))).toBe("true");
|
|
25
|
-
|
|
26
|
-
// Fresh mount (same session) reads the persisted value.
|
|
27
|
-
const second = renderHook(() => useFlowCollapsePersisted("sess-A", "summary"));
|
|
28
|
-
expect(second.result.current[0]).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("isolates state per session id", () => {
|
|
32
|
-
const a = renderHook(() => useFlowCollapsePersisted("sess-A", "summary"));
|
|
33
|
-
act(() => a.result.current[1]()); // A collapsed
|
|
34
|
-
const b = renderHook(() => useFlowCollapsePersisted("sess-B", "summary"));
|
|
35
|
-
expect(b.result.current[0]).toBe(false); // B untouched → expanded
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("isolates state per kind for the same session", () => {
|
|
39
|
-
const summary = renderHook(() => useFlowCollapsePersisted("sess-A", "summary"));
|
|
40
|
-
act(() => summary.result.current[1]());
|
|
41
|
-
const dashboard = renderHook(() => useFlowCollapsePersisted("sess-A", "dashboard"));
|
|
42
|
-
expect(dashboard.result.current[0]).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("degrades to in-memory when localStorage.setItem throws", () => {
|
|
46
|
-
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
|
|
47
|
-
throw new Error("quota");
|
|
48
|
-
});
|
|
49
|
-
const { result } = renderHook(() => useFlowCollapsePersisted("sess-A", "summary"));
|
|
50
|
-
expect(() => act(() => result.current[1]())).not.toThrow();
|
|
51
|
-
expect(result.current[0]).toBe(true); // toggle still works in-memory
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("is purely in-memory when sessionId is undefined", () => {
|
|
55
|
-
const setSpy = vi.spyOn(Storage.prototype, "setItem");
|
|
56
|
-
const { result } = renderHook(() => useFlowCollapsePersisted(undefined, "summary"));
|
|
57
|
-
act(() => result.current[1]());
|
|
58
|
-
expect(result.current[0]).toBe(true);
|
|
59
|
-
expect(setSpy).not.toHaveBeenCalled();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe("usePersistedToggle (global error-route visibility)", () => {
|
|
64
|
-
it("defaults to the fallback when unset", () => {
|
|
65
|
-
const { result } = renderHook(() => usePersistedToggle(FLOW_SHOW_ERROR_ROUTES_KEY, false));
|
|
66
|
-
expect(result.current[0]).toBe(false);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("persists on/off across remounts (global key, no session)", () => {
|
|
70
|
-
const first = renderHook(() => usePersistedToggle(FLOW_SHOW_ERROR_ROUTES_KEY, false));
|
|
71
|
-
act(() => first.result.current[1]()); // on
|
|
72
|
-
expect(first.result.current[0]).toBe(true);
|
|
73
|
-
expect(localStorage.getItem(FLOW_SHOW_ERROR_ROUTES_KEY)).toBe("true");
|
|
74
|
-
|
|
75
|
-
const second = renderHook(() => usePersistedToggle(FLOW_SHOW_ERROR_ROUTES_KEY, false));
|
|
76
|
-
expect(second.result.current[0]).toBe(true); // remount reads persisted ON
|
|
77
|
-
|
|
78
|
-
act(() => second.result.current[1]()); // off
|
|
79
|
-
expect(localStorage.getItem(FLOW_SHOW_ERROR_ROUTES_KEY)).toBe("false");
|
|
80
|
-
const third = renderHook(() => usePersistedToggle(FLOW_SHOW_ERROR_ROUTES_KEY, false));
|
|
81
|
-
expect(third.result.current[0]).toBe(false);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("degrades to in-memory when localStorage throws", () => {
|
|
85
|
-
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => { throw new Error("quota"); });
|
|
86
|
-
const { result } = renderHook(() => usePersistedToggle(FLOW_SHOW_ERROR_ROUTES_KEY, false));
|
|
87
|
-
expect(() => act(() => result.current[1]())).not.toThrow();
|
|
88
|
-
expect(result.current[0]).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
});
|