@blackbelt-technology/pi-dashboard-flows-plugin 0.5.2 → 0.5.4
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 +39 -4
- package/src/__tests__/FlowsSessionStateContext.test.tsx +260 -0
- package/src/__tests__/FlowsUiStateContext.test.tsx +140 -0
- package/src/__tests__/flowsAvailability.test.ts +92 -0
- package/src/__tests__/manifest-discoverability.test.ts +97 -0
- package/src/__tests__/render-actions.test.ts +63 -0
- package/src/bridge/flow-question-adapter.ts +93 -0
- package/src/bridge/index.ts +30 -0
- package/src/client/FlowActivityBadge.tsx +36 -9
- package/src/client/FlowAgentCard.tsx +180 -41
- package/src/client/FlowAgentDetail.tsx +95 -154
- package/src/client/FlowAgentPopoutClaim.tsx +66 -0
- package/src/client/FlowAgentPopoutPage.tsx +177 -0
- package/src/client/FlowArchitect.tsx +297 -220
- package/src/client/FlowArchitectPopoutClaim.tsx +52 -0
- package/src/client/FlowArchitectPopoutPage.tsx +133 -0
- package/src/client/FlowDashboard.tsx +194 -31
- package/src/client/FlowGraph.tsx +6 -2
- package/src/client/FlowLaunchDialog.tsx +8 -2
- package/src/client/FlowQuestionCard.tsx +213 -0
- package/src/client/FlowQuestionTranscriptPill.tsx +58 -0
- package/src/client/FlowSummary.tsx +43 -21
- package/src/client/FlowYamlPopoverButton.tsx +109 -0
- package/src/client/FlowYamlPreview.tsx +65 -0
- package/src/client/FlowsCommandRoutes.tsx +237 -0
- package/src/client/FlowsSessionStateContext.tsx +161 -0
- package/src/client/FlowsUiStateContext.tsx +169 -0
- package/src/client/SessionFlowActions.tsx +96 -5
- package/src/client/flowsAvailability.ts +103 -0
- package/src/client/index.tsx +94 -7
- package/src/client/popout-url.ts +59 -0
- package/src/client/shouldRender.ts +26 -0
- package/src/server/index.ts +87 -0
- package/src/server/render-actions.ts +88 -0
- package/src/server/state-store.ts +85 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbelt-technology/pi-dashboard-flows-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Flow rendering plugin for pi-dashboard — pi-flows event reaction (FlowDashboard, FlowAgentCard, FlowArchitect, etc.)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -29,20 +29,55 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"src/"
|
|
31
31
|
],
|
|
32
|
-
"//pi-dashboard-plugin-deferred-claims": "session-card-badge (FlowActivityBadge) and session-card-action-bar (SessionFlowActions) are deferred until migrate-flows-jsx-to-slots adapts those components to accept {session} and pull app state from context. Until then they remain wired via direct JSX in SessionCard.tsx.",
|
|
33
32
|
"pi-dashboard-plugin": {
|
|
34
33
|
"id": "flows",
|
|
35
34
|
"displayName": "Flows",
|
|
36
35
|
"priority": 100,
|
|
37
36
|
"client": "./src/client/index.tsx",
|
|
38
|
-
"
|
|
37
|
+
"server": "./src/server/index.ts",
|
|
38
|
+
"bridge": "./src/bridge/index.ts",
|
|
39
|
+
"claims": [
|
|
40
|
+
{
|
|
41
|
+
"slot": "session-card-flows",
|
|
42
|
+
"component": "SessionFlowActionsClaim",
|
|
43
|
+
"shouldRender": "shouldRenderFlowsSubcard"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"slot": "content-header-sticky",
|
|
47
|
+
"component": "FlowDashboardClaim"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"slot": "content-header-sticky",
|
|
51
|
+
"component": "FlowArchitectClaim"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"slot": "content-view",
|
|
55
|
+
"component": "FlowYamlPreviewClaim",
|
|
56
|
+
"predicate": "isFlowYamlPreviewActive"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"slot": "shell-overlay-route",
|
|
60
|
+
"component": "FlowAgentPopoutClaim",
|
|
61
|
+
"path": "/session/:sid/flow/:flowId/agent/:agentId",
|
|
62
|
+
"sessionParam": "sid"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"slot": "shell-overlay-route",
|
|
66
|
+
"component": "FlowArchitectPopoutClaim",
|
|
67
|
+
"path": "/session/:sid/architect",
|
|
68
|
+
"sessionParam": "sid"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
39
71
|
},
|
|
40
72
|
"peerDependencies": {
|
|
41
73
|
"react": ">=18.0.0",
|
|
42
74
|
"react-dom": ">=18.0.0"
|
|
43
75
|
},
|
|
76
|
+
"//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.",
|
|
44
77
|
"dependencies": {
|
|
45
|
-
"@blackbelt-technology/
|
|
78
|
+
"@blackbelt-technology/dashboard-plugin-runtime": "^0.5.4",
|
|
79
|
+
"@blackbelt-technology/pi-dashboard-client-utils": "^0.5.4",
|
|
80
|
+
"@blackbelt-technology/pi-dashboard-shared": "^0.5.4"
|
|
46
81
|
},
|
|
47
82
|
"devDependencies": {
|
|
48
83
|
"@types/react": "^19.0.0",
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `reduceFlowsSessionState` and `useFlowsSessionState`.
|
|
3
|
+
*
|
|
4
|
+
* The pure reducer is tested with synthesized event sequences to verify
|
|
5
|
+
* it matches the shell's pre-deletion behavior (event-reducer.ts:1292-1313)
|
|
6
|
+
* exactly. The hook is smoke-tested via React rendering with a live
|
|
7
|
+
* `useSessionEvents` subscription and direct calls to
|
|
8
|
+
* `publishSessionEvent` to drive the event stream.
|
|
9
|
+
*
|
|
10
|
+
* See change: pluginize-flows-via-registry.
|
|
11
|
+
*/
|
|
12
|
+
import React from "react";
|
|
13
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
14
|
+
import { render, act, cleanup } from "@testing-library/react";
|
|
15
|
+
import {
|
|
16
|
+
PluginContextProvider,
|
|
17
|
+
publishSessionEvent,
|
|
18
|
+
clearSessionEvents,
|
|
19
|
+
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
20
|
+
|
|
21
|
+
// We don't import __resetSessionEventsStoreForTests across the package
|
|
22
|
+
// boundary (it's marked @internal). Each test scopes events to a unique
|
|
23
|
+
// session id, so isolation comes from the session-id namespace itself.
|
|
24
|
+
let __testCounter = 0;
|
|
25
|
+
function nextSessionId(): string { return `S-${++__testCounter}`; }
|
|
26
|
+
import type { DashboardEvent } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
27
|
+
import {
|
|
28
|
+
reduceFlowsSessionState,
|
|
29
|
+
useFlowsSessionState,
|
|
30
|
+
type FlowsSessionState,
|
|
31
|
+
} from "../client/FlowsSessionStateContext.js";
|
|
32
|
+
|
|
33
|
+
// ── Event factories matching the real protocol shapes ──────────────
|
|
34
|
+
|
|
35
|
+
function flowStartedEvent(seq: number, flowName = "build"): DashboardEvent {
|
|
36
|
+
return {
|
|
37
|
+
seq,
|
|
38
|
+
timestamp: new Date(seq * 1000).toISOString(),
|
|
39
|
+
eventType: "flow_started",
|
|
40
|
+
data: {
|
|
41
|
+
flowName,
|
|
42
|
+
task: "test task",
|
|
43
|
+
steps: [
|
|
44
|
+
{ id: "s1", stepType: "agent", agent: "alpha", blockedBy: [] },
|
|
45
|
+
{ id: "s2", stepType: "agent", agent: "beta", blockedBy: ["s1"] },
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
} as any;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function flowSummaryDismissedEvent(seq: number): DashboardEvent {
|
|
53
|
+
return {
|
|
54
|
+
seq,
|
|
55
|
+
timestamp: new Date(seq * 1000).toISOString(),
|
|
56
|
+
eventType: "flow_summary_dismissed",
|
|
57
|
+
data: {},
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
} as any;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function 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
|
+
function unrelatedEvent(seq: number): DashboardEvent {
|
|
77
|
+
return {
|
|
78
|
+
seq,
|
|
79
|
+
timestamp: new Date(seq * 1000).toISOString(),
|
|
80
|
+
eventType: "tool_start",
|
|
81
|
+
data: { toolName: "Read" },
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
} as any;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ── Pure reducer tests ─────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
describe("reduceFlowsSessionState (pure)", () => {
|
|
89
|
+
it("returns the same EMPTY_STATE reference for empty input", () => {
|
|
90
|
+
const a = reduceFlowsSessionState([]);
|
|
91
|
+
const b = reduceFlowsSessionState([]);
|
|
92
|
+
expect(a).toBe(b);
|
|
93
|
+
expect(a.flowState).toBeNull();
|
|
94
|
+
expect(a.architectState).toBeNull();
|
|
95
|
+
expect(a.flowStates.size).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("returns EMPTY_STATE when no flow / architect events are present", () => {
|
|
99
|
+
const result = reduceFlowsSessionState([
|
|
100
|
+
unrelatedEvent(1),
|
|
101
|
+
unrelatedEvent(2),
|
|
102
|
+
]);
|
|
103
|
+
expect(result.flowState).toBeNull();
|
|
104
|
+
expect(result.architectState).toBeNull();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("derives flowState from a flow_started event", () => {
|
|
108
|
+
const result = reduceFlowsSessionState([flowStartedEvent(1, "build")]);
|
|
109
|
+
expect(result.flowState).not.toBeNull();
|
|
110
|
+
expect(result.flowState!.flowName).toBe("build");
|
|
111
|
+
expect(result.flowStates.size).toBe(1);
|
|
112
|
+
expect(result.flowStates.get("build")).toBe(result.flowState);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("clears flowStates on flow_summary_dismissed", () => {
|
|
116
|
+
const result = reduceFlowsSessionState([
|
|
117
|
+
flowStartedEvent(1, "build"),
|
|
118
|
+
flowSummaryDismissedEvent(2),
|
|
119
|
+
]);
|
|
120
|
+
// flow_summary_dismissed clears flowStates per
|
|
121
|
+
// event-reducer.ts:1298-1300 behavior.
|
|
122
|
+
expect(result.flowStates.size).toBe(0);
|
|
123
|
+
});
|
|
124
|
+
|
|
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
|
+
it("ignores unrelated events between flow events", () => {
|
|
146
|
+
const result = reduceFlowsSessionState([
|
|
147
|
+
flowStartedEvent(1, "build"),
|
|
148
|
+
unrelatedEvent(2),
|
|
149
|
+
unrelatedEvent(3),
|
|
150
|
+
]);
|
|
151
|
+
expect(result.flowState!.flowName).toBe("build");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// ── Hook tests (live useSessionEvents subscription) ────────────────
|
|
156
|
+
|
|
157
|
+
function Probe({ sessionId, onSnapshot }: {
|
|
158
|
+
sessionId: string;
|
|
159
|
+
onSnapshot: (state: FlowsSessionState) => void;
|
|
160
|
+
}) {
|
|
161
|
+
const state = useFlowsSessionState(sessionId);
|
|
162
|
+
onSnapshot(state);
|
|
163
|
+
return (
|
|
164
|
+
<div data-testid="probe">
|
|
165
|
+
flow={state.flowState?.flowName ?? "(none)"} arch={state.architectState?.flowName ?? "(none)"}
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
describe("useFlowsSessionState (hook)", () => {
|
|
171
|
+
afterEach(() => cleanup());
|
|
172
|
+
|
|
173
|
+
it("returns EMPTY_STATE for a session with no events", () => {
|
|
174
|
+
const snaps: FlowsSessionState[] = [];
|
|
175
|
+
const sid = nextSessionId();
|
|
176
|
+
render(
|
|
177
|
+
<PluginContextProvider>
|
|
178
|
+
<Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
|
|
179
|
+
</PluginContextProvider>,
|
|
180
|
+
);
|
|
181
|
+
expect(snaps[0].flowState).toBeNull();
|
|
182
|
+
expect(snaps[0].architectState).toBeNull();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("re-renders with derived state when a flow event arrives", () => {
|
|
186
|
+
const snaps: FlowsSessionState[] = [];
|
|
187
|
+
const sid = nextSessionId();
|
|
188
|
+
const { getByTestId } = render(
|
|
189
|
+
<PluginContextProvider>
|
|
190
|
+
<Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
|
|
191
|
+
</PluginContextProvider>,
|
|
192
|
+
);
|
|
193
|
+
expect(getByTestId("probe").textContent).toContain("flow=(none)");
|
|
194
|
+
|
|
195
|
+
act(() => publishSessionEvent(sid, flowStartedEvent(1, "build")));
|
|
196
|
+
expect(getByTestId("probe").textContent).toContain("flow=build");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("scopes derived state per session", () => {
|
|
200
|
+
const snapsA: FlowsSessionState[] = [];
|
|
201
|
+
const snapsB: FlowsSessionState[] = [];
|
|
202
|
+
const sidA = nextSessionId();
|
|
203
|
+
const sidB = nextSessionId();
|
|
204
|
+
render(
|
|
205
|
+
<PluginContextProvider>
|
|
206
|
+
<Probe sessionId={sidA} onSnapshot={(s) => snapsA.push(s)} />
|
|
207
|
+
<Probe sessionId={sidB} onSnapshot={(s) => snapsB.push(s)} />
|
|
208
|
+
</PluginContextProvider>,
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
act(() => publishSessionEvent(sidA, flowStartedEvent(1, "alpha-flow")));
|
|
212
|
+
act(() => publishSessionEvent(sidB, flowStartedEvent(2, "beta-flow")));
|
|
213
|
+
|
|
214
|
+
const lastA = snapsA[snapsA.length - 1];
|
|
215
|
+
const lastB = snapsB[snapsB.length - 1];
|
|
216
|
+
expect(lastA.flowState!.flowName).toBe("alpha-flow");
|
|
217
|
+
expect(lastB.flowState!.flowName).toBe("beta-flow");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("returns a stable state reference across renders that don't change events", () => {
|
|
221
|
+
const snaps: FlowsSessionState[] = [];
|
|
222
|
+
const sid = nextSessionId();
|
|
223
|
+
const { rerender } = render(
|
|
224
|
+
<PluginContextProvider>
|
|
225
|
+
<Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
|
|
226
|
+
</PluginContextProvider>,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
act(() => publishSessionEvent(sid, flowStartedEvent(1, "build")));
|
|
230
|
+
const refAfterPublish = snaps[snaps.length - 1];
|
|
231
|
+
|
|
232
|
+
// Force re-render without publishing.
|
|
233
|
+
rerender(
|
|
234
|
+
<PluginContextProvider>
|
|
235
|
+
<Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
|
|
236
|
+
</PluginContextProvider>,
|
|
237
|
+
);
|
|
238
|
+
const refAfterRerender = snaps[snaps.length - 1];
|
|
239
|
+
|
|
240
|
+
expect(refAfterRerender).toBe(refAfterPublish);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("clears flowStates when the events store is cleared", () => {
|
|
244
|
+
const snaps: FlowsSessionState[] = [];
|
|
245
|
+
const sid = nextSessionId();
|
|
246
|
+
render(
|
|
247
|
+
<PluginContextProvider>
|
|
248
|
+
<Probe sessionId={sid} onSnapshot={(s) => snaps.push(s)} />
|
|
249
|
+
</PluginContextProvider>,
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
act(() => publishSessionEvent(sid, flowStartedEvent(1, "build")));
|
|
253
|
+
expect(snaps[snaps.length - 1].flowState).not.toBeNull();
|
|
254
|
+
|
|
255
|
+
act(() => clearSessionEvents(sid));
|
|
256
|
+
const last = snaps[snaps.length - 1];
|
|
257
|
+
expect(last.flowState).toBeNull();
|
|
258
|
+
expect(last.flowStates.size).toBe(0);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the plugin-internal UI selection state. Verifies the
|
|
3
|
+
* module-level store, setter semantics, no-op short-circuiting, and
|
|
4
|
+
* the unified `dismissAll` cleanup. See change:
|
|
5
|
+
* pluginize-flows-via-registry.
|
|
6
|
+
*/
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
9
|
+
import { render, act, cleanup } from "@testing-library/react";
|
|
10
|
+
import {
|
|
11
|
+
useFlowsUiState,
|
|
12
|
+
useFlowsUiActions,
|
|
13
|
+
__resetFlowsUiStateForTests,
|
|
14
|
+
type FlowsUiState,
|
|
15
|
+
} from "../client/FlowsUiStateContext.js";
|
|
16
|
+
|
|
17
|
+
function Probe({ onSnapshot }: { onSnapshot: (state: FlowsUiState) => void }) {
|
|
18
|
+
const state = useFlowsUiState();
|
|
19
|
+
onSnapshot(state);
|
|
20
|
+
return (
|
|
21
|
+
<div data-testid="probe">
|
|
22
|
+
src={state.sourceOpenAgent ?? "(null)"} yaml={state.flowYamlPreview?.title ?? "(null)"}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("FlowsUiStateContext", () => {
|
|
28
|
+
beforeEach(() => __resetFlowsUiStateForTests());
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
cleanup();
|
|
31
|
+
__resetFlowsUiStateForTests();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("starts with the initial state (all nulls / false)", () => {
|
|
35
|
+
const snaps: FlowsUiState[] = [];
|
|
36
|
+
render(<Probe onSnapshot={(s) => snaps.push(s)} />);
|
|
37
|
+
expect(snaps[0]).toEqual({
|
|
38
|
+
sourceOpenAgent: null,
|
|
39
|
+
flowYamlPreview: null,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("does not notify when a setter is called with the same value", () => {
|
|
44
|
+
let renderCount = 0;
|
|
45
|
+
function CountingProbe() {
|
|
46
|
+
renderCount++;
|
|
47
|
+
useFlowsUiState();
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function ActionsProbe() {
|
|
51
|
+
actions = useFlowsUiActions();
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
render(
|
|
55
|
+
<>
|
|
56
|
+
<ActionsProbe />
|
|
57
|
+
<CountingProbe />
|
|
58
|
+
</>,
|
|
59
|
+
);
|
|
60
|
+
const initial = renderCount;
|
|
61
|
+
|
|
62
|
+
act(() => actions.setSourceOpenAgent(null)); // already null
|
|
63
|
+
expect(renderCount).toBe(initial); // no extra render
|
|
64
|
+
|
|
65
|
+
act(() => actions.setSourceOpenAgent("alpha")); // change
|
|
66
|
+
expect(renderCount).toBe(initial + 1);
|
|
67
|
+
|
|
68
|
+
act(() => actions.setSourceOpenAgent("alpha")); // same value
|
|
69
|
+
expect(renderCount).toBe(initial + 1); // no extra render
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("dismissAll clears every field in one notify", () => {
|
|
73
|
+
let renderCount = 0;
|
|
74
|
+
function CountingProbe() {
|
|
75
|
+
renderCount++;
|
|
76
|
+
useFlowsUiState();
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
function ActionsProbe() {
|
|
80
|
+
actions = useFlowsUiActions();
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
render(
|
|
84
|
+
<>
|
|
85
|
+
<ActionsProbe />
|
|
86
|
+
<CountingProbe />
|
|
87
|
+
</>,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// Set every field.
|
|
91
|
+
act(() => {
|
|
92
|
+
actions.setSourceOpenAgent("beta");
|
|
93
|
+
actions.setFlowYamlPreview({ content: "x", title: "t" });
|
|
94
|
+
});
|
|
95
|
+
const beforeDismiss = renderCount;
|
|
96
|
+
|
|
97
|
+
// dismissAll: single act → expect a single notify (one render).
|
|
98
|
+
act(() => actions.dismissAll());
|
|
99
|
+
expect(renderCount).toBe(beforeDismiss + 1);
|
|
100
|
+
|
|
101
|
+
// All fields cleared.
|
|
102
|
+
const probeText = (function readProbe() {
|
|
103
|
+
const snaps: FlowsUiState[] = [];
|
|
104
|
+
render(<Probe onSnapshot={(s) => snaps.push(s)} />);
|
|
105
|
+
return snaps[0];
|
|
106
|
+
})();
|
|
107
|
+
expect(probeText).toEqual({
|
|
108
|
+
sourceOpenAgent: null,
|
|
109
|
+
flowYamlPreview: null,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("returns a stable actions reference across renders", () => {
|
|
114
|
+
const seen = new Set<unknown>();
|
|
115
|
+
function ActionsProbe() {
|
|
116
|
+
const a = useFlowsUiActions();
|
|
117
|
+
seen.add(a);
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const { rerender } = render(<ActionsProbe />);
|
|
121
|
+
rerender(<ActionsProbe />);
|
|
122
|
+
rerender(<ActionsProbe />);
|
|
123
|
+
expect(seen.size).toBe(1);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Shared module-level holder so tests can call setters from outside
|
|
128
|
+
// the rendered tree.
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
let actions: any;
|
|
131
|
+
|
|
132
|
+
function ActionsProbeWithUI() {
|
|
133
|
+
actions = useFlowsUiActions();
|
|
134
|
+
const state = useFlowsUiState();
|
|
135
|
+
return (
|
|
136
|
+
<div data-testid="probe">
|
|
137
|
+
src={state.sourceOpenAgent ?? "(null)"} yaml={state.flowYamlPreview?.title ?? "(null)"}
|
|
138
|
+
</div>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the per-session flows availability cache backing
|
|
3
|
+
* `shouldRenderFlowsSubcard`. See change: add-flows-subcard.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
getFlowsAvailabilitySync,
|
|
8
|
+
setFlowsAvailability,
|
|
9
|
+
installFlowsAvailabilitySubscriber,
|
|
10
|
+
__resetFlowsAvailabilityForTests,
|
|
11
|
+
} from "../client/flowsAvailability.js";
|
|
12
|
+
import {
|
|
13
|
+
publishSessionData,
|
|
14
|
+
clearSessionData,
|
|
15
|
+
__resetSessionDataStoreForTests,
|
|
16
|
+
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
17
|
+
|
|
18
|
+
describe("flows-plugin: flowsAvailability cache", () => {
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
__resetFlowsAvailabilityForTests();
|
|
21
|
+
__resetSessionDataStoreForTests();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
__resetFlowsAvailabilityForTests();
|
|
26
|
+
__resetSessionDataStoreForTests();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("returns false for unknown sessions (closed-by-default)", () => {
|
|
30
|
+
expect(getFlowsAvailabilitySync("unknown-id")).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("set then get round-trips", () => {
|
|
34
|
+
setFlowsAvailability("s1", true);
|
|
35
|
+
expect(getFlowsAvailabilitySync("s1")).toBe(true);
|
|
36
|
+
|
|
37
|
+
setFlowsAvailability("s1", false);
|
|
38
|
+
expect(getFlowsAvailabilitySync("s1")).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("installFlowsAvailabilitySubscriber is idempotent — same unsubscribe twice", () => {
|
|
42
|
+
const off1 = installFlowsAvailabilitySubscriber();
|
|
43
|
+
const off2 = installFlowsAvailabilitySubscriber();
|
|
44
|
+
expect(off1).toBe(off2);
|
|
45
|
+
off1();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("subscriber populates cache to `true` when flowsList is non-empty", () => {
|
|
49
|
+
const off = installFlowsAvailabilitySubscriber();
|
|
50
|
+
expect(getFlowsAvailabilitySync("s1")).toBe(false); // closed-by-default
|
|
51
|
+
|
|
52
|
+
publishSessionData("s1", "flowsList", [
|
|
53
|
+
{ name: "deploy", description: "Deploy the app" },
|
|
54
|
+
]);
|
|
55
|
+
expect(getFlowsAvailabilitySync("s1")).toBe(true);
|
|
56
|
+
off();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("subscriber populates cache to `true` when commandsList contains flows:new", () => {
|
|
60
|
+
const off = installFlowsAvailabilitySubscriber();
|
|
61
|
+
publishSessionData("s2", "commandsList", [{ name: "flows:new" }]);
|
|
62
|
+
expect(getFlowsAvailabilitySync("s2")).toBe(true);
|
|
63
|
+
off();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("subscriber leaves cache `false` when neither flows nor flows:new are available", () => {
|
|
67
|
+
const off = installFlowsAvailabilitySubscriber();
|
|
68
|
+
publishSessionData("s3", "flowsList", []);
|
|
69
|
+
publishSessionData("s3", "commandsList", [{ name: "skill:foo" }]);
|
|
70
|
+
expect(getFlowsAvailabilitySync("s3")).toBe(false);
|
|
71
|
+
off();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("subscriber drops availability to false when session data is cleared", () => {
|
|
75
|
+
const off = installFlowsAvailabilitySubscriber();
|
|
76
|
+
publishSessionData("s4", "flowsList", [{ name: "x" }]);
|
|
77
|
+
expect(getFlowsAvailabilitySync("s4")).toBe(true);
|
|
78
|
+
|
|
79
|
+
clearSessionData("s4");
|
|
80
|
+
expect(getFlowsAvailabilitySync("s4")).toBe(false);
|
|
81
|
+
off();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("subscriber tracks multiple sessions independently", () => {
|
|
85
|
+
const off = installFlowsAvailabilitySubscriber();
|
|
86
|
+
publishSessionData("sA", "flowsList", [{ name: "a" }]);
|
|
87
|
+
publishSessionData("sB", "flowsList", []);
|
|
88
|
+
expect(getFlowsAvailabilitySync("sA")).toBe(true);
|
|
89
|
+
expect(getFlowsAvailabilitySync("sB")).toBe(false);
|
|
90
|
+
off();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discoverability test — flows-plugin manifest.
|
|
3
|
+
*
|
|
4
|
+
* Verifies the flows-plugin's `pi-dashboard-plugin` manifest (read from its
|
|
5
|
+
* own package.json) validates against the dashboard's manifest schema and
|
|
6
|
+
* encodes the contract this plugin promises to the shell.
|
|
7
|
+
*
|
|
8
|
+
* Specifically asserts:
|
|
9
|
+
* - manifest is present and schema-valid
|
|
10
|
+
* - plugin id is `flows`
|
|
11
|
+
* - `SessionFlowActionsClaim` lives in the `session-card-flows` slot
|
|
12
|
+
* (not `session-card-action-bar` — see change: add-flows-subcard)
|
|
13
|
+
* - the `session-card-flows` claim declares the `shouldRenderFlowsSubcard`
|
|
14
|
+
* gate so the FLOWS subcard hides cleanly when no flows are available
|
|
15
|
+
* - `shouldRenderFlowsSubcard` is exported from the client entry so the
|
|
16
|
+
* vite plugin's name-resolver can wire it
|
|
17
|
+
*/
|
|
18
|
+
import { describe, it, expect } from "vitest";
|
|
19
|
+
import { readFileSync } from "node:fs";
|
|
20
|
+
import { dirname, resolve } from "node:path";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
import { validateManifest } from "@blackbelt-technology/dashboard-plugin-runtime/manifest-validator";
|
|
23
|
+
import * as flowsClientEntry from "../client/index.js";
|
|
24
|
+
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = dirname(__filename);
|
|
27
|
+
const PACKAGE_JSON = resolve(__dirname, "../../package.json");
|
|
28
|
+
|
|
29
|
+
describe("flows-plugin manifest discoverability", () => {
|
|
30
|
+
const pkg = JSON.parse(readFileSync(PACKAGE_JSON, "utf-8")) as {
|
|
31
|
+
name: string;
|
|
32
|
+
"pi-dashboard-plugin"?: unknown;
|
|
33
|
+
};
|
|
34
|
+
const manifest = pkg["pi-dashboard-plugin"];
|
|
35
|
+
|
|
36
|
+
it("declares a `pi-dashboard-plugin` manifest field", () => {
|
|
37
|
+
expect(manifest).toBeDefined();
|
|
38
|
+
expect(typeof manifest).toBe("object");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("validates against the dashboard's manifest schema", () => {
|
|
42
|
+
expect(() => validateManifest(manifest, pkg.name)).not.toThrow();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("declares plugin id `flows`", () => {
|
|
46
|
+
const validated = validateManifest(manifest, pkg.name);
|
|
47
|
+
expect(validated.id).toBe("flows");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("routes SessionFlowActions through `session-card-flows` slot", () => {
|
|
51
|
+
// Post add-flows-subcard: SessionFlowActionsClaim moved from
|
|
52
|
+
// `session-card-action-bar` to its own `session-card-flows` slot so the
|
|
53
|
+
// shell can host it inside a dedicated FLOWS subcard.
|
|
54
|
+
const validated = validateManifest(manifest, pkg.name);
|
|
55
|
+
const flowsSubcardClaims = validated.claims.filter(
|
|
56
|
+
(c) => c.slot === "session-card-flows",
|
|
57
|
+
);
|
|
58
|
+
const components = new Set(flowsSubcardClaims.map((c) => c.component));
|
|
59
|
+
expect(components.has("SessionFlowActionsClaim")).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("no claim occupies the deprecated `session-card-action-bar` mapping", () => {
|
|
63
|
+
// Defensive: ensure the legacy slot mapping is gone (would silently
|
|
64
|
+
// double-render the actions outside the FLOWS subcard otherwise).
|
|
65
|
+
const validated = validateManifest(manifest, pkg.name);
|
|
66
|
+
const actionBarClaims = validated.claims.filter(
|
|
67
|
+
(c) =>
|
|
68
|
+
c.slot === "session-card-action-bar" &&
|
|
69
|
+
c.component === "SessionFlowActionsClaim",
|
|
70
|
+
);
|
|
71
|
+
expect(actionBarClaims).toHaveLength(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("every `session-card-flows` claim declares the shouldRenderFlowsSubcard gate", () => {
|
|
75
|
+
const validated = validateManifest(manifest, pkg.name);
|
|
76
|
+
const flowsClaims = validated.claims.filter(
|
|
77
|
+
(c) => c.slot === "session-card-flows",
|
|
78
|
+
);
|
|
79
|
+
expect(flowsClaims.length).toBeGreaterThan(0);
|
|
80
|
+
for (const c of flowsClaims) {
|
|
81
|
+
expect((c as { shouldRender?: string }).shouldRender).toBe(
|
|
82
|
+
"shouldRenderFlowsSubcard",
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("client entry exports `shouldRenderFlowsSubcard`", () => {
|
|
88
|
+
// The vite plugin's plugin-registry generator resolves the
|
|
89
|
+
// `shouldRender` string against this module's named exports. If the
|
|
90
|
+
// export is missing, the build fails — this test catches the
|
|
91
|
+
// contract break before the build.
|
|
92
|
+
expect(
|
|
93
|
+
(flowsClientEntry as { shouldRenderFlowsSubcard?: unknown })
|
|
94
|
+
.shouldRenderFlowsSubcard,
|
|
95
|
+
).toBeTypeOf("function");
|
|
96
|
+
});
|
|
97
|
+
});
|