@blackbelt-technology/pi-dashboard-client-utils 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/package.json +37 -4
- package/src/ActionList.tsx +9 -12
- package/src/Dialog.tsx +59 -23
- package/src/LayerPortal.tsx +61 -0
- package/src/SearchableSelectDialog.tsx +94 -31
- package/src/StatusPill.tsx +10 -8
- package/src/ZoomControls.tsx +6 -3
- package/src/agent-card-utils.ts +10 -3
- package/src/identity/dpop.ts +75 -0
- package/src/identity/login-flow.ts +197 -0
- package/src/identity/oidc-flow.ts +96 -0
- package/src/identity/pkce.ts +129 -0
- package/src/identity/token-store.ts +66 -0
- package/src/mdi-by-key.ts +90 -0
- package/src/useFocusTrap.ts +55 -1
- package/src/useZoomPan.ts +33 -13
- package/src/AGENTS.md +0 -25
- package/src/__tests__/ActionList.test.tsx +0 -72
- package/src/__tests__/Confirm.test.tsx +0 -105
- package/src/__tests__/Dialog.test.tsx +0 -215
- package/src/__tests__/DialogPortal.test.tsx +0 -58
- package/src/__tests__/EmptyState.test.tsx +0 -44
- package/src/__tests__/Skeleton.test.tsx +0 -51
- package/src/__tests__/StatusPill.test.tsx +0 -63
- package/src/__tests__/escape-stack.test.ts +0 -166
- package/src/__tests__/statusPresentation.test.ts +0 -34
- package/src/__tests__/useFocusTrap.test.tsx +0 -68
- package/src/__tests__/useMobile.test.tsx +0 -92
- package/src/__tests__/useZoomPan.test.ts +0 -128
- package/src/extension-ui/AGENTS.md +0 -10
- package/src/minimal-chat/AGENTS.md +0 -9
- package/src/minimal-chat/__tests__/MinimalChatView.test.tsx +0 -235
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MinimalChatView unit tests.
|
|
3
|
-
*
|
|
4
|
-
* Tests use `withUiPrimitiveProvider` to mock `MarkdownContent`,
|
|
5
|
-
* `formatTokens`, `formatDuration`. Rendering without the provider must
|
|
6
|
-
* throw a hook-resolution error (covered by the negative case below).
|
|
7
|
-
*
|
|
8
|
-
* See change: extract-minimal-chat-view.
|
|
9
|
-
*/
|
|
10
|
-
import React from "react";
|
|
11
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
12
|
-
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
13
|
-
import { withUiPrimitiveProvider } from "@blackbelt-technology/dashboard-plugin-runtime/test-support";
|
|
14
|
-
import { MinimalChatView } from "../MinimalChatView.js";
|
|
15
|
-
import type { MinimalChatEntry, MinimalChatStatus } from "../types.js";
|
|
16
|
-
|
|
17
|
-
const MockMarkdown: React.FC<{ content: string }> = ({ content }) => (
|
|
18
|
-
<div data-testid="md">{content}</div>
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const mockFormatTokens = (n: number) => {
|
|
22
|
-
if (n >= 1000) return `${Math.round(n / 100) / 10}k`;
|
|
23
|
-
return String(n);
|
|
24
|
-
};
|
|
25
|
-
const mockFormatDuration = (ms: number) => `${(ms / 1000).toFixed(1)}s`;
|
|
26
|
-
|
|
27
|
-
function renderView(ui: React.ReactElement) {
|
|
28
|
-
return render(
|
|
29
|
-
withUiPrimitiveProvider(
|
|
30
|
-
{
|
|
31
|
-
"ui:markdown-content": MockMarkdown,
|
|
32
|
-
"ui:format-tokens": mockFormatTokens,
|
|
33
|
-
"ui:format-duration": mockFormatDuration,
|
|
34
|
-
},
|
|
35
|
-
ui,
|
|
36
|
-
),
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
describe("MinimalChatView", () => {
|
|
41
|
-
afterEach(() => cleanup());
|
|
42
|
-
|
|
43
|
-
it("renders each of the four entry kinds in order", () => {
|
|
44
|
-
const entries: MinimalChatEntry[] = [
|
|
45
|
-
{ kind: "tool", toolName: "Read", input: { file_path: "/foo.ts" } },
|
|
46
|
-
{ kind: "text", text: "Hello world" },
|
|
47
|
-
{ kind: "thinking", text: "I should look here" },
|
|
48
|
-
{ kind: "error", text: "Boom" },
|
|
49
|
-
];
|
|
50
|
-
renderView(
|
|
51
|
-
<MinimalChatView title="alpha" status="running" entries={entries} />,
|
|
52
|
-
);
|
|
53
|
-
expect(screen.getByText("Read")).toBeTruthy();
|
|
54
|
-
expect(screen.getByText("/foo.ts")).toBeTruthy();
|
|
55
|
-
expect(screen.getByText(/Hello world/)).toBeTruthy();
|
|
56
|
-
expect(screen.getByText("Thinking")).toBeTruthy();
|
|
57
|
-
expect(screen.getByText("Boom")).toBeTruthy();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("status enum maps to expected icon + color (5 values)", () => {
|
|
61
|
-
const cases: Array<{ status: MinimalChatStatus; color: string }> = [
|
|
62
|
-
{ status: "complete", color: "text-green-400" },
|
|
63
|
-
{ status: "error", color: "text-red-400" },
|
|
64
|
-
{ status: "running", color: "text-yellow-400" },
|
|
65
|
-
{ status: "blocked", color: "text-orange-400" },
|
|
66
|
-
{ status: "pending", color: "text-[var(--text-tertiary)]" },
|
|
67
|
-
];
|
|
68
|
-
for (const { status, color } of cases) {
|
|
69
|
-
cleanup();
|
|
70
|
-
const { container } = renderView(
|
|
71
|
-
<MinimalChatView title="t" status={status} entries={[]} />,
|
|
72
|
-
);
|
|
73
|
-
// Walk all spans, find one whose classList contains both the color
|
|
74
|
-
// and `inline-flex`. Avoids CSS.escape (not available in jsdom env).
|
|
75
|
-
const spans = Array.from(container.querySelectorAll<HTMLElement>("span"));
|
|
76
|
-
const span = spans.find(
|
|
77
|
-
(s) => s.classList.contains(color) && s.classList.contains("inline-flex"),
|
|
78
|
-
);
|
|
79
|
-
expect(span, `expected color span for status=${status}`).toBeTruthy();
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("three modes apply expected root container classes", () => {
|
|
84
|
-
{
|
|
85
|
-
const { container } = renderView(
|
|
86
|
-
<MinimalChatView title="a" status="running" entries={[]} mode="popout" />,
|
|
87
|
-
);
|
|
88
|
-
const root = container.firstElementChild as HTMLElement;
|
|
89
|
-
expect(root.className).toContain("h-full");
|
|
90
|
-
expect(root.className).toContain("overflow-hidden");
|
|
91
|
-
}
|
|
92
|
-
cleanup();
|
|
93
|
-
{
|
|
94
|
-
const { container } = renderView(
|
|
95
|
-
<MinimalChatView title="a" status="running" entries={[]} mode="inline" />,
|
|
96
|
-
);
|
|
97
|
-
const root = container.firstElementChild as HTMLElement;
|
|
98
|
-
// Inline mode now uses a STABLE `h-[60vh]` (not `max-h-[60vh]`) so the
|
|
99
|
-
// container doesn't bounce as content streams in. The body's
|
|
100
|
-
// `flex-1 min-h-0 overflow-y-auto` provides the scroll surface.
|
|
101
|
-
// See change: fix-flows-plugin-polish (stable inline height).
|
|
102
|
-
expect(root.className).toContain("h-[60vh]");
|
|
103
|
-
expect(root.className).not.toContain("max-h-[60vh]");
|
|
104
|
-
}
|
|
105
|
-
cleanup();
|
|
106
|
-
{
|
|
107
|
-
const { container } = renderView(
|
|
108
|
-
<MinimalChatView title="a" status="running" entries={[{ kind: "text", text: "body" }]} mode="row" activity="reading" />,
|
|
109
|
-
);
|
|
110
|
-
// Row mode: no body, only single line
|
|
111
|
-
expect(screen.queryByTestId("md")).toBeNull();
|
|
112
|
-
expect(screen.getByText("a")).toBeTruthy();
|
|
113
|
-
expect(screen.getByText("reading")).toBeTruthy();
|
|
114
|
-
// Root has no flex-col h-full
|
|
115
|
-
const root = container.firstElementChild as HTMLElement;
|
|
116
|
-
expect(root.className).not.toContain("h-full");
|
|
117
|
-
expect(root.className).not.toContain("h-[60vh]");
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("hides meta when prop is omitted", () => {
|
|
122
|
-
renderView(<MinimalChatView title="hdr" status="complete" entries={[]} />);
|
|
123
|
-
expect(screen.queryByText(/↑/)).toBeNull();
|
|
124
|
-
expect(screen.queryByText(/↓/)).toBeNull();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("renders ↑/↓ tokens and formatted duration when meta supplied", () => {
|
|
128
|
-
renderView(
|
|
129
|
-
<MinimalChatView
|
|
130
|
-
title="hdr"
|
|
131
|
-
status="complete"
|
|
132
|
-
entries={[]}
|
|
133
|
-
meta={{ tokens: { input: 1234, output: 567 }, durationMs: 4500 }}
|
|
134
|
-
/>,
|
|
135
|
-
);
|
|
136
|
-
expect(screen.getByText(/↑1\.2k/)).toBeTruthy();
|
|
137
|
-
expect(screen.getByText(/↓567/)).toBeTruthy();
|
|
138
|
-
expect(screen.getByText(/4\.5s/)).toBeTruthy();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("renders subtitle path under the title in monospace", () => {
|
|
142
|
-
renderView(
|
|
143
|
-
<MinimalChatView
|
|
144
|
-
title="explorer"
|
|
145
|
-
subtitle="~/.pi/agent/agents/Explore.md"
|
|
146
|
-
status="complete"
|
|
147
|
-
entries={[]}
|
|
148
|
-
/>,
|
|
149
|
-
);
|
|
150
|
-
const sub = screen.getByText("~/.pi/agent/agents/Explore.md");
|
|
151
|
-
expect(sub).toBeTruthy();
|
|
152
|
-
expect(sub.className).toContain("font-mono");
|
|
153
|
-
expect(sub.getAttribute("title")).toBe("~/.pi/agent/agents/Explore.md");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("tool entry without output shows no expand toggle", () => {
|
|
157
|
-
renderView(
|
|
158
|
-
<MinimalChatView
|
|
159
|
-
title="t"
|
|
160
|
-
status="running"
|
|
161
|
-
entries={[{ kind: "tool", toolName: "Read", input: { file_path: "foo.ts" } }]}
|
|
162
|
-
/>,
|
|
163
|
-
);
|
|
164
|
-
expect(screen.queryByText("▸")).toBeNull();
|
|
165
|
-
expect(screen.queryByText("▾")).toBeNull();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("tool entry with output toggles open on click", () => {
|
|
169
|
-
renderView(
|
|
170
|
-
<MinimalChatView
|
|
171
|
-
title="t"
|
|
172
|
-
status="running"
|
|
173
|
-
entries={[{ kind: "tool", toolName: "Bash", input: { command: "ls" }, output: "abc-output" }]}
|
|
174
|
-
/>,
|
|
175
|
-
);
|
|
176
|
-
const toggle = screen.getByText("▸");
|
|
177
|
-
expect(screen.queryByText("abc-output")).toBeNull();
|
|
178
|
-
fireEvent.click(toggle);
|
|
179
|
-
expect(screen.getByText("▾")).toBeTruthy();
|
|
180
|
-
expect(screen.getByText("abc-output")).toBeTruthy();
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("tool entry with isError paints row border and name red", () => {
|
|
184
|
-
const { container } = renderView(
|
|
185
|
-
<MinimalChatView
|
|
186
|
-
title="t"
|
|
187
|
-
status="error"
|
|
188
|
-
entries={[{ kind: "tool", toolName: "Bash", input: {}, isError: true }]}
|
|
189
|
-
/>,
|
|
190
|
-
);
|
|
191
|
-
// Border red on row container
|
|
192
|
-
const row = container.querySelector("div.border-l-2");
|
|
193
|
-
expect(row?.className).toContain("border-red-500/50");
|
|
194
|
-
// Name red
|
|
195
|
-
const name = screen.getByText("Bash");
|
|
196
|
-
expect(name.className).toContain("text-red-400");
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("renders the supplied empty-state message when entries is empty", () => {
|
|
200
|
-
renderView(
|
|
201
|
-
<MinimalChatView
|
|
202
|
-
title="t"
|
|
203
|
-
status="pending"
|
|
204
|
-
entries={[]}
|
|
205
|
-
emptyMessage="Waiting to start..."
|
|
206
|
-
/>,
|
|
207
|
-
);
|
|
208
|
-
expect(screen.getByText(/Waiting to start/)).toBeTruthy();
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("renders footer node below entries", () => {
|
|
212
|
-
renderView(
|
|
213
|
-
<MinimalChatView
|
|
214
|
-
title="t"
|
|
215
|
-
status="complete"
|
|
216
|
-
entries={[]}
|
|
217
|
-
footer={<div data-testid="footer">FOOTER</div>}
|
|
218
|
-
/>,
|
|
219
|
-
);
|
|
220
|
-
expect(screen.getByTestId("footer")).toBeTruthy();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("throws when rendered without the UiPrimitiveProvider (negative case)", () => {
|
|
224
|
-
// Suppress console.error noise from the rendered error
|
|
225
|
-
const orig = console.error;
|
|
226
|
-
console.error = () => {};
|
|
227
|
-
try {
|
|
228
|
-
expect(() =>
|
|
229
|
-
render(<MinimalChatView title="t" status="running" entries={[]} />),
|
|
230
|
-
).toThrow();
|
|
231
|
-
} finally {
|
|
232
|
-
console.error = orig;
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
});
|