@blackbelt-technology/pi-dashboard-flows-plugin 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -5
- package/src/client/FlowAgentCard.tsx +4 -8
- package/src/client/FlowAgentDetail.tsx +1 -1
- package/src/client/FlowDashboard.tsx +6 -2
- package/src/client/FlowInputWiring.tsx +2 -2
- package/src/client/FlowsCommandRoutes.tsx +13 -5
- package/src/client/FlowsSettings.tsx +4 -4
- package/src/client/SessionFlowActions.tsx +9 -4
- package/src/client/format-cost.ts +21 -0
- package/src/client/send-safe.ts +19 -0
- package/src/AGENTS.md +0 -8
- package/src/__tests__/FlowGraph.test.ts +0 -305
- package/src/__tests__/FlowInputWiring.test.tsx +0 -97
- package/src/__tests__/FlowSummary.test.tsx +0 -331
- package/src/__tests__/FlowYamlPreview.test.tsx +0 -75
- package/src/__tests__/FlowsSessionStateContext.test.tsx +0 -223
- package/src/__tests__/FlowsUiStateContext.test.tsx +0 -140
- package/src/__tests__/authoring-renderers.test.tsx +0 -190
- package/src/__tests__/automation-actions.test.ts +0 -117
- package/src/__tests__/flow-agent-card-code-source.test.tsx +0 -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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbelt-technology/pi-dashboard-flows-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Flow rendering plugin for pi-dashboard — pi-flows event reaction (FlowDashboard, FlowAgentCard, FlowArchitect, etc.)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -27,7 +27,12 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
|
-
"src/"
|
|
30
|
+
"src/",
|
|
31
|
+
"!**/AGENTS.md",
|
|
32
|
+
"!**/*.AGENTS.md",
|
|
33
|
+
"!**/__tests__",
|
|
34
|
+
"!**/*.test.ts",
|
|
35
|
+
"!**/*.test.tsx"
|
|
31
36
|
],
|
|
32
37
|
"pi-dashboard-plugin": {
|
|
33
38
|
"id": "flows",
|
|
@@ -83,9 +88,12 @@
|
|
|
83
88
|
},
|
|
84
89
|
"//deps-rationale": "client-utils retained for hooks (useMobile, useZoomPan) and Phase-2 extension-ui slot consumers (AgentMetricSlot, BreadcrumbSlot, GateSlot, aggregateGateState helper). All UI primitive components (AgentCardShell, MarkdownContent, ConfirmDialog, DialogPortal, SearchableSelectDialog, ZoomControls, format-tokens, format-duration) flow through the UI primitive registry per add-plugin-ui-primitive-registry.",
|
|
85
90
|
"dependencies": {
|
|
86
|
-
"@blackbelt-technology/dashboard-plugin-runtime": "^0.
|
|
87
|
-
"@blackbelt-technology/pi-dashboard-client-utils": "^0.
|
|
88
|
-
"@blackbelt-technology/pi-dashboard-shared": "^0.
|
|
91
|
+
"@blackbelt-technology/dashboard-plugin-runtime": "^0.8.0",
|
|
92
|
+
"@blackbelt-technology/pi-dashboard-client-utils": "^0.8.0",
|
|
93
|
+
"@blackbelt-technology/pi-dashboard-shared": "^0.8.0",
|
|
94
|
+
"@mdi/js": "^7.4.47",
|
|
95
|
+
"@mdi/react": "^1.6.1",
|
|
96
|
+
"dagre-d3-es": "^7.0.14",
|
|
89
97
|
"yaml": "^2.9.0"
|
|
90
98
|
},
|
|
91
99
|
"devDependencies": {
|
|
@@ -8,6 +8,7 @@ import { mdiCallSplit, mdiCodeBraces, mdiCodeTags, mdiEyeOffOutline, mdiEyeOutli
|
|
|
8
8
|
import { Icon } from "@mdi/react";
|
|
9
9
|
import React, { useEffect, useState } from "react";
|
|
10
10
|
import { FlowAgentDetail } from "./FlowAgentDetail.js";
|
|
11
|
+
import { formatCost } from "./format-cost.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* State of the agent-source fetch for the document-icon popover.
|
|
@@ -19,14 +20,6 @@ import { FlowAgentDetail } from "./FlowAgentDetail.js";
|
|
|
19
20
|
*
|
|
20
21
|
* See change: add-ui-popover-primitive.
|
|
21
22
|
*/
|
|
22
|
-
/**
|
|
23
|
-
* Format an accumulated USD cost, matching the pi-flows TUI precision
|
|
24
|
-
* (`agent-card.ts`): two decimals at or above $1, four decimals sub-dollar.
|
|
25
|
-
* Exported so `FlowAgentDetail` renders identical values (DRY, D4).
|
|
26
|
-
*/
|
|
27
|
-
export function formatCost(n: number): string {
|
|
28
|
-
return `$${n >= 1 ? n.toFixed(2) : n.toFixed(4)}`;
|
|
29
|
-
}
|
|
30
23
|
|
|
31
24
|
type AgentSourceState =
|
|
32
25
|
| { kind: "idle" }
|
|
@@ -388,6 +381,9 @@ export function FlowAgentCard({
|
|
|
388
381
|
size="lg"
|
|
389
382
|
flush
|
|
390
383
|
>
|
|
384
|
+
{/* STAYS: a DEFINITE height pin, not a duplicated flex context —
|
|
385
|
+
the popout keeps a stable height as the transcript grows.
|
|
386
|
+
See change: fix-flush-dialog-scroll-and-close-collision. */}
|
|
391
387
|
<div className="h-[70vh] overflow-hidden flex flex-col">
|
|
392
388
|
<FlowAgentDetail
|
|
393
389
|
agent={agent}
|
|
@@ -21,7 +21,7 @@ import type {
|
|
|
21
21
|
FlowDetailEntry,
|
|
22
22
|
} from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
23
23
|
import React from "react";
|
|
24
|
-
import { formatCost } from "./
|
|
24
|
+
import { formatCost } from "./format-cost.js";
|
|
25
25
|
|
|
26
26
|
function mapFlowStatus(status: FlowAgentStatus): MinimalChatStatus {
|
|
27
27
|
switch (status) {
|
|
@@ -15,6 +15,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
|
15
15
|
import { FlowAgentCard } from "./FlowAgentCard.js";
|
|
16
16
|
import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
|
|
17
17
|
import { FlowQuestionCard } from "./FlowQuestionCard.js";
|
|
18
|
+
import { makeSafeSend } from "./send-safe.js";
|
|
18
19
|
import { FlowQuestionTranscriptPill } from "./FlowQuestionTranscriptPill.js";
|
|
19
20
|
import { FlowSummary } from "./FlowSummary.js";
|
|
20
21
|
import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
|
|
@@ -337,6 +338,9 @@ function FlowQuestionsSection({
|
|
|
337
338
|
}) {
|
|
338
339
|
const requests = useSessionInteractiveRequests(sessionId);
|
|
339
340
|
const send = usePluginSend();
|
|
341
|
+
// Card callbacks cannot own the send promise — discard it explicitly.
|
|
342
|
+
// See change: cleanup-client-plugin-promises.
|
|
343
|
+
const dispatch = useMemo(() => makeSafeSend(send), [send]);
|
|
340
344
|
|
|
341
345
|
const queue = useMemo<InteractiveUiRequestSnapshot[]>(() => {
|
|
342
346
|
const out: InteractiveUiRequestSnapshot[] = [];
|
|
@@ -363,7 +367,7 @@ function FlowQuestionsSection({
|
|
|
363
367
|
const question = typeof props.question === "string" ? props.question : "";
|
|
364
368
|
if (req.status === "pending") {
|
|
365
369
|
const submit = (answer: string) => {
|
|
366
|
-
|
|
370
|
+
dispatch({
|
|
367
371
|
type: "prompt_response",
|
|
368
372
|
sessionId,
|
|
369
373
|
promptId: req.requestId,
|
|
@@ -372,7 +376,7 @@ function FlowQuestionsSection({
|
|
|
372
376
|
});
|
|
373
377
|
};
|
|
374
378
|
const dismiss = () => {
|
|
375
|
-
|
|
379
|
+
dispatch({ type: "prompt_cancel", sessionId, promptId: req.requestId });
|
|
376
380
|
};
|
|
377
381
|
return (
|
|
378
382
|
<FlowQuestionCard
|
|
@@ -181,7 +181,7 @@ export function FlowInputWiring({ payload, onChange, cwd }: FlowInputWiringProps
|
|
|
181
181
|
className={`px-2 text-[10px] ${
|
|
182
182
|
boundToTrigger
|
|
183
183
|
? "text-[var(--text-secondary)]"
|
|
184
|
-
: "bg-[var(--accent
|
|
184
|
+
: "bg-[var(--accent-solid)] text-white"
|
|
185
185
|
}`}
|
|
186
186
|
>
|
|
187
187
|
literal
|
|
@@ -192,7 +192,7 @@ export function FlowInputWiring({ payload, onChange, cwd }: FlowInputWiringProps
|
|
|
192
192
|
onClick={() => setInput(f.name, TRIGGER_TOKEN)}
|
|
193
193
|
className={`border-l border-[var(--border-secondary)] px-2 text-[10px] ${
|
|
194
194
|
boundToTrigger
|
|
195
|
-
? "bg-[var(--accent
|
|
195
|
+
? "bg-[var(--accent-solid)] text-white"
|
|
196
196
|
: "text-[var(--text-secondary)]"
|
|
197
197
|
}`}
|
|
198
198
|
>
|
|
@@ -24,16 +24,21 @@ import {
|
|
|
24
24
|
useSessionData,
|
|
25
25
|
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
26
26
|
import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
|
|
27
|
+
import { makeSafeSend, type PluginSend } from "./send-safe.js";
|
|
27
28
|
|
|
28
29
|
// ── Helpers ────────────────────────────────────────────────────────
|
|
29
30
|
|
|
31
|
+
// Every flow action routes through here, so the discard is stated once at the
|
|
32
|
+
// shared seam rather than at each of the five call sites. A dropped
|
|
33
|
+
// `flow_management` message otherwise leaves the UI showing a run the server
|
|
34
|
+
// never started. See change: cleanup-client-plugin-promises.
|
|
30
35
|
function dispatchFlowAction(
|
|
31
|
-
send:
|
|
36
|
+
send: PluginSend,
|
|
32
37
|
sessionId: string,
|
|
33
38
|
action: string,
|
|
34
39
|
opts?: { flowName?: string; task?: string; description?: string },
|
|
35
40
|
): void {
|
|
36
|
-
send({
|
|
41
|
+
makeSafeSend(send)({
|
|
37
42
|
type: "flow_management",
|
|
38
43
|
sessionId,
|
|
39
44
|
action,
|
|
@@ -59,6 +64,9 @@ interface RouteProps {
|
|
|
59
64
|
export function FlowsListRoute({ session, onClose }: RouteProps) {
|
|
60
65
|
const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
|
|
61
66
|
const send = usePluginSend();
|
|
67
|
+
// Dialog `onSelect` cannot own the send promise — discard it explicitly.
|
|
68
|
+
// See change: cleanup-client-plugin-promises.
|
|
69
|
+
const dispatch = makeSafeSend(send);
|
|
62
70
|
const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
|
|
63
71
|
const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
|
|
64
72
|
const [launchTarget, setLaunchTarget] = useState<FlowInfo | null>(null);
|
|
@@ -112,17 +120,17 @@ export function FlowsListRoute({ session, onClose }: RouteProps) {
|
|
|
112
120
|
// Send the user to the /flows:new route via pluginRouter.
|
|
113
121
|
// Until pluginRouter wiring lands, just open the new dialog
|
|
114
122
|
// inline by closing this and dispatching the new command.
|
|
115
|
-
|
|
123
|
+
dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:new" });
|
|
116
124
|
onClose();
|
|
117
125
|
return;
|
|
118
126
|
}
|
|
119
127
|
if (value === "__edit__") {
|
|
120
|
-
|
|
128
|
+
dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:edit" });
|
|
121
129
|
onClose();
|
|
122
130
|
return;
|
|
123
131
|
}
|
|
124
132
|
if (value === "__delete__") {
|
|
125
|
-
|
|
133
|
+
dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:delete" });
|
|
126
134
|
onClose();
|
|
127
135
|
return;
|
|
128
136
|
}
|
|
@@ -38,11 +38,11 @@ export function FlowsSettings(): React.ReactElement {
|
|
|
38
38
|
await send({ type: "plugin_config_write", id: "flows", config: { editFlow: valuesRef.current } });
|
|
39
39
|
}, [send]);
|
|
40
40
|
const reset = useCallback(() => setEditFlow(baseRef.current), []);
|
|
41
|
-
useSettingsDraftSource({ id: "plugin:flows",
|
|
41
|
+
useSettingsDraftSource({ id: "plugin:flows", isDirty, commit, reset });
|
|
42
42
|
|
|
43
43
|
return (
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// No self-header: the host owns identity + status chrome (design D1).
|
|
45
|
+
<div>
|
|
46
46
|
<p className="text-xs text-[var(--text-tertiary)] mb-3">
|
|
47
47
|
Multi-agent workflow orchestration. Applies globally; sessions inherit this default.
|
|
48
48
|
</p>
|
|
@@ -63,6 +63,6 @@ export function FlowsSettings(): React.ReactElement {
|
|
|
63
63
|
</span>
|
|
64
64
|
</span>
|
|
65
65
|
</label>
|
|
66
|
-
</
|
|
66
|
+
</div>
|
|
67
67
|
);
|
|
68
68
|
}
|
|
@@ -15,12 +15,13 @@ import type {
|
|
|
15
15
|
} from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
16
16
|
import { mdiPencil, mdiPlay } from "@mdi/js";
|
|
17
17
|
import { Icon } from "@mdi/react";
|
|
18
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
18
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
19
19
|
import { FlowActivityBadge } from "./FlowActivityBadge.js";
|
|
20
20
|
import { FlowAuthorPromptDialog } from "./FlowAuthorPromptDialog.js";
|
|
21
21
|
import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
|
|
22
22
|
import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
|
|
23
23
|
import type { FlowsPluginConfig } from "./FlowsSettings.js";
|
|
24
|
+
import { makeSafeSend } from "./send-safe.js";
|
|
24
25
|
|
|
25
26
|
export function SessionFlowActions({
|
|
26
27
|
flows,
|
|
@@ -231,6 +232,10 @@ export function SessionFlowActionsClaim({ session }: { session: DashboardSession
|
|
|
231
232
|
const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
|
|
232
233
|
const { flowState } = useFlowsSessionState(session.id);
|
|
233
234
|
const send = usePluginSend();
|
|
235
|
+
// The edit-mode reconcile effect and the author-prompt handler cannot own the
|
|
236
|
+
// send promise — discard it explicitly.
|
|
237
|
+
// See change: cleanup-client-plugin-promises.
|
|
238
|
+
const dispatch = useMemo(() => makeSafeSend(send), [send]);
|
|
234
239
|
const config = usePluginConfig<FlowsPluginConfig>();
|
|
235
240
|
const editMode = config.editFlow ?? false;
|
|
236
241
|
|
|
@@ -245,8 +250,8 @@ export function SessionFlowActionsClaim({ session }: { session: DashboardSession
|
|
|
245
250
|
if (flows.length === 0) return; // wait until flows-plugin is available
|
|
246
251
|
if (reconciledRef.current === editMode) return;
|
|
247
252
|
reconciledRef.current = editMode;
|
|
248
|
-
|
|
249
|
-
}, [flows.length, editMode, session.id,
|
|
253
|
+
dispatch({ type: "flow_management", sessionId: session.id, action: "set-edit-mode", enabled: editMode });
|
|
254
|
+
}, [flows.length, editMode, session.id, dispatch]);
|
|
250
255
|
|
|
251
256
|
// Render when there's a flow active OR action buttons are available.
|
|
252
257
|
if (flows.length === 0 && !editMode && !flowState) return null;
|
|
@@ -267,7 +272,7 @@ export function SessionFlowActionsClaim({ session }: { session: DashboardSession
|
|
|
267
272
|
? `/skill:manage-flows ${flowName}\n\n${intent}`
|
|
268
273
|
: `/skill:manage-flows ${flowName}`
|
|
269
274
|
: `/skill:manage-flows ${intent}`;
|
|
270
|
-
|
|
275
|
+
dispatch({ type: "send_prompt", sessionId: session.id, text });
|
|
271
276
|
}}
|
|
272
277
|
onFlowAction={(action, opts) =>
|
|
273
278
|
send({
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accumulated-USD cost formatting — a leaf module with no dependencies.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `FlowAgentCard.tsx` to break the import cycle
|
|
5
|
+
* `FlowAgentCard -> FlowAgentDetail -> FlowAgentCard`: the card renders the
|
|
6
|
+
* detail view, and the detail view only needed the card for this formatter.
|
|
7
|
+
* A currency formatter living in a card component was incidental placement.
|
|
8
|
+
*
|
|
9
|
+
* See change: cleanup-import-cycles (D2).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Format an accumulated USD cost, matching the pi-flows TUI precision
|
|
14
|
+
* (`agent-card.ts`): two decimals at or above $1, four decimals sub-dollar.
|
|
15
|
+
*
|
|
16
|
+
* The sub-dollar branch is load-bearing — flow agent costs are routinely well
|
|
17
|
+
* below $1, where 2 decimals would collapse distinct values to `$0.00`.
|
|
18
|
+
*/
|
|
19
|
+
export function formatCost(n: number): string {
|
|
20
|
+
return `$${n >= 1 ? n.toFixed(2) : n.toFixed(4)}`;
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discard-with-a-stated-handler wrapper around the plugin send primitive.
|
|
3
|
+
*
|
|
4
|
+
* A plugin message dispatched from an event handler or effect has no caller to
|
|
5
|
+
* own its promise. Wrapping it here keeps the discard explicit and routes the
|
|
6
|
+
* rejection to the package's logging path, so a dropped message is observable
|
|
7
|
+
* instead of leaving the UI showing a change the server never applied.
|
|
8
|
+
*
|
|
9
|
+
* See change: cleanup-client-plugin-promises (design D1).
|
|
10
|
+
*/
|
|
11
|
+
export type PluginSend = (message: unknown) => void | Promise<void>;
|
|
12
|
+
|
|
13
|
+
export function makeSafeSend(send: PluginSend): (message: unknown) => void {
|
|
14
|
+
return (message: unknown): void => {
|
|
15
|
+
void Promise.resolve(send(message)).catch((err: unknown) => {
|
|
16
|
+
console.error("[flows-plugin] plugin send failed:", err);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
package/src/AGENTS.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# DOX — packages/flows-plugin/src
|
|
2
|
-
|
|
3
|
-
Files in this directory. One row per source file.
|
|
4
|
-
|
|
5
|
-
| File | Purpose |
|
|
6
|
-
|------|---------|
|
|
7
|
-
| `flow-reducer.ts` | Flow event fold. Reads `nodeKind` at `flow_agent_started` (decided once; agent-card fallback), `typedOutputs`/`branch`/`outcome` at complete, code target from `data.target`, `cost` from `result.cost` (verbatim, undefined when absent; see change surface-flow-agent-cost). Pre-lists code/code-decision steps as pending cards. `flow_complete` non-success downgrades in-flight cards to error/hard. See change: rework-flows-plugin-for-new-pi-flows. |
|
|
8
|
-
| `reducer.ts` | Re-export barrel for `isFlowEvent`, `reduceFlowEvent`. Architect reducer exports REMOVED (flow-architect deleted upstream). See change: rework-flows-plugin-for-new-pi-flows. L1/L2 reducer coverage: `__tests__/flow-reducer-seed-on-start.test.ts` (missing-start -> null; start-then-progression advances status + agents to terminal) and `__tests__/flow-reducer-bridge-contract.test.ts` (CONTRACT-PINNED: event types read from the bridge `FLOW_EVENT_MAP` values, never hand-typed; core lifecycle reduces to terminal, reducer never throws on any mapped `flow_*`, passthrough leaves state unchanged). See change: add-flow-plugin-e2e-tests. |
|
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createUiPrimitiveRegistry,
|
|
3
|
-
registerUiPrimitive,
|
|
4
|
-
UiPrimitiveProvider,
|
|
5
|
-
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
6
|
-
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
7
|
-
import { cleanup, render } from "@testing-library/react";
|
|
8
|
-
import { createElement } from "react";
|
|
9
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
10
|
-
import { computeLayout, FlowGraph, type FlowGraphStep, mapStepType } from "../client/FlowGraph.js";
|
|
11
|
-
|
|
12
|
-
const registry = createUiPrimitiveRegistry();
|
|
13
|
-
registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.zoomControls, ((() => null) as never));
|
|
14
|
-
|
|
15
|
-
afterEach(() => cleanup());
|
|
16
|
-
|
|
17
|
-
describe("FlowGraph render: on_complete label suppression", () => {
|
|
18
|
-
it("renders branch labels but never the on_complete label", () => {
|
|
19
|
-
// See change: fix-flow-ui-graph-zoom-summary — on_complete is the happy-path
|
|
20
|
-
// default and renders as a plain arrow; branch labels stay visible.
|
|
21
|
-
const steps: FlowGraphStep[] = [
|
|
22
|
-
{ id: "load", label: "load", status: "complete", blockedBy: [], type: "code", onComplete: "gate" },
|
|
23
|
-
{ id: "gate", label: "gate", status: "complete", blockedBy: [], type: "code-decision", branches: { go: "done" } },
|
|
24
|
-
{ id: "done", label: "done", status: "pending", blockedBy: [] },
|
|
25
|
-
];
|
|
26
|
-
const { container } = render(
|
|
27
|
-
createElement(UiPrimitiveProvider, {
|
|
28
|
-
value: registry,
|
|
29
|
-
children: createElement(FlowGraph, { steps }),
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
const text = container.textContent ?? "";
|
|
33
|
-
expect(text).toContain("go"); // branch label rendered
|
|
34
|
-
expect(text).not.toContain("on_complete"); // route happy-path label suppressed
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe("mapStepType (canonical node set)", () => {
|
|
39
|
-
it("maps the new code node kinds", () => {
|
|
40
|
-
expect(mapStepType("code")).toBe("code");
|
|
41
|
-
expect(mapStepType("code-decision")).toBe("code-decision");
|
|
42
|
-
});
|
|
43
|
-
it("maps fork + agent-decision to fork shape", () => {
|
|
44
|
-
expect(mapStepType("fork")).toBe("fork");
|
|
45
|
-
expect(mapStepType("agent-decision")).toBe("fork");
|
|
46
|
-
});
|
|
47
|
-
it("agent and removed legacy types (incl. flow-ref) map to default (undefined)", () => {
|
|
48
|
-
expect(mapStepType("agent")).toBeUndefined();
|
|
49
|
-
expect(mapStepType("conditional")).toBeUndefined();
|
|
50
|
-
expect(mapStepType("agent-loop-decision")).toBeUndefined();
|
|
51
|
-
expect(mapStepType("flow-ref")).toBeUndefined();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("computeLayout", () => {
|
|
56
|
-
it("lays out a linear flow A→B→C left-to-right", () => {
|
|
57
|
-
const steps: FlowGraphStep[] = [
|
|
58
|
-
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
59
|
-
{ id: "b", label: "step-b", status: "running", blockedBy: ["a"] },
|
|
60
|
-
{ id: "c", label: "step-c", status: "pending", blockedBy: ["b"] },
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
const result = computeLayout(steps);
|
|
64
|
-
|
|
65
|
-
expect(result.nodes).toHaveLength(3);
|
|
66
|
-
expect(result.edges).toHaveLength(2);
|
|
67
|
-
|
|
68
|
-
// Nodes should be left-to-right: a.x < b.x < c.x
|
|
69
|
-
const nodeA = result.nodes.find(n => n.id === "a")!;
|
|
70
|
-
const nodeB = result.nodes.find(n => n.id === "b")!;
|
|
71
|
-
const nodeC = result.nodes.find(n => n.id === "c")!;
|
|
72
|
-
expect(nodeA.x).toBeLessThan(nodeB.x);
|
|
73
|
-
expect(nodeB.x).toBeLessThan(nodeC.x);
|
|
74
|
-
|
|
75
|
-
// All nodes at same y (linear flow, same rank)
|
|
76
|
-
expect(nodeA.y).toBe(nodeB.y);
|
|
77
|
-
expect(nodeB.y).toBe(nodeC.y);
|
|
78
|
-
|
|
79
|
-
// Edges should have points
|
|
80
|
-
for (const edge of result.edges) {
|
|
81
|
-
expect(edge.points.length).toBeGreaterThanOrEqual(2);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Width and height should be positive
|
|
85
|
-
expect(result.width).toBeGreaterThan(0);
|
|
86
|
-
expect(result.height).toBeGreaterThan(0);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("lays out a branching flow A→B, A→C, B→D, C→D with vertical stacking", () => {
|
|
90
|
-
const steps: FlowGraphStep[] = [
|
|
91
|
-
{ id: "a", label: "start", status: "complete", blockedBy: [] },
|
|
92
|
-
{ id: "b", label: "branch-1", status: "running", blockedBy: ["a"] },
|
|
93
|
-
{ id: "c", label: "branch-2", status: "running", blockedBy: ["a"] },
|
|
94
|
-
{ id: "d", label: "merge", status: "pending", blockedBy: ["b", "c"] },
|
|
95
|
-
];
|
|
96
|
-
|
|
97
|
-
const result = computeLayout(steps);
|
|
98
|
-
|
|
99
|
-
expect(result.nodes).toHaveLength(4);
|
|
100
|
-
expect(result.edges).toHaveLength(4); // a→b, a→c, b→d, c→d
|
|
101
|
-
|
|
102
|
-
const nodeA = result.nodes.find(n => n.id === "a")!;
|
|
103
|
-
const nodeB = result.nodes.find(n => n.id === "b")!;
|
|
104
|
-
const nodeC = result.nodes.find(n => n.id === "c")!;
|
|
105
|
-
const nodeD = result.nodes.find(n => n.id === "d")!;
|
|
106
|
-
|
|
107
|
-
// A and D should be at different x positions (different ranks)
|
|
108
|
-
expect(nodeA.x).toBeLessThan(nodeB.x);
|
|
109
|
-
expect(nodeB.x).toBeLessThan(nodeD.x);
|
|
110
|
-
|
|
111
|
-
// B and C should be at the same x (same rank) but different y (stacked)
|
|
112
|
-
expect(nodeB.x).toBe(nodeC.x);
|
|
113
|
-
expect(nodeB.y).not.toBe(nodeC.y);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("places no-blockedBy parallel roots in the same rank (no false serialization)", () => {
|
|
117
|
-
// Two roots, no blockedBy, no separator between them. The engine runs both
|
|
118
|
-
// in wave 1 (parallel); the layout must NOT synthesize an impl→docs edge that
|
|
119
|
-
// pushes them into consecutive ranks (would read as sequential).
|
|
120
|
-
const steps: FlowGraphStep[] = [
|
|
121
|
-
{ id: "impl", label: "impl", status: "running", blockedBy: [] },
|
|
122
|
-
{ id: "docs", label: "docs", status: "running", blockedBy: [] },
|
|
123
|
-
];
|
|
124
|
-
const result = computeLayout(steps);
|
|
125
|
-
expect(result.edges).toHaveLength(0);
|
|
126
|
-
const impl = result.nodes.find(n => n.id === "impl")!;
|
|
127
|
-
const docs = result.nodes.find(n => n.id === "docs")!;
|
|
128
|
-
expect(impl.x).toBe(docs.x); // same rank
|
|
129
|
-
expect(impl.y).not.toBe(docs.y); // stacked vertically = parallel
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("handles single-step flow", () => {
|
|
133
|
-
const steps: FlowGraphStep[] = [
|
|
134
|
-
{ id: "solo", label: "solo-step", status: "running", blockedBy: [] },
|
|
135
|
-
];
|
|
136
|
-
|
|
137
|
-
const result = computeLayout(steps);
|
|
138
|
-
expect(result.nodes).toHaveLength(1);
|
|
139
|
-
expect(result.edges).toHaveLength(0);
|
|
140
|
-
expect(result.width).toBeGreaterThan(0);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("marks a returning on_error route as a red loop-styled edge (isError + isReturning)", () => {
|
|
144
|
-
const steps: FlowGraphStep[] = [
|
|
145
|
-
{ id: "validate", label: "validate", status: "complete", blockedBy: [], type: "code-decision", onError: "fixup" },
|
|
146
|
-
{ id: "transform", label: "transform", status: "running", blockedBy: ["validate"] },
|
|
147
|
-
{ id: "fixup", label: "fixup", status: "pending", blockedBy: [], onComplete: "validate" },
|
|
148
|
-
];
|
|
149
|
-
const result = computeLayout(steps);
|
|
150
|
-
const e = result.edges.find(ed => ed.source === "validate" && ed.target === "fixup");
|
|
151
|
-
expect(e).toBeTruthy();
|
|
152
|
-
expect(e!.isError).toBe(true);
|
|
153
|
-
expect(e!.isReturning).toBe(true);
|
|
154
|
-
// dagre-routed: multi-segment polyline (does not cross the band naively)
|
|
155
|
-
expect(e!.points.length).toBeGreaterThanOrEqual(2);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("collapses terminal on_error handlers into a single sink node", () => {
|
|
159
|
-
const steps: FlowGraphStep[] = [
|
|
160
|
-
{ id: "a", label: "a", status: "complete", blockedBy: [], onError: "notify" },
|
|
161
|
-
{ id: "b", label: "b", status: "running", blockedBy: ["a"], onError: "notify" },
|
|
162
|
-
{ id: "notify", label: "notify", status: "pending", blockedBy: [] },
|
|
163
|
-
];
|
|
164
|
-
const result = computeLayout(steps);
|
|
165
|
-
expect(result.errorSink).toBeTruthy();
|
|
166
|
-
expect(result.errorSink!.handlers).toEqual(["notify"]);
|
|
167
|
-
// the terminal handler is NOT laid out as a normal node
|
|
168
|
-
expect(result.nodes.some(n => n.id === "notify")).toBe(false);
|
|
169
|
-
// both terminal routes are present as error edges (routed to the sink)
|
|
170
|
-
expect(result.edges.filter(e => e.isError).map(e => e.source).sort()).toEqual(["a", "b"]);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("removes error routes from layout when showErrorRoutes is false (zero footprint)", () => {
|
|
174
|
-
const withErr: FlowGraphStep[] = [
|
|
175
|
-
{ id: "a", label: "a", status: "complete", blockedBy: [], onError: "notify" },
|
|
176
|
-
{ id: "b", label: "b", status: "running", blockedBy: ["a"] },
|
|
177
|
-
{ id: "notify", label: "notify", status: "pending", blockedBy: [] },
|
|
178
|
-
];
|
|
179
|
-
const baseline: FlowGraphStep[] = [
|
|
180
|
-
{ id: "a", label: "a", status: "complete", blockedBy: [] },
|
|
181
|
-
{ id: "b", label: "b", status: "running", blockedBy: ["a"] },
|
|
182
|
-
];
|
|
183
|
-
const off = computeLayout(withErr, { showErrorRoutes: false });
|
|
184
|
-
const base = computeLayout(baseline);
|
|
185
|
-
expect(off.errorSink).toBeUndefined();
|
|
186
|
-
expect(off.edges.some(e => e.isError)).toBe(false);
|
|
187
|
-
expect(off.nodes.some(n => n.id === "notify")).toBe(false);
|
|
188
|
-
expect(off.height).toBe(base.height);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("handles empty steps array", () => {
|
|
192
|
-
const result = computeLayout([]);
|
|
193
|
-
// Should return empty layout without throwing
|
|
194
|
-
expect(result.nodes).toHaveLength(0);
|
|
195
|
-
expect(result.edges).toHaveLength(0);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("uses consistent node dimensions", () => {
|
|
199
|
-
const steps: FlowGraphStep[] = [
|
|
200
|
-
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
201
|
-
{ id: "b", label: "step-b", status: "pending", blockedBy: ["a"] },
|
|
202
|
-
];
|
|
203
|
-
|
|
204
|
-
const result = computeLayout(steps);
|
|
205
|
-
// All nodes should have same width and height
|
|
206
|
-
expect(result.nodes[0].width).toBe(result.nodes[1].width);
|
|
207
|
-
expect(result.nodes[0].height).toBe(result.nodes[1].height);
|
|
208
|
-
expect(result.nodes[0].width).toBeGreaterThan(0);
|
|
209
|
-
expect(result.nodes[0].height).toBeGreaterThan(0);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("preserves status on positioned nodes", () => {
|
|
213
|
-
const steps: FlowGraphStep[] = [
|
|
214
|
-
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
215
|
-
{ id: "b", label: "step-b", status: "error", blockedBy: ["a"] },
|
|
216
|
-
];
|
|
217
|
-
|
|
218
|
-
const result = computeLayout(steps);
|
|
219
|
-
expect(result.nodes.find(n => n.id === "a")!.status).toBe("complete");
|
|
220
|
-
expect(result.nodes.find(n => n.id === "b")!.status).toBe("error");
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("edges carry source/target status for styling", () => {
|
|
224
|
-
const steps: FlowGraphStep[] = [
|
|
225
|
-
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
226
|
-
{ id: "b", label: "step-b", status: "running", blockedBy: ["a"] },
|
|
227
|
-
];
|
|
228
|
-
|
|
229
|
-
const result = computeLayout(steps);
|
|
230
|
-
expect(result.edges).toHaveLength(1);
|
|
231
|
-
expect(result.edges[0].sourceStatus).toBe("complete");
|
|
232
|
-
expect(result.edges[0].targetStatus).toBe("running");
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("layout dimensions are consistent regardless of step count", () => {
|
|
236
|
-
// Single node
|
|
237
|
-
const single = computeLayout([
|
|
238
|
-
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
239
|
-
]);
|
|
240
|
-
// Many nodes
|
|
241
|
-
const many = computeLayout([
|
|
242
|
-
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
243
|
-
{ id: "b", label: "step-b", status: "pending", blockedBy: ["a"] },
|
|
244
|
-
{ id: "c", label: "step-c", status: "pending", blockedBy: ["b"] },
|
|
245
|
-
{ id: "d", label: "step-d", status: "pending", blockedBy: ["c"] },
|
|
246
|
-
]);
|
|
247
|
-
// Nodes should have identical dimensions in both layouts (fixed-scale)
|
|
248
|
-
expect(single.nodes[0].width).toBe(many.nodes[0].width);
|
|
249
|
-
expect(single.nodes[0].height).toBe(many.nodes[0].height);
|
|
250
|
-
// Multi-node layout should be wider
|
|
251
|
-
expect(many.width).toBeGreaterThan(single.width);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("ignores blockedBy references to non-existent steps", () => {
|
|
255
|
-
const steps: FlowGraphStep[] = [
|
|
256
|
-
{ id: "a", label: "step-a", status: "pending", blockedBy: ["nonexistent"] },
|
|
257
|
-
];
|
|
258
|
-
|
|
259
|
-
const result = computeLayout(steps);
|
|
260
|
-
expect(result.nodes).toHaveLength(1);
|
|
261
|
-
expect(result.edges).toHaveLength(0); // no edge for missing dep
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it("preserves type field on positioned nodes", () => {
|
|
265
|
-
const steps: FlowGraphStep[] = [
|
|
266
|
-
{ id: "a", label: "agent-step", status: "pending", blockedBy: [], type: "agent" },
|
|
267
|
-
{ id: "b", label: "decision-step", status: "pending", blockedBy: ["a"], type: "code-decision" },
|
|
268
|
-
];
|
|
269
|
-
|
|
270
|
-
const result = computeLayout(steps);
|
|
271
|
-
expect(result.nodes.find(n => n.id === "a")!.type).toBe("agent");
|
|
272
|
-
expect(result.nodes.find(n => n.id === "b")!.type).toBe("code-decision");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("renders forward decision-branch edges with labels while running", () => {
|
|
276
|
-
const steps: FlowGraphStep[] = [
|
|
277
|
-
{ id: "choose", label: "choose", status: "running", blockedBy: [], type: "fork", branches: { PathA: "a", PathB: "b" } },
|
|
278
|
-
{ id: "a", label: "a", status: "pending", blockedBy: [] },
|
|
279
|
-
{ id: "b", label: "b", status: "pending", blockedBy: [] },
|
|
280
|
-
];
|
|
281
|
-
const result = computeLayout(steps);
|
|
282
|
-
const labels = result.edges.map(e => e.label).sort();
|
|
283
|
-
expect(result.edges).toHaveLength(2);
|
|
284
|
-
expect(labels).toEqual(["PathA", "PathB"]);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it("marks a backward branch as a loop edge, routed by dagre (not a hand-arc)", () => {
|
|
288
|
-
const steps: FlowGraphStep[] = [
|
|
289
|
-
{ id: "work", label: "work", status: "complete", blockedBy: [] },
|
|
290
|
-
{ id: "gate", label: "gate", status: "running", blockedBy: ["work"], type: "code-decision", branches: { again: "work", go: "done" } },
|
|
291
|
-
{ id: "done", label: "done", status: "pending", blockedBy: [] },
|
|
292
|
-
];
|
|
293
|
-
const result = computeLayout(steps);
|
|
294
|
-
// Backward branch gate->work is a loop-styled edge (isLoop), routed by dagre.
|
|
295
|
-
const loop = result.edges.find(e => e.source === "gate" && e.target === "work");
|
|
296
|
-
expect(loop).toBeTruthy();
|
|
297
|
-
expect(loop!.isLoop).toBe(true);
|
|
298
|
-
expect(loop!.label).toBe("again");
|
|
299
|
-
expect(loop!.points.length).toBeGreaterThanOrEqual(2);
|
|
300
|
-
// forward branch gate->done carries its label and is not a loop.
|
|
301
|
-
const fwd = result.edges.find(e => e.source === "gate" && e.target === "done");
|
|
302
|
-
expect(fwd?.label).toBe("go");
|
|
303
|
-
expect(fwd?.isLoop).toBeFalsy();
|
|
304
|
-
});
|
|
305
|
-
});
|