@blackbelt-technology/pi-dashboard-flows-plugin 0.5.3 → 0.6.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 +48 -4
- package/src/AGENTS.md +8 -0
- package/src/__tests__/FlowGraph.test.ts +151 -5
- package/src/__tests__/FlowInputWiring.test.tsx +97 -0
- package/src/__tests__/FlowSummary.test.tsx +331 -0
- package/src/__tests__/FlowYamlPreview.test.tsx +75 -0
- package/src/__tests__/FlowsSessionStateContext.test.tsx +223 -0
- package/src/__tests__/FlowsUiStateContext.test.tsx +140 -0
- package/src/__tests__/authoring-renderers.test.tsx +190 -0
- package/src/__tests__/automation-actions.test.ts +117 -0
- package/src/__tests__/flow-agent-card-code-source.test.tsx +154 -0
- package/src/__tests__/flow-agent-cost.test.tsx +160 -0
- package/src/__tests__/flow-agent-error.test.ts +60 -0
- package/src/__tests__/flow-collapse-storage.test.ts +90 -0
- package/src/__tests__/flow-edges.test.ts +195 -0
- package/src/__tests__/flow-inputs.test.ts +69 -0
- package/src/__tests__/flow-reducer-bridge-contract.test.ts +108 -0
- package/src/__tests__/flow-reducer-seed-on-start.test.ts +61 -0
- package/src/__tests__/flow-yaml-parse.test.ts +124 -0
- package/src/__tests__/flows-for-cwd.test.ts +51 -0
- package/src/__tests__/flowsAvailability.test.ts +79 -0
- package/src/__tests__/manifest-discoverability.test.ts +97 -0
- package/src/__tests__/node-kind-reducer.test.ts +135 -0
- package/src/__tests__/plugin-action-handler.test.ts +54 -0
- package/src/__tests__/render-actions.test.ts +63 -0
- package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
- package/src/bridge/AGENTS.md +8 -0
- package/src/bridge/flow-question-adapter.ts +93 -0
- package/src/bridge/index.ts +30 -0
- package/src/client/AGENTS.md +32 -0
- package/src/client/FlowActivityBadge.tsx +41 -11
- package/src/client/FlowAgentCard.tsx +321 -61
- package/src/client/FlowAgentDetail.tsx +103 -154
- package/src/client/FlowAgentsToolRenderer.tsx +228 -0
- package/src/client/FlowAuthorPromptDialog.tsx +92 -0
- package/src/client/FlowDashboard.tsx +271 -43
- package/src/client/FlowGraph.tsx +425 -276
- package/src/client/FlowInputWiring.tsx +243 -0
- package/src/client/FlowLaunchDialog.tsx +52 -52
- package/src/client/FlowQuestionCard.tsx +216 -0
- package/src/client/FlowQuestionTranscriptPill.tsx +58 -0
- package/src/client/FlowSummary.tsx +285 -80
- package/src/client/FlowWriteToolRenderer.tsx +127 -0
- package/src/client/FlowYamlPopoverButton.tsx +110 -0
- package/src/client/FlowYamlPreview.tsx +67 -0
- package/src/client/FlowsCommandRoutes.tsx +237 -0
- package/src/client/FlowsSessionStateContext.tsx +142 -0
- package/src/client/FlowsSettings.tsx +68 -0
- package/src/client/FlowsUiStateContext.tsx +169 -0
- package/src/client/SessionFlowActions.tsx +172 -65
- package/src/client/flow-collapse-storage.ts +79 -0
- package/src/client/flow-edges.ts +173 -0
- package/src/client/flow-yaml-parse.ts +140 -0
- package/src/client/flowsAvailability.ts +44 -0
- package/src/client/index.tsx +95 -13
- package/src/client/shouldRender.ts +38 -0
- package/src/configSchema.json +14 -0
- package/src/flow-reducer.ts +94 -13
- package/src/i18n.ts +90 -0
- package/src/reducer.ts +5 -5
- package/src/server/AGENTS.md +10 -0
- package/src/server/automation-actions.ts +162 -0
- package/src/server/flow-inputs.ts +58 -0
- package/src/server/index.ts +171 -0
- package/src/server/render-actions.ts +88 -0
- package/src/server/state-store.ts +74 -0
- package/src/__tests__/ArchitectInputPrompt.test.tsx +0 -81
- package/src/__tests__/architect-reducer.test.ts +0 -307
- package/src/architect-reducer.ts +0 -386
- package/src/client/FlowArchitect.tsx +0 -622
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 contract-pinned bridge-forward + reducer coverage.
|
|
3
|
+
*
|
|
4
|
+
* The dashboard bridge forwards pi-flows `flow:*` events to the dashboard
|
|
5
|
+
* protocol via `FLOW_EVENT_MAP` (packages/extension/src/flow-event-wiring.ts);
|
|
6
|
+
* the flows-plugin reducer consumes the mapped `flow_*` types. This test PINS
|
|
7
|
+
* the reducer to that map: event types are read from `FLOW_EVENT_MAP` VALUES
|
|
8
|
+
* (never hand-typed literals), so a pi-flows rename that updates the map
|
|
9
|
+
* propagates here, and a reducer that stops handling a core lifecycle event
|
|
10
|
+
* fails loudly.
|
|
11
|
+
*
|
|
12
|
+
* Hermetic by design (design D2): no browser, no network, no runtime
|
|
13
|
+
* dependency on pi-flows. Real-engine event fidelity is covered at L3 (the
|
|
14
|
+
* Docker harness), where pi-flows is genuinely installed.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { DashboardEvent, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
18
|
+
import { describe, expect, it } from "vitest";
|
|
19
|
+
// Relative import into the extension package source: vitest maps the `.js`
|
|
20
|
+
// specifier to the `.ts` source. This is the CONTRACT PIN — the same map the
|
|
21
|
+
// bridge forwards through at runtime.
|
|
22
|
+
import { FLOW_EVENT_MAP } from "../../../extension/src/flow-event-wiring.js";
|
|
23
|
+
import { reduceFlowEvent } from "../reducer.js";
|
|
24
|
+
|
|
25
|
+
function ev(type: string, data: Record<string, unknown>): DashboardEvent {
|
|
26
|
+
return { seq: 1, timestamp: 0, sessionId: "s1", eventType: type, data } as unknown as DashboardEvent;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Event types resolved FROM the map (pin). If pi-flows renames an event and the
|
|
30
|
+
// bridge map updates, these follow automatically.
|
|
31
|
+
const T_STARTED = FLOW_EVENT_MAP["flow:flow-started"];
|
|
32
|
+
const T_AGENT_STARTED = FLOW_EVENT_MAP["flow:agent-started"];
|
|
33
|
+
const T_AGENT_COMPLETE = FLOW_EVENT_MAP["flow:agent-complete"];
|
|
34
|
+
const T_COMPLETE = FLOW_EVENT_MAP["flow:complete"];
|
|
35
|
+
|
|
36
|
+
describe("flow reducer × bridge FLOW_EVENT_MAP contract", () => {
|
|
37
|
+
it("the map exposes the core lifecycle event types", () => {
|
|
38
|
+
expect(T_STARTED).toBe("flow_started");
|
|
39
|
+
expect(T_AGENT_STARTED).toBe("flow_agent_started");
|
|
40
|
+
expect(T_AGENT_COMPLETE).toBe("flow_agent_complete");
|
|
41
|
+
expect(T_COMPLETE).toBe("flow_complete");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("a contract-pinned lifecycle reduces to a terminal flow + agent state", () => {
|
|
45
|
+
let s: FlowState | null = null;
|
|
46
|
+
s = reduceFlowEvent(s, ev(T_STARTED, {
|
|
47
|
+
flowName: "contract",
|
|
48
|
+
task: "t",
|
|
49
|
+
steps: [{ id: "s1", stepType: "agent", agent: "a1", blockedBy: [] }],
|
|
50
|
+
}));
|
|
51
|
+
expect(s?.status).toBe("running");
|
|
52
|
+
s = reduceFlowEvent(s, ev(T_AGENT_STARTED, { agentName: "a1", stepId: "s1" }));
|
|
53
|
+
s = reduceFlowEvent(s, ev(T_AGENT_COMPLETE, {
|
|
54
|
+
agentName: "a1",
|
|
55
|
+
stepId: "s1",
|
|
56
|
+
result: { success: true, status: "complete", tokens: { input: 1, output: 1 } },
|
|
57
|
+
}));
|
|
58
|
+
expect(s?.agents.get("s1")?.status).toBe("complete");
|
|
59
|
+
s = reduceFlowEvent(s, ev(T_COMPLETE, { status: "success" }));
|
|
60
|
+
expect(s?.status).toBe("success");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("the reducer never throws on ANY mapped flow_* value (default passthrough)", () => {
|
|
64
|
+
// Seed a state so post-start cases have something to fold into.
|
|
65
|
+
const seeded = reduceFlowEvent(null, ev(T_STARTED, {
|
|
66
|
+
flowName: "f",
|
|
67
|
+
task: "t",
|
|
68
|
+
steps: [{ id: "s1", stepType: "agent", agent: "a1", blockedBy: [] }],
|
|
69
|
+
}));
|
|
70
|
+
for (const mappedType of Object.values(FLOW_EVENT_MAP)) {
|
|
71
|
+
expect(() => reduceFlowEvent(seeded, ev(mappedType, {}))).not.toThrow();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("a mapped event without a dedicated case leaves state unchanged", () => {
|
|
76
|
+
const seeded = reduceFlowEvent(null, ev(T_STARTED, {
|
|
77
|
+
flowName: "f",
|
|
78
|
+
task: "t",
|
|
79
|
+
steps: [{ id: "s1", stepType: "agent", agent: "a1", blockedBy: [] }],
|
|
80
|
+
}));
|
|
81
|
+
// flow_summary_started is mapped but intentionally has no reducer case.
|
|
82
|
+
const passthrough = FLOW_EVENT_MAP["flow:summary-started"];
|
|
83
|
+
expect(passthrough).toBe("flow_summary_started");
|
|
84
|
+
expect(reduceFlowEvent(seeded, ev(passthrough, {}))).toBe(seeded);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("each core lifecycle event produces an observable mutation (no silent drop)", () => {
|
|
88
|
+
const started = reduceFlowEvent(null, ev(T_STARTED, {
|
|
89
|
+
flowName: "f",
|
|
90
|
+
task: "t",
|
|
91
|
+
steps: [{ id: "s1", stepType: "agent", agent: "a1", blockedBy: [] }],
|
|
92
|
+
}));
|
|
93
|
+
expect(started).not.toBeNull(); // flow_started seeds
|
|
94
|
+
|
|
95
|
+
const agentStarted = reduceFlowEvent(started, ev(T_AGENT_STARTED, { agentName: "a1", stepId: "s1" }));
|
|
96
|
+
expect(agentStarted).not.toBe(started); // new state object
|
|
97
|
+
|
|
98
|
+
const agentComplete = reduceFlowEvent(agentStarted, ev(T_AGENT_COMPLETE, {
|
|
99
|
+
agentName: "a1",
|
|
100
|
+
stepId: "s1",
|
|
101
|
+
result: { success: true, status: "complete" },
|
|
102
|
+
}));
|
|
103
|
+
expect(agentComplete?.agents.get("s1")?.status).toBe("complete");
|
|
104
|
+
|
|
105
|
+
const complete = reduceFlowEvent(agentComplete, ev(T_COMPLETE, { status: "success" }));
|
|
106
|
+
expect(complete?.status).toBe("success");
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed-on-start coverage for the flows-plugin reducer.
|
|
3
|
+
*
|
|
4
|
+
* Regression guard: FlowState is seeded ONLY by the initial `flow_started`
|
|
5
|
+
* event. Every other event returns null when no start was observed, so a
|
|
6
|
+
* client that connects mid-flow (missing the start) renders nothing rather
|
|
7
|
+
* than fabricating state from a progression event. Once seeded, progression
|
|
8
|
+
* events advance status and drive agents to a terminal state.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { DashboardEvent, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
12
|
+
import { describe, expect, it } from "vitest";
|
|
13
|
+
import { reduceFlowEvent } from "../reducer.js";
|
|
14
|
+
|
|
15
|
+
function ev(type: string, data: Record<string, unknown>): DashboardEvent {
|
|
16
|
+
return { seq: 1, timestamp: 0, sessionId: "s1", eventType: type, data } as unknown as DashboardEvent;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function fold(events: Array<[string, Record<string, unknown>]>): FlowState | null {
|
|
20
|
+
let s: FlowState | null = null;
|
|
21
|
+
for (const [t, d] of events) s = reduceFlowEvent(s, ev(t, d));
|
|
22
|
+
return s;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("flow reducer seed-on-start", () => {
|
|
26
|
+
it("returns null for a progression event with no prior start", () => {
|
|
27
|
+
expect(reduceFlowEvent(null, ev("flow_agent_complete", { agentName: "a", stepId: "s1" }))).toBeNull();
|
|
28
|
+
expect(reduceFlowEvent(null, ev("flow_agent_started", { agentName: "a", stepId: "s1" }))).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("seeds state on flow_started and advances through progression", () => {
|
|
32
|
+
const state = fold([
|
|
33
|
+
["flow_started", {
|
|
34
|
+
flowName: "invoice",
|
|
35
|
+
task: "validate",
|
|
36
|
+
steps: [{ id: "s1", stepType: "agent", agent: "extractor", blockedBy: [] }],
|
|
37
|
+
}],
|
|
38
|
+
["flow_agent_started", { agentName: "extractor", stepId: "s1" }],
|
|
39
|
+
["flow_agent_complete", { agentName: "extractor", stepId: "s1", status: "complete" }],
|
|
40
|
+
]);
|
|
41
|
+
expect(state).not.toBeNull();
|
|
42
|
+
expect(state?.flowName).toBe("invoice");
|
|
43
|
+
const agent = state?.agents.get("s1");
|
|
44
|
+
expect(agent).toBeDefined();
|
|
45
|
+
expect(["complete", "error", "blocked"]).toContain(agent?.status);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("drops events that arrive before the start even if a later start appears with no prior state", () => {
|
|
49
|
+
// A stray progression event against null stays null; the subsequent start
|
|
50
|
+
// still seeds cleanly (no residue from the dropped event).
|
|
51
|
+
const afterStray = reduceFlowEvent(null, ev("flow_agent_started", { agentName: "x", stepId: "s1" }));
|
|
52
|
+
expect(afterStray).toBeNull();
|
|
53
|
+
const seeded = reduceFlowEvent(afterStray, ev("flow_started", {
|
|
54
|
+
flowName: "f",
|
|
55
|
+
task: "t",
|
|
56
|
+
steps: [{ id: "s1", stepType: "agent", agent: "x", blockedBy: [] }],
|
|
57
|
+
}));
|
|
58
|
+
expect(seeded?.status).toBe("running");
|
|
59
|
+
expect(seeded?.agents.get("s1")?.status).toBe("pending");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { flowToMermaid, parseFlowYaml } from "../client/flow-yaml-parse.js";
|
|
3
|
+
|
|
4
|
+
const YAML = `
|
|
5
|
+
name: invoice-research
|
|
6
|
+
steps:
|
|
7
|
+
- id: extract
|
|
8
|
+
type: agent
|
|
9
|
+
agent: extractor
|
|
10
|
+
blockedBy: []
|
|
11
|
+
on_complete: validate-nav
|
|
12
|
+
- id: validate-nav
|
|
13
|
+
type: code
|
|
14
|
+
blockedBy: [extract]
|
|
15
|
+
on_error: park
|
|
16
|
+
- id: approve
|
|
17
|
+
type: code-decision
|
|
18
|
+
blockedBy: [validate-nav]
|
|
19
|
+
branches:
|
|
20
|
+
auto: export
|
|
21
|
+
rework: extract
|
|
22
|
+
- id: export
|
|
23
|
+
type: agent
|
|
24
|
+
agent: exporter
|
|
25
|
+
blockedBy: [approve]
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
describe("parseFlowYaml", () => {
|
|
29
|
+
it("parses steps + counts", () => {
|
|
30
|
+
const flow = parseFlowYaml(YAML)!;
|
|
31
|
+
expect(flow.name).toBe("invoice-research");
|
|
32
|
+
expect(flow.counts.total).toBe(4);
|
|
33
|
+
expect(flow.counts.agents).toBe(2); // extract, export
|
|
34
|
+
expect(flow.counts.code).toBe(2); // validate-nav, approve
|
|
35
|
+
expect(flow.steps.find((s) => s.id === "approve")?.branches).toEqual({ auto: "export", rework: "extract" });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("returns null on invalid YAML / no steps", () => {
|
|
39
|
+
expect(parseFlowYaml(":::not yaml:::")).toBeNull();
|
|
40
|
+
expect(parseFlowYaml("name: x")).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("defaults missing type to agent", () => {
|
|
44
|
+
const flow = parseFlowYaml("steps:\n - id: a\n blockedBy: []")!;
|
|
45
|
+
expect(flow.steps[0].type).toBe("agent");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("flowToMermaid", () => {
|
|
50
|
+
it("emits graph LR with node shapes + forward and backward edges", () => {
|
|
51
|
+
const flow = parseFlowYaml(YAML)!;
|
|
52
|
+
const m = flowToMermaid(flow);
|
|
53
|
+
expect(m.startsWith("graph LR")).toBe(true);
|
|
54
|
+
expect(m).toContain('validate-nav[["⌗ validate-nav"]]'); // code shape
|
|
55
|
+
expect(m).toContain('approve{"◈ approve"}'); // code-decision shape
|
|
56
|
+
expect(m).toContain("approve -->|auto| export"); // forward branch
|
|
57
|
+
expect(m).toContain('approve -. "rework ↺" .-> extract'); // backward branch (loop)
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("renders on_complete routing edges UNLABELED (happy-path default)", () => {
|
|
61
|
+
// Policy (change: fix-flow-ui-graph-zoom-summary): an `on_complete` route is
|
|
62
|
+
// the happy path — render as a plain arrow, never `|on_complete|`, so an
|
|
63
|
+
// on_complete-wired flow's spine isn't labelled on every edge.
|
|
64
|
+
const flow = parseFlowYaml(YAML)!;
|
|
65
|
+
const m = flowToMermaid(flow);
|
|
66
|
+
// extract.on_complete=validate-nav AND validate-nav.blockedBy=[extract] -> one route edge, unlabeled
|
|
67
|
+
expect(m).toContain("extract --> validate-nav");
|
|
68
|
+
expect(m).not.toContain("extract -->|on_complete| validate-nav");
|
|
69
|
+
expect(m).not.toContain("|on_complete|");
|
|
70
|
+
// on_error -> park, but no `park` step exists -> edge skipped
|
|
71
|
+
expect(m).not.toContain("park");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("renders on_error routes topology-distinctly (returning ↺ vs terminal ⊗)", () => {
|
|
75
|
+
const flow = parseFlowYaml(`
|
|
76
|
+
name: topo
|
|
77
|
+
steps:
|
|
78
|
+
- id: validate
|
|
79
|
+
type: code-decision
|
|
80
|
+
blockedBy: []
|
|
81
|
+
on_error: fixup
|
|
82
|
+
- id: transform
|
|
83
|
+
type: agent
|
|
84
|
+
blockedBy: [validate]
|
|
85
|
+
- id: fixup
|
|
86
|
+
type: agent
|
|
87
|
+
blockedBy: []
|
|
88
|
+
on_complete: validate
|
|
89
|
+
- id: finalize
|
|
90
|
+
type: agent
|
|
91
|
+
blockedBy: [transform]
|
|
92
|
+
on_error: notify
|
|
93
|
+
- id: notify
|
|
94
|
+
type: agent
|
|
95
|
+
blockedBy: []
|
|
96
|
+
`)!;
|
|
97
|
+
const m = flowToMermaid(flow);
|
|
98
|
+
// returning handler (fixup rejoins validate) → dashed loop marker
|
|
99
|
+
expect(m).toContain('validate -. "on_error ↺" .-> fixup');
|
|
100
|
+
// terminal handler (notify is a sink) → dashed terminal marker
|
|
101
|
+
expect(m).toContain('finalize -. "on_error ⊗" .-> notify');
|
|
102
|
+
// an on_error route is never rendered as a solid labeled forward edge
|
|
103
|
+
expect(m).not.toContain("-->|on_error|");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("renders implicit-segment edges and emits no flow-ref shape", () => {
|
|
107
|
+
const flow = parseFlowYaml(`
|
|
108
|
+
name: seg
|
|
109
|
+
steps:
|
|
110
|
+
- id: decide
|
|
111
|
+
type: fork
|
|
112
|
+
branches: { go: end }
|
|
113
|
+
- id: orphan
|
|
114
|
+
type: agent
|
|
115
|
+
- id: end
|
|
116
|
+
type: agent
|
|
117
|
+
`)!;
|
|
118
|
+
const m = flowToMermaid(flow);
|
|
119
|
+
// `orphan` has no blockedBy and no incoming edge -> implicit edge from the
|
|
120
|
+
// preceding separator `decide`.
|
|
121
|
+
expect(m).toContain("decide --> orphan");
|
|
122
|
+
expect(m).not.toContain("[[\"orphan");
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* makeFlowsForCwd: resolves a folder cwd to the live per-session flows list
|
|
3
|
+
* (stateStore, populated by the forwarded flows_list). Reflects package/event
|
|
4
|
+
* flows a static disk scan would miss; empty with no matching running session.
|
|
5
|
+
* See change: fix-automation-flow-detection.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, it } from "vitest";
|
|
9
|
+
import { makeFlowsForCwd } from "../server/index.js";
|
|
10
|
+
|
|
11
|
+
function store(byId: Record<string, string[]>) {
|
|
12
|
+
return {
|
|
13
|
+
getState(id: string) {
|
|
14
|
+
const names = byId[id];
|
|
15
|
+
return names ? { flows: names.map((name) => ({ name })) } : undefined;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("makeFlowsForCwd", () => {
|
|
21
|
+
it("returns the running session's flows for a matching cwd (package/event flows included)", () => {
|
|
22
|
+
const sm = { listActive: () => [{ id: "s1", cwd: "/w/invoice-bot" }] };
|
|
23
|
+
const resolve = makeFlowsForCwd(sm, store({ s1: ["invoicebot:pull", "invoicebot:process"] }));
|
|
24
|
+
expect(resolve("/w/invoice-bot")).toEqual(["invoicebot:process", "invoicebot:pull"]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("returns [] when no active session matches the cwd", () => {
|
|
28
|
+
const sm = { listActive: () => [{ id: "s1", cwd: "/w/other" }] };
|
|
29
|
+
const resolve = makeFlowsForCwd(sm, store({ s1: ["a:b"] }));
|
|
30
|
+
expect(resolve("/w/invoice-bot")).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("unions + de-dupes + sorts across multiple sessions in the same cwd", () => {
|
|
34
|
+
const sm = {
|
|
35
|
+
listActive: () => [
|
|
36
|
+
{ id: "s1", cwd: "/w/x" },
|
|
37
|
+
{ id: "s2", cwd: "/w/x" },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
const resolve = makeFlowsForCwd(sm, store({ s1: ["ns:b", "ns:a"], s2: ["ns:a", "ns:c"] }));
|
|
41
|
+
expect(resolve("/w/x")).toEqual(["ns:a", "ns:b", "ns:c"]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("tolerates malformed session entries and missing state", () => {
|
|
45
|
+
const sm = {
|
|
46
|
+
listActive: () => [null, { cwd: "/w/x" }, { id: 7, cwd: "/w/x" }, { id: "s1", cwd: "/w/x" }],
|
|
47
|
+
};
|
|
48
|
+
const resolve = makeFlowsForCwd(sm, store({})); // s1 has no state
|
|
49
|
+
expect(resolve("/w/x")).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for `shouldRenderFlowsSubcard`, the manifest-level visibility gate
|
|
3
|
+
* for the `session-card-flows` claim. The gate reads live per-session-data
|
|
4
|
+
* (`flowsList`) + plugin config (`editFlow`) + flow events — the same sources
|
|
5
|
+
* `SessionFlowActionsClaim` uses to decide it renders content. See change:
|
|
6
|
+
* fix-empty-flows-subcard.
|
|
7
|
+
*/
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
9
|
+
import {
|
|
10
|
+
__resetSessionDataStoreForTests,
|
|
11
|
+
clearSessionEvents,
|
|
12
|
+
publishSessionData,
|
|
13
|
+
publishSessionEvent,
|
|
14
|
+
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
15
|
+
import { initPluginConfigs } from "@blackbelt-technology/dashboard-plugin-runtime/context";
|
|
16
|
+
import { __resetFlowsAvailabilityForTests, sessionHasFlowEvents } from "../client/flowsAvailability.js";
|
|
17
|
+
import { shouldRenderFlowsSubcard } from "../client/shouldRender.js";
|
|
18
|
+
|
|
19
|
+
const session = (id: string) => ({ id }) as never;
|
|
20
|
+
const setEditMode = (on: boolean) => initPluginConfigs({ flows: { editFlow: on } });
|
|
21
|
+
|
|
22
|
+
describe("flows-plugin: shouldRenderFlowsSubcard predicate", () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
__resetFlowsAvailabilityForTests();
|
|
25
|
+
__resetSessionDataStoreForTests();
|
|
26
|
+
setEditMode(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
__resetFlowsAvailabilityForTests();
|
|
31
|
+
__resetSessionDataStoreForTests();
|
|
32
|
+
setEditMode(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("returns false for null/undefined session", () => {
|
|
36
|
+
expect(shouldRenderFlowsSubcard(null)).toBe(false);
|
|
37
|
+
expect(shouldRenderFlowsSubcard(undefined)).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("hidden in the bug state: flowsList empty + edit mode off + no flow events", () => {
|
|
41
|
+
const sid = "bug-state";
|
|
42
|
+
publishSessionData(sid, "flowsList", []);
|
|
43
|
+
// Extension present (a /flows command exists) must NOT open the gate anymore.
|
|
44
|
+
publishSessionData(sid, "commandsList", [{ name: "flows" }]);
|
|
45
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("visible when flowsList is non-empty", () => {
|
|
49
|
+
const sid = "has-flows";
|
|
50
|
+
publishSessionData(sid, "flowsList", [{ name: "deploy" }]);
|
|
51
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("visible when edit mode is on (author-first, zero flows)", () => {
|
|
55
|
+
const sid = "edit-mode";
|
|
56
|
+
publishSessionData(sid, "flowsList", []);
|
|
57
|
+
setEditMode(true);
|
|
58
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("visible when a flow event exists (running/completed, zero listed flows)", () => {
|
|
62
|
+
const sid = "flow-ran";
|
|
63
|
+
publishSessionData(sid, "flowsList", []);
|
|
64
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(false);
|
|
65
|
+
publishSessionEvent(sid, { eventType: "flow_started", timestamp: 1, data: {} } as never);
|
|
66
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(true);
|
|
67
|
+
clearSessionEvents(sid);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("sessionHasFlowEvents ignores non-flow events, reflects flow events", () => {
|
|
71
|
+
const sid = "flow-evt";
|
|
72
|
+
expect(sessionHasFlowEvents(sid)).toBe(false);
|
|
73
|
+
publishSessionEvent(sid, { eventType: "message_start", timestamp: 1, data: {} } as never);
|
|
74
|
+
expect(sessionHasFlowEvents(sid)).toBe(false);
|
|
75
|
+
publishSessionEvent(sid, { eventType: "flow_started", timestamp: 2, data: {} } as never);
|
|
76
|
+
expect(sessionHasFlowEvents(sid)).toBe(true);
|
|
77
|
+
clearSessionEvents(sid);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-kind / code-node reducer coverage for the rework-flows-plugin-for-new-pi-flows
|
|
3
|
+
* change. Pins: nodeKind decided at started, code target, typed outputs + chosen
|
|
4
|
+
* branch from complete, soft/hard outcome, interrupted downgrade, pre-listed code
|
|
5
|
+
* cards, and replay identity (same fold for live + persisted events).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { DashboardEvent, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
9
|
+
import { describe, expect, it } from "vitest";
|
|
10
|
+
import { reduceFlowEvent } from "../reducer.js";
|
|
11
|
+
|
|
12
|
+
function ev(type: string, data: Record<string, unknown>): DashboardEvent {
|
|
13
|
+
return { seq: 1, timestamp: 0, sessionId: "s1", eventType: type, data } as unknown as DashboardEvent;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Drive a sequence of events through the fold, starting from null. */
|
|
17
|
+
function fold(events: Array<[string, Record<string, unknown>]>): FlowState | null {
|
|
18
|
+
let s: FlowState | null = null;
|
|
19
|
+
for (const [t, d] of events) s = reduceFlowEvent(s, ev(t, d));
|
|
20
|
+
return s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const startedWithCode: Array<[string, Record<string, unknown>]> = [
|
|
24
|
+
["flow_started", {
|
|
25
|
+
flowName: "invoice", task: "validate",
|
|
26
|
+
steps: [
|
|
27
|
+
{ id: "extract", stepType: "agent", agent: "extractor", blockedBy: [] },
|
|
28
|
+
{ id: "validate-nav", stepType: "code", blockedBy: ["extract"] },
|
|
29
|
+
{ id: "approve", stepType: "code-decision", blockedBy: ["validate-nav"] },
|
|
30
|
+
],
|
|
31
|
+
}],
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
describe("node-kind reducer", () => {
|
|
35
|
+
it("pre-lists code and code-decision steps as pending cards (task 2.6)", () => {
|
|
36
|
+
const s = fold(startedWithCode)!;
|
|
37
|
+
expect(s.agents.get("validate-nav")?.nodeKind).toBe("code");
|
|
38
|
+
expect(s.agents.get("validate-nav")?.status).toBe("pending");
|
|
39
|
+
expect(s.agents.get("approve")?.nodeKind).toBe("code-decision");
|
|
40
|
+
expect(s.agents.get("extract")?.nodeKind).toBe("agent");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("decides nodeKind + code target at started; never changes at complete", () => {
|
|
44
|
+
const s = fold([
|
|
45
|
+
...startedWithCode,
|
|
46
|
+
["flow_agent_started", { agentName: "validate-nav", stepId: "validate-nav", nodeKind: "code", target: "handlers/validate-nav.ts" }],
|
|
47
|
+
["flow_assistant_text", { agentName: "validate-nav", stepId: "validate-nav", text: "checking record against NAV" }],
|
|
48
|
+
["flow_agent_complete", { agentName: "validate-nav", stepId: "validate-nav", result: { success: true, summary: "validated against NAV", typedOutputs: { valid: "true", nav_record: "INV-2231" }, outcome: "success" } }],
|
|
49
|
+
])!;
|
|
50
|
+
const code = s.agents.get("validate-nav")!;
|
|
51
|
+
expect(code.nodeKind).toBe("code");
|
|
52
|
+
expect(code.codeTarget).toBe("handlers/validate-nav.ts");
|
|
53
|
+
expect(code.status).toBe("complete");
|
|
54
|
+
expect(code.summary).toBe("validated against NAV");
|
|
55
|
+
expect(code.typedOutputs).toEqual({ valid: "true", nav_record: "INV-2231" });
|
|
56
|
+
// logger output rode the assistant-text channel → detailHistory text entry (logs by card kind)
|
|
57
|
+
expect(code.detailHistory).toContainEqual({ kind: "text", text: "checking record against NAV" });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("exposes the chosen branch from typedOutputs for code-decision", () => {
|
|
61
|
+
const s = fold([
|
|
62
|
+
...startedWithCode,
|
|
63
|
+
["flow_agent_started", { agentName: "approve", stepId: "approve", nodeKind: "code-decision" }],
|
|
64
|
+
["flow_agent_complete", { agentName: "approve", stepId: "approve", result: { success: true, typedOutputs: { branch: "rework", score: "72" }, outcome: "success" } }],
|
|
65
|
+
["flow_loop_iteration", { loopTarget: "approve", iteration: 2, maxIterations: 3 }],
|
|
66
|
+
])!;
|
|
67
|
+
const dec = s.agents.get("approve")!;
|
|
68
|
+
expect(dec.branch).toBe("rework");
|
|
69
|
+
expect(dec.loopIteration).toBe(2);
|
|
70
|
+
expect(dec.loopMax).toBe(3);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("records soft outcome on a routed failure", () => {
|
|
74
|
+
const s = fold([
|
|
75
|
+
...startedWithCode,
|
|
76
|
+
["flow_agent_started", { agentName: "validate-nav", stepId: "validate-nav", nodeKind: "code" }],
|
|
77
|
+
["flow_agent_complete", { agentName: "validate-nav", stepId: "validate-nav", result: { success: false, outcome: "soft" } }],
|
|
78
|
+
])!;
|
|
79
|
+
expect(s.agents.get("validate-nav")?.outcome).toBe("soft");
|
|
80
|
+
expect(s.agents.get("validate-nav")?.status).toBe("error");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("downgrades in-flight cards to error on a non-success terminal (task 3.6)", () => {
|
|
84
|
+
const s = fold([
|
|
85
|
+
...startedWithCode,
|
|
86
|
+
["flow_agent_started", { agentName: "validate-nav", stepId: "validate-nav", nodeKind: "code" }],
|
|
87
|
+
["flow_complete", { status: "interrupted" }],
|
|
88
|
+
])!;
|
|
89
|
+
expect(s.status).toBe("interrupted");
|
|
90
|
+
// started-but-never-completed code card must not spin forever
|
|
91
|
+
expect(s.agents.get("validate-nav")?.status).toBe("error");
|
|
92
|
+
expect(s.agents.get("validate-nav")?.outcome).toBe("hard");
|
|
93
|
+
// pending sibling also resolved
|
|
94
|
+
expect(s.agents.get("approve")?.status).toBe("error");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("falls back to an agent card when nodeKind is absent (pre-contract / skew)", () => {
|
|
98
|
+
const s = fold([
|
|
99
|
+
["flow_started", { flowName: "f", task: "t", steps: [{ id: "a", stepType: "agent", agent: "a", blockedBy: [] }] }],
|
|
100
|
+
["flow_agent_started", { agentName: "a", stepId: "a" }], // no nodeKind
|
|
101
|
+
])!;
|
|
102
|
+
expect(s.agents.get("a")?.nodeKind).toBe("agent");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("lands on_complete / on_error onto dagSteps; absent fields stay undefined", () => {
|
|
106
|
+
// See change: fix-flow-ui-graph-zoom-summary — routing fields drive live route edges.
|
|
107
|
+
const s = fold([
|
|
108
|
+
["flow_started", {
|
|
109
|
+
flowName: "invoice", task: "t",
|
|
110
|
+
steps: [
|
|
111
|
+
{ id: "load-state", stepType: "code", blockedBy: [], onComplete: "resume-gate", onError: "hold" },
|
|
112
|
+
{ id: "resume-gate", stepType: "code-decision", blockedBy: [], branches: { new: "intake" } },
|
|
113
|
+
],
|
|
114
|
+
}],
|
|
115
|
+
])!;
|
|
116
|
+
const loadState = s.dagSteps?.find(d => d.id === "load-state");
|
|
117
|
+
expect(loadState?.onComplete).toBe("resume-gate");
|
|
118
|
+
expect(loadState?.onError).toBe("hold");
|
|
119
|
+
const gate = s.dagSteps?.find(d => d.id === "resume-gate");
|
|
120
|
+
expect(gate?.onComplete).toBeUndefined();
|
|
121
|
+
expect(gate?.onError).toBeUndefined();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("replays identically: same fold over persisted events rebuilds the same card", () => {
|
|
125
|
+
const seq: Array<[string, Record<string, unknown>]> = [
|
|
126
|
+
...startedWithCode,
|
|
127
|
+
["flow_agent_started", { agentName: "approve", stepId: "approve", nodeKind: "code-decision" }],
|
|
128
|
+
["flow_agent_complete", { agentName: "approve", stepId: "approve", result: { success: true, typedOutputs: { branch: "rework" }, outcome: "success" } }],
|
|
129
|
+
["flow_loop_iteration", { loopTarget: "approve", iteration: 2, maxIterations: 3 }],
|
|
130
|
+
];
|
|
131
|
+
const live = fold(seq)!;
|
|
132
|
+
const replay = fold(seq)!; // replay re-forwards the identical records
|
|
133
|
+
expect(replay.agents.get("approve")).toEqual(live.agents.get("approve"));
|
|
134
|
+
});
|
|
135
|
+
});
|