@blackbelt-technology/pi-dashboard-flows-plugin 0.6.1 → 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 +24 -17
- 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 -154
- 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,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the plugin-internal UI selection state. Verifies the
|
|
3
|
-
* module-level store, setter semantics, no-op short-circuiting, and
|
|
4
|
-
* the unified `dismissAll` cleanup. See change:
|
|
5
|
-
* pluginize-flows-via-registry.
|
|
6
|
-
*/
|
|
7
|
-
import React from "react";
|
|
8
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
9
|
-
import { render, act, cleanup } from "@testing-library/react";
|
|
10
|
-
import {
|
|
11
|
-
useFlowsUiState,
|
|
12
|
-
useFlowsUiActions,
|
|
13
|
-
__resetFlowsUiStateForTests,
|
|
14
|
-
type FlowsUiState,
|
|
15
|
-
} from "../client/FlowsUiStateContext.js";
|
|
16
|
-
|
|
17
|
-
function Probe({ onSnapshot }: { onSnapshot: (state: FlowsUiState) => void }) {
|
|
18
|
-
const state = useFlowsUiState();
|
|
19
|
-
onSnapshot(state);
|
|
20
|
-
return (
|
|
21
|
-
<div data-testid="probe">
|
|
22
|
-
src={state.sourceOpenAgent ?? "(null)"} yaml={state.flowYamlPreview?.title ?? "(null)"}
|
|
23
|
-
</div>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe("FlowsUiStateContext", () => {
|
|
28
|
-
beforeEach(() => __resetFlowsUiStateForTests());
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
cleanup();
|
|
31
|
-
__resetFlowsUiStateForTests();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("starts with the initial state (all nulls / false)", () => {
|
|
35
|
-
const snaps: FlowsUiState[] = [];
|
|
36
|
-
render(<Probe onSnapshot={(s) => snaps.push(s)} />);
|
|
37
|
-
expect(snaps[0]).toEqual({
|
|
38
|
-
sourceOpenAgent: null,
|
|
39
|
-
flowYamlPreview: null,
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("does not notify when a setter is called with the same value", () => {
|
|
44
|
-
let renderCount = 0;
|
|
45
|
-
function CountingProbe() {
|
|
46
|
-
renderCount++;
|
|
47
|
-
useFlowsUiState();
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
function ActionsProbe() {
|
|
51
|
-
actions = useFlowsUiActions();
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
render(
|
|
55
|
-
<>
|
|
56
|
-
<ActionsProbe />
|
|
57
|
-
<CountingProbe />
|
|
58
|
-
</>,
|
|
59
|
-
);
|
|
60
|
-
const initial = renderCount;
|
|
61
|
-
|
|
62
|
-
act(() => actions.setSourceOpenAgent(null)); // already null
|
|
63
|
-
expect(renderCount).toBe(initial); // no extra render
|
|
64
|
-
|
|
65
|
-
act(() => actions.setSourceOpenAgent("alpha")); // change
|
|
66
|
-
expect(renderCount).toBe(initial + 1);
|
|
67
|
-
|
|
68
|
-
act(() => actions.setSourceOpenAgent("alpha")); // same value
|
|
69
|
-
expect(renderCount).toBe(initial + 1); // no extra render
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("dismissAll clears every field in one notify", () => {
|
|
73
|
-
let renderCount = 0;
|
|
74
|
-
function CountingProbe() {
|
|
75
|
-
renderCount++;
|
|
76
|
-
useFlowsUiState();
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
function ActionsProbe() {
|
|
80
|
-
actions = useFlowsUiActions();
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
render(
|
|
84
|
-
<>
|
|
85
|
-
<ActionsProbe />
|
|
86
|
-
<CountingProbe />
|
|
87
|
-
</>,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// Set every field.
|
|
91
|
-
act(() => {
|
|
92
|
-
actions.setSourceOpenAgent("beta");
|
|
93
|
-
actions.setFlowYamlPreview({ content: "x", title: "t" });
|
|
94
|
-
});
|
|
95
|
-
const beforeDismiss = renderCount;
|
|
96
|
-
|
|
97
|
-
// dismissAll: single act → expect a single notify (one render).
|
|
98
|
-
act(() => actions.dismissAll());
|
|
99
|
-
expect(renderCount).toBe(beforeDismiss + 1);
|
|
100
|
-
|
|
101
|
-
// All fields cleared.
|
|
102
|
-
const probeText = (function readProbe() {
|
|
103
|
-
const snaps: FlowsUiState[] = [];
|
|
104
|
-
render(<Probe onSnapshot={(s) => snaps.push(s)} />);
|
|
105
|
-
return snaps[0];
|
|
106
|
-
})();
|
|
107
|
-
expect(probeText).toEqual({
|
|
108
|
-
sourceOpenAgent: null,
|
|
109
|
-
flowYamlPreview: null,
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("returns a stable actions reference across renders", () => {
|
|
114
|
-
const seen = new Set<unknown>();
|
|
115
|
-
function ActionsProbe() {
|
|
116
|
-
const a = useFlowsUiActions();
|
|
117
|
-
seen.add(a);
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
const { rerender } = render(<ActionsProbe />);
|
|
121
|
-
rerender(<ActionsProbe />);
|
|
122
|
-
rerender(<ActionsProbe />);
|
|
123
|
-
expect(seen.size).toBe(1);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Shared module-level holder so tests can call setters from outside
|
|
128
|
-
// the rendered tree.
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
-
let actions: any;
|
|
131
|
-
|
|
132
|
-
function ActionsProbeWithUI() {
|
|
133
|
-
actions = useFlowsUiActions();
|
|
134
|
-
const state = useFlowsUiState();
|
|
135
|
-
return (
|
|
136
|
-
<div data-testid="probe">
|
|
137
|
-
src={state.sourceOpenAgent ?? "(null)"} yaml={state.flowYamlPreview?.title ?? "(null)"}
|
|
138
|
-
</div>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the flow_write / flow_agents authoring tool renderers.
|
|
3
|
-
* Covers success, validation-failure, and list states + the args-backed
|
|
4
|
-
* Mermaid snapshot. See change: rework-flows-plugin-for-new-pi-flows.
|
|
5
|
-
*/
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { describe, it, expect, afterEach } from "vitest";
|
|
8
|
-
import { render, cleanup, fireEvent } from "@testing-library/react";
|
|
9
|
-
import {
|
|
10
|
-
UiPrimitiveProvider,
|
|
11
|
-
createUiPrimitiveRegistry,
|
|
12
|
-
registerUiPrimitive,
|
|
13
|
-
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
14
|
-
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
15
|
-
import { FlowWriteToolRenderer } from "../client/FlowWriteToolRenderer.js";
|
|
16
|
-
import { FlowAgentsToolRenderer } from "../client/FlowAgentsToolRenderer.js";
|
|
17
|
-
|
|
18
|
-
const registry = createUiPrimitiveRegistry();
|
|
19
|
-
registerUiPrimitive(
|
|
20
|
-
registry,
|
|
21
|
-
UI_PRIMITIVE_KEYS.markdownContent,
|
|
22
|
-
(({ content }: { content: string }) => <div data-testid="md">{content}</div>) as never,
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
function renderWrite(props: { toolInput: Record<string, unknown>; status?: "running" | "complete" | "error"; result?: string }) {
|
|
26
|
-
return render(
|
|
27
|
-
<UiPrimitiveProvider value={registry}>
|
|
28
|
-
<FlowWriteToolRenderer toolName="flow_write" sessionId="s1" {...props} />
|
|
29
|
-
</UiPrimitiveProvider>,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const FLOW_YAML = `name: invoice
|
|
34
|
-
steps:
|
|
35
|
-
- id: extract
|
|
36
|
-
type: agent
|
|
37
|
-
agent: e
|
|
38
|
-
blockedBy: []
|
|
39
|
-
- id: validate
|
|
40
|
-
type: code
|
|
41
|
-
blockedBy: [extract]`;
|
|
42
|
-
|
|
43
|
-
afterEach(() => cleanup());
|
|
44
|
-
|
|
45
|
-
describe("FlowWriteToolRenderer", () => {
|
|
46
|
-
it("success: shows command, counts, and a Mermaid snapshot from args", () => {
|
|
47
|
-
const { getByText, getByTestId } = renderWrite({
|
|
48
|
-
toolInput: { name: "invoice", content: FLOW_YAML },
|
|
49
|
-
status: "complete",
|
|
50
|
-
result: JSON.stringify({ written: true, name: "invoice", namespace: "custom", command: "custom:invoice", path: "/p/invoice.yaml", diagnostics: [] }),
|
|
51
|
-
});
|
|
52
|
-
expect(getByText("/custom:invoice")).toBeTruthy();
|
|
53
|
-
expect(getByText("2 steps · 1 agents, 1 code")).toBeTruthy();
|
|
54
|
-
expect(getByTestId("md").textContent).toContain("graph LR");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("validation failure: renders diagnostics verbatim", () => {
|
|
58
|
-
const { getByText } = renderWrite({
|
|
59
|
-
toolInput: { name: "invoice", content: FLOW_YAML },
|
|
60
|
-
status: "error",
|
|
61
|
-
result: JSON.stringify({ written: false, diagnostics: [{ message: 'step "validate" missing' }] }),
|
|
62
|
-
});
|
|
63
|
-
expect(getByText(/step "validate" missing/)).toBeTruthy();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("view-yaml toggle reveals the submitted args", () => {
|
|
67
|
-
const { getByText, queryByText } = renderWrite({
|
|
68
|
-
toolInput: { name: "invoice", content: FLOW_YAML },
|
|
69
|
-
status: "complete",
|
|
70
|
-
result: JSON.stringify({ written: true, command: "custom:invoice", diagnostics: [] }),
|
|
71
|
-
});
|
|
72
|
-
expect(queryByText(/type: code/)).toBeNull();
|
|
73
|
-
fireEvent.click(getByText(/View flow YAML/));
|
|
74
|
-
expect(getByText(/type: code/)).toBeTruthy();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("FlowAgentsToolRenderer", () => {
|
|
79
|
-
it("list: shows agent names + count (as rows)", () => {
|
|
80
|
-
const { getByText } = render(
|
|
81
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
82
|
-
toolInput={{ op: "list" }} status="complete"
|
|
83
|
-
result={JSON.stringify([{ name: "reviewer" }, { name: "reader" }])} />,
|
|
84
|
-
);
|
|
85
|
-
expect(getByText("list · 2 agents")).toBeTruthy();
|
|
86
|
-
expect(getByText("reviewer")).toBeTruthy();
|
|
87
|
-
expect(getByText("reader")).toBeTruthy();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("write success: shows saved name", () => {
|
|
91
|
-
const { getByText } = render(
|
|
92
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
93
|
-
toolInput={{ op: "write", content: "name: reviewer" }} status="complete"
|
|
94
|
-
result={JSON.stringify({ written: true, name: "reviewer", path: "/a/reviewer.md", diagnostics: [] })} />,
|
|
95
|
-
);
|
|
96
|
-
expect(getByText("reviewer")).toBeTruthy();
|
|
97
|
-
expect(getByText("saved")).toBeTruthy();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("write failure: shows diagnostics", () => {
|
|
101
|
-
const { getByText } = render(
|
|
102
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
103
|
-
toolInput={{ op: "write", content: "bad" }} status="error"
|
|
104
|
-
result={JSON.stringify({ written: false, error: "missing name" })} />,
|
|
105
|
-
);
|
|
106
|
-
expect(getByText("not written")).toBeTruthy();
|
|
107
|
-
expect(getByText(/missing name/)).toBeTruthy();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const AGENTS_DETAILS = [
|
|
111
|
-
{ name: "test-analyzer", description: "Emits a one-line note", source_type: "local", tools: ["read"], inputs: ["focus"], outputs: ["notes"], use_when: "parallel analysis branch" },
|
|
112
|
-
{ name: "flow-decision", description: "Decides at forks", source_type: "built-in" },
|
|
113
|
-
];
|
|
114
|
-
|
|
115
|
-
it("list truncated (no details): does not report zero, shows truncated indicator", () => {
|
|
116
|
-
const { queryByText, getByText } = render(
|
|
117
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
118
|
-
toolInput={{ op: "list" }} status="complete"
|
|
119
|
-
result={'«76 earlier lines hidden»\n "source_type": "local"\n }\n]'} />,
|
|
120
|
-
);
|
|
121
|
-
expect(queryByText(/·\s*0 agents/)).toBeNull();
|
|
122
|
-
expect(getByText(/truncated/i)).toBeTruthy();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("list details present + truncated text: renders rows (name+description+badge), no truncated", () => {
|
|
126
|
-
const { getByText, queryByText } = render(
|
|
127
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
128
|
-
toolInput={{ op: "list" }} status="complete"
|
|
129
|
-
toolDetails={{ count: 2, agents: AGENTS_DETAILS }}
|
|
130
|
-
result={'«76 earlier lines hidden»\n]'} />,
|
|
131
|
-
);
|
|
132
|
-
expect(getByText("list · 2 agents")).toBeTruthy();
|
|
133
|
-
expect(getByText("test-analyzer")).toBeTruthy();
|
|
134
|
-
expect(getByText("Emits a one-line note")).toBeTruthy();
|
|
135
|
-
expect(getByText("flow-decision")).toBeTruthy();
|
|
136
|
-
// source badges present
|
|
137
|
-
expect(getByText("local")).toBeTruthy();
|
|
138
|
-
expect(getByText("built-in")).toBeTruthy();
|
|
139
|
-
expect(queryByText(/truncated/i)).toBeNull();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("list rows are collapsed by default (no detail block until expand)", () => {
|
|
143
|
-
const { queryByText } = render(
|
|
144
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
145
|
-
toolInput={{ op: "list" }} status="complete"
|
|
146
|
-
toolDetails={{ count: 2, agents: AGENTS_DETAILS }} result={"[]"} />,
|
|
147
|
-
);
|
|
148
|
-
// detail-only field values must not be visible before expanding
|
|
149
|
-
expect(queryByText("focus")).toBeNull();
|
|
150
|
-
expect(queryByText("parallel analysis branch")).toBeNull();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("expanding a row reveals present fields and omits absent ones", () => {
|
|
154
|
-
const { getByText, queryByText } = render(
|
|
155
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
156
|
-
toolInput={{ op: "list" }} status="complete"
|
|
157
|
-
toolDetails={{ count: 2, agents: AGENTS_DETAILS }} result={"[]"} />,
|
|
158
|
-
);
|
|
159
|
-
fireEvent.click(getByText("test-analyzer"));
|
|
160
|
-
expect(getByText("read")).toBeTruthy(); // tools
|
|
161
|
-
expect(getByText("focus")).toBeTruthy(); // inputs
|
|
162
|
-
expect(getByText("notes")).toBeTruthy(); // outputs
|
|
163
|
-
expect(getByText("parallel analysis branch")).toBeTruthy(); // use_when
|
|
164
|
-
// flow-decision (no tools/inputs/outputs) — expand shows no such fields
|
|
165
|
-
fireEvent.click(getByText("flow-decision"));
|
|
166
|
-
// its use_when falls back to description; but tools/inputs/outputs absent
|
|
167
|
-
expect(queryByText("grep")).toBeNull();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("list text fallback (no details): renders rows from parsed text catalog", () => {
|
|
171
|
-
const { getByText } = render(
|
|
172
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
173
|
-
toolInput={{ op: "list" }} status="complete"
|
|
174
|
-
result={JSON.stringify([{ name: "x", description: "the x", source_type: "local" }, { name: "y", description: "the y", source_type: "package" }])} />,
|
|
175
|
-
);
|
|
176
|
-
expect(getByText("list · 2 agents")).toBeTruthy();
|
|
177
|
-
expect(getByText("x")).toBeTruthy();
|
|
178
|
-
expect(getByText("the x")).toBeTruthy();
|
|
179
|
-
expect(getByText("y")).toBeTruthy();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("list genuine empty array: reports 0 agents", () => {
|
|
183
|
-
const { getByText, queryByText } = render(
|
|
184
|
-
<FlowAgentsToolRenderer toolName="flow_agents" sessionId="s1"
|
|
185
|
-
toolInput={{ op: "list" }} status="complete" result={"[]"} />,
|
|
186
|
-
);
|
|
187
|
-
expect(getByText("list · 0 agents")).toBeTruthy();
|
|
188
|
-
expect(queryByText(/truncated/i)).toBeNull();
|
|
189
|
-
});
|
|
190
|
-
});
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flows → automation action contribution (publish/collect): availability
|
|
3
|
-
* gating + enum options from the injected live flows resolver, flow:run event
|
|
4
|
-
* build, and pure-publisher wiring (provide, no consume).
|
|
5
|
-
* See change: decouple-automation-action-registry, fix-automation-flow-detection.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { describe, expect, it, vi } from "vitest";
|
|
9
|
-
import {
|
|
10
|
-
ACTION_CONTRIBUTION_KEY,
|
|
11
|
-
type FlowsForCwd,
|
|
12
|
-
flowsActionContributions,
|
|
13
|
-
provideFlowsActions,
|
|
14
|
-
summarizeFlowResult,
|
|
15
|
-
} from "../server/automation-actions.js";
|
|
16
|
-
|
|
17
|
-
/** Stub resolver: returns the flows configured for a given cwd. */
|
|
18
|
-
function stubFlows(map: Record<string, string[]>): FlowsForCwd {
|
|
19
|
-
return (cwd: string) => map[cwd] ?? [];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const noFlows: FlowsForCwd = () => [];
|
|
23
|
-
|
|
24
|
-
describe("flowsActionContributions", () => {
|
|
25
|
-
it("contributes flows.run only (no resume/cancel); gated on the live flows resolver; enum options resolve", () => {
|
|
26
|
-
const flowsForCwd = stubFlows({ "/w/invoice-bot": ["invoicebot:pull"] });
|
|
27
|
-
const contribs = flowsActionContributions(flowsForCwd);
|
|
28
|
-
expect(contribs.map((c) => c.id)).toEqual(["flows.run"]);
|
|
29
|
-
|
|
30
|
-
const run = contribs[0]!;
|
|
31
|
-
expect(run.source).toBe("flows");
|
|
32
|
-
// Package/event-registered flow, not on disk under .pi/flows/flows.
|
|
33
|
-
expect(run.available!("/w/invoice-bot")).toBe(true);
|
|
34
|
-
// No running session for this cwd → empty → unavailable.
|
|
35
|
-
expect(run.available!("/w/other")).toBe(false);
|
|
36
|
-
|
|
37
|
-
const flowField = run.payloadSchema!.find((f) => f.key === "flow")!;
|
|
38
|
-
expect(flowField.type).toBe("enum");
|
|
39
|
-
expect(flowField.options!("/w/invoice-bot")).toEqual(["invoicebot:pull"]);
|
|
40
|
-
expect(flowField.options!("/w/other")).toEqual([]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("flows.run emits a flow:run event (flowName+task) and declares its completion", () => {
|
|
44
|
-
const run = flowsActionContributions(noFlows)[0]!;
|
|
45
|
-
const ev = run.buildEvent!({ payload: { flow: "test:capabilities", task: "do it" }, automation: {} });
|
|
46
|
-
expect(ev).toMatchObject({ eventType: "flow:run", data: { flowName: "test:capabilities", task: "do it" } });
|
|
47
|
-
// Event-dispatched flow runs emit no agent_end — the action declares how it
|
|
48
|
-
// finishes so the automation engine can finalize generically.
|
|
49
|
-
expect(ev!.completion!.eventType).toBe("flow_complete");
|
|
50
|
-
expect(typeof ev!.completion!.summarize).toBe("function");
|
|
51
|
-
// task optional
|
|
52
|
-
expect(run.buildEvent!({ payload: { flow: "test:capabilities" }, automation: {} }))
|
|
53
|
-
.toMatchObject({ eventType: "flow:run", data: { flowName: "test:capabilities" } });
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("flows.run emits data.inputs (per-fire resolved, types preserved), task optional", () => {
|
|
57
|
-
const run = flowsActionContributions(noFlows)[0]!;
|
|
58
|
-
// Every flows.run also declares its completion (merged from
|
|
59
|
-
// finalize-event-dispatched-automation-runs).
|
|
60
|
-
const completion = { eventType: "flow_complete", summarize: expect.any(Function) };
|
|
61
|
-
// payload arrives already interpolated by the engine: ${{trigger}} resolved.
|
|
62
|
-
expect(
|
|
63
|
-
run.buildEvent!({
|
|
64
|
-
payload: { flow: "invoicebot:process", inputs: { invoice: "/spool/inv-042.pdf", priority: 5, dry: true } },
|
|
65
|
-
automation: {},
|
|
66
|
-
}),
|
|
67
|
-
).toEqual({
|
|
68
|
-
eventType: "flow:run",
|
|
69
|
-
data: { flowName: "invoicebot:process", inputs: { invoice: "/spool/inv-042.pdf", priority: 5, dry: true } },
|
|
70
|
-
completion,
|
|
71
|
-
});
|
|
72
|
-
// task + inputs coexist
|
|
73
|
-
expect(
|
|
74
|
-
run.buildEvent!({ payload: { flow: "a:b", task: "label", inputs: { x: 1 } }, automation: {} }),
|
|
75
|
-
).toEqual({ eventType: "flow:run", data: { flowName: "a:b", task: "label", inputs: { x: 1 } }, completion });
|
|
76
|
-
// empty / non-object inputs omitted
|
|
77
|
-
expect(run.buildEvent!({ payload: { flow: "a:b", inputs: {} }, automation: {} }))
|
|
78
|
-
.toEqual({ eventType: "flow:run", data: { flowName: "a:b" }, completion });
|
|
79
|
-
expect(run.buildEvent!({ payload: { flow: "a:b", inputs: "nope" }, automation: {} }))
|
|
80
|
-
.toEqual({ eventType: "flow:run", data: { flowName: "a:b" }, completion });
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("flows.run rejects a malformed flow id (emits nothing)", () => {
|
|
84
|
-
const run = flowsActionContributions(noFlows)[0]!;
|
|
85
|
-
expect(run.buildEvent!({ payload: { flow: "test:cap x", task: "t" }, automation: {} })).toBeNull();
|
|
86
|
-
expect(run.buildEvent!({ payload: { flow: "nocolon", task: "t" }, automation: {} })).toBeNull();
|
|
87
|
-
expect(run.buildEvent!({ payload: { flow: "" }, automation: {} })).toBeNull();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("summarizeFlowResult (flows owns the FlowResult shape)", () => {
|
|
92
|
-
it("builds a line from status + flowName + summary", () => {
|
|
93
|
-
expect(
|
|
94
|
-
summarizeFlowResult({
|
|
95
|
-
status: "success",
|
|
96
|
-
flowName: "invoicebot:process",
|
|
97
|
-
lastResult: { result: { summary: "done: exported" } },
|
|
98
|
-
}),
|
|
99
|
-
).toBe("flow invoicebot:process success: done: exported");
|
|
100
|
-
});
|
|
101
|
-
it("tolerates a missing summary and missing fields", () => {
|
|
102
|
-
expect(summarizeFlowResult({ status: "error", flowName: "x:y" })).toBe("flow x:y error");
|
|
103
|
-
expect(summarizeFlowResult(undefined)).toBe("flow finished");
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("provideFlowsActions (pure publisher)", () => {
|
|
108
|
-
it("publishes the contribution under automation.action.flows and consumes nothing", () => {
|
|
109
|
-
const provide = vi.fn();
|
|
110
|
-
provideFlowsActions(provide, () => {}, noFlows);
|
|
111
|
-
expect(provide).toHaveBeenCalledTimes(1);
|
|
112
|
-
const [key, value] = provide.mock.calls[0]!;
|
|
113
|
-
expect(key).toBe(ACTION_CONTRIBUTION_KEY);
|
|
114
|
-
expect(key).toBe("automation.action.flows");
|
|
115
|
-
expect((value as Array<{ id: string }>).map((c) => c.id)).toEqual(["flows.run"]);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
@@ -1,154 +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
|
-
import React from "react";
|
|
11
|
-
import { describe, it, expect, afterEach, beforeEach, vi } from "vitest";
|
|
12
|
-
import { render, cleanup, fireEvent, waitFor } from "@testing-library/react";
|
|
13
|
-
import {
|
|
14
|
-
UiPrimitiveProvider,
|
|
15
|
-
createUiPrimitiveRegistry,
|
|
16
|
-
registerUiPrimitive,
|
|
17
|
-
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
18
|
-
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
19
|
-
import type { FlowAgentState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
20
|
-
import { FlowAgentCard } from "../client/FlowAgentCard.js";
|
|
21
|
-
|
|
22
|
-
const registry = createUiPrimitiveRegistry();
|
|
23
|
-
|
|
24
|
-
// AgentCardShell: render headerRight + children + forward onClick.
|
|
25
|
-
registerUiPrimitive(
|
|
26
|
-
registry,
|
|
27
|
-
UI_PRIMITIVE_KEYS.agentCard,
|
|
28
|
-
(({ children, headerRight, onClick }: { children: React.ReactNode; headerRight?: React.ReactNode; onClick?: () => void }) => (
|
|
29
|
-
<div data-testid="card" onClick={onClick}>
|
|
30
|
-
<div>{headerRight}</div>
|
|
31
|
-
{children}
|
|
32
|
-
</div>
|
|
33
|
-
)) as never,
|
|
34
|
-
);
|
|
35
|
-
registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.formatTokens, ((n: number) => String(n)) as never);
|
|
36
|
-
registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.formatDuration, ((n: number) => String(n)) as never);
|
|
37
|
-
// Dialog: render children only when open.
|
|
38
|
-
registerUiPrimitive(
|
|
39
|
-
registry,
|
|
40
|
-
UI_PRIMITIVE_KEYS.dialog,
|
|
41
|
-
(({ open, title, children }: { open: boolean; title?: string; children: React.ReactNode }) =>
|
|
42
|
-
open ? (
|
|
43
|
-
<div data-testid="dialog">
|
|
44
|
-
<div data-testid="dialog-title">{title}</div>
|
|
45
|
-
{children}
|
|
46
|
-
</div>
|
|
47
|
-
) : null) as never,
|
|
48
|
-
);
|
|
49
|
-
// MarkdownContent: surface the raw content for fence assertions.
|
|
50
|
-
registerUiPrimitive(
|
|
51
|
-
registry,
|
|
52
|
-
UI_PRIMITIVE_KEYS.markdownContent,
|
|
53
|
-
(({ content }: { content: string }) => <pre data-testid="md">{content}</pre>) as never,
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
function makeAgent(over: Partial<FlowAgentState>): FlowAgentState {
|
|
57
|
-
return {
|
|
58
|
-
agentName: "verify",
|
|
59
|
-
stepId: "verify",
|
|
60
|
-
status: "complete",
|
|
61
|
-
blockedBy: [],
|
|
62
|
-
recentTools: [],
|
|
63
|
-
detailHistory: [],
|
|
64
|
-
...over,
|
|
65
|
-
} as FlowAgentState;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function renderCard(agent: FlowAgentState) {
|
|
69
|
-
return render(
|
|
70
|
-
<UiPrimitiveProvider value={registry}>
|
|
71
|
-
<FlowAgentCard agent={agent} />
|
|
72
|
-
</UiPrimitiveProvider>,
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const HANDLER_PATH = "/home/u/proj/.pi/flows/flows/custom/test-flow/verify.ts";
|
|
77
|
-
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
cleanup();
|
|
80
|
-
vi.unstubAllGlobals();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe("FlowAgentCard code-handler source", () => {
|
|
84
|
-
it("3.1 renders the code button only for code nodes with a target", () => {
|
|
85
|
-
const { queryByTitle, unmount } = renderCard(
|
|
86
|
-
makeAgent({ nodeKind: "code", codeTarget: HANDLER_PATH }),
|
|
87
|
-
);
|
|
88
|
-
expect(queryByTitle("View handler source")).not.toBeNull();
|
|
89
|
-
unmount();
|
|
90
|
-
|
|
91
|
-
// agent node — no code button
|
|
92
|
-
const agentCard = renderCard(makeAgent({ nodeKind: "agent" }));
|
|
93
|
-
expect(agentCard.queryByTitle("View handler source")).toBeNull();
|
|
94
|
-
agentCard.unmount();
|
|
95
|
-
|
|
96
|
-
// code node without target — no code button
|
|
97
|
-
const noTarget = renderCard(makeAgent({ nodeKind: "code", codeTarget: undefined }));
|
|
98
|
-
expect(noTarget.queryByTitle("View handler source")).toBeNull();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("3.2 clicking the code button opens a dialog and fetches the handler path", async () => {
|
|
102
|
-
const fetchMock = vi.fn(async () => ({
|
|
103
|
-
json: async () => ({ success: true, data: { type: "file", content: "export const x = 1;" } }),
|
|
104
|
-
}));
|
|
105
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
106
|
-
|
|
107
|
-
const { getByTitle, findByTestId } = renderCard(
|
|
108
|
-
makeAgent({ nodeKind: "code", codeTarget: HANDLER_PATH }),
|
|
109
|
-
);
|
|
110
|
-
fireEvent.click(getByTitle("View handler source"));
|
|
111
|
-
|
|
112
|
-
await findByTestId("dialog");
|
|
113
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
114
|
-
`/api/pi-resource-file?path=${encodeURIComponent(HANDLER_PATH)}`,
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("3.3 loaded handler content is wrapped in a ```ts fence", async () => {
|
|
119
|
-
vi.stubGlobal(
|
|
120
|
-
"fetch",
|
|
121
|
-
vi.fn(async () => ({
|
|
122
|
-
json: async () => ({ success: true, data: { type: "file", content: "export const x = 1;" } }),
|
|
123
|
-
})),
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const { getByTitle, findByTestId } = renderCard(
|
|
127
|
-
makeAgent({ nodeKind: "code-decision", codeTarget: HANDLER_PATH }),
|
|
128
|
-
);
|
|
129
|
-
fireEvent.click(getByTitle("View handler source"));
|
|
130
|
-
|
|
131
|
-
const md = await findByTestId("md");
|
|
132
|
-
expect(md.textContent).toBe("```ts\nexport const x = 1;\n```");
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("3.4 fetch error surfaces in the dialog", async () => {
|
|
136
|
-
vi.stubGlobal(
|
|
137
|
-
"fetch",
|
|
138
|
-
vi.fn(async () => ({
|
|
139
|
-
json: async () => ({ success: false, error: "path not in allowed resource location" }),
|
|
140
|
-
})),
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
const { getByTitle, findByTestId } = renderCard(
|
|
144
|
-
makeAgent({ nodeKind: "code", codeTarget: HANDLER_PATH }),
|
|
145
|
-
);
|
|
146
|
-
fireEvent.click(getByTitle("View handler source"));
|
|
147
|
-
|
|
148
|
-
const dialog = await findByTestId("dialog");
|
|
149
|
-
await waitFor(() =>
|
|
150
|
-
expect(dialog.textContent).toContain("path not in allowed resource location"),
|
|
151
|
-
);
|
|
152
|
-
expect(dialog.querySelector('[data-testid="md"]')).toBeNull();
|
|
153
|
-
});
|
|
154
|
-
});
|