@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,281 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { nextTick, ref } from "vue";
3
- import {
4
- type AssistantStatusPayload,
5
- createAssistantActivity,
6
- } from "../app/runtime/assistant-activity";
7
- import type { ChannelStatus } from "../app/runtime/channel-client";
8
- import type { ChatTransport } from "../app/runtime/chat-transport";
9
-
10
- type Listener = (msg: object) => void;
11
- type StatusListener = (status: ChannelStatus) => void;
12
-
13
- function fakeChat(initial: ChannelStatus = "connected") {
14
- const listeners = new Set<Listener>();
15
- const statusListeners = new Set<StatusListener>();
16
- let status = initial;
17
- const chat = {
18
- onMessage: (listener: Listener) => {
19
- listeners.add(listener);
20
- return () => listeners.delete(listener);
21
- },
22
- onStatus: (listener: StatusListener) => {
23
- statusListeners.add(listener);
24
- return () => statusListeners.delete(listener);
25
- },
26
- getStatus: () => status,
27
- } as unknown as ChatTransport;
28
- return {
29
- chat,
30
- emit: (msg: object) => listeners.forEach((l) => l(msg)),
31
- announce: (next: ChannelStatus) => {
32
- status = next;
33
- statusListeners.forEach((l) => l(next));
34
- },
35
- };
36
- }
37
-
38
- function activityOver(chat: ChatTransport) {
39
- const data = ref<AssistantStatusPayload | null>(null);
40
- const activity = createAssistantActivity({
41
- readStatus: () => ({ data, refresh: async () => undefined }),
42
- chat,
43
- shouldPoll: () => true,
44
- });
45
- return { data, activity };
46
- }
47
-
48
- function activityOverHeldRefresh(chat: ChatTransport) {
49
- const data = ref<AssistantStatusPayload | null>(null);
50
- const refreshes: { resolve: () => void; reject: (reason: Error) => void }[] =
51
- [];
52
- const activity = createAssistantActivity({
53
- readStatus: () => ({
54
- data,
55
- refresh: () =>
56
- new Promise<void>((resolve, reject) => {
57
- refreshes.push({ resolve, reject });
58
- }),
59
- }),
60
- chat,
61
- shouldPoll: () => true,
62
- });
63
- return { data, activity, refreshes };
64
- }
65
-
66
- function finishTurnThenLoseStream(
67
- emit: (msg: object) => void,
68
- announce: (next: ChannelStatus) => void,
69
- ): void {
70
- emit({ type: "conversation_list", conversations: [{ isRunning: true }] });
71
- emit({ type: "conversation_list", conversations: [{ isRunning: false }] });
72
- announce("disconnected");
73
- }
74
-
75
- describe("assistant activity", () => {
76
- it("polls the status through the read's interval while it is useful, and stops on teardown", async () => {
77
- const data = ref<AssistantStatusPayload | null>(null);
78
- let interval: () => number = () => -1;
79
- const isPanelOpen = ref(false);
80
- const { chat } = fakeChat();
81
- const activity = createAssistantActivity({
82
- readStatus: (given) => {
83
- interval = given;
84
- return { data, refresh: async () => undefined };
85
- },
86
- chat,
87
- shouldPoll: () => !isPanelOpen.value,
88
- });
89
- expect(interval()).toBe(15_000);
90
- isPanelOpen.value = true;
91
- expect(interval()).toBe(0);
92
- isPanelOpen.value = false;
93
- activity.stop();
94
- expect(interval()).toBe(0);
95
- });
96
-
97
- it("takes its counts from each status answer and from the stream's lists, and from the status again once the stream drops", async () => {
98
- const { chat, emit, announce } = fakeChat();
99
- const { data, activity } = activityOver(chat);
100
- data.value = { pendingApprovals: 2, workingConversations: 0 };
101
- await nextTick();
102
- expect(activity.pendingApprovals.value).toBe(2);
103
- expect(activity.isBusy.value).toBe(true);
104
- emit({ type: "conversation_list", conversations: [{ isRunning: true }] });
105
- expect(activity.pendingApprovals.value).toBe(0);
106
- expect(activity.workingConversations.value).toBe(1);
107
- announce("reconnecting");
108
- data.value = {
109
- pendingApprovals: 0,
110
- workingConversations: 0,
111
- lastError: "boom",
112
- };
113
- await nextTick();
114
- expect(activity.workingConversations.value).toBe(0);
115
- expect(activity.lastError.value).toBe("boom");
116
- activity.stop();
117
- });
118
-
119
- it("keeps the stream open while a question waits, from the status and from a list", async () => {
120
- const data = ref<AssistantStatusPayload | null>(null);
121
- const { chat, emit } = fakeChat();
122
- const activity = createAssistantActivity({
123
- readStatus: () => ({ data, refresh: async () => undefined }),
124
- chat,
125
- shouldPoll: () => true,
126
- });
127
- data.value = { pendingQuestions: 1 };
128
- await nextTick();
129
- expect(activity.pendingQuestions.value).toBe(1);
130
- expect(activity.pendingApprovals.value).toBe(0);
131
- expect(activity.isBusy.value).toBe(true);
132
- emit({ type: "conversation_list", conversations: [{}] });
133
- expect(activity.pendingQuestions.value).toBe(0);
134
- expect(activity.isBusy.value).toBe(false);
135
- emit({
136
- type: "conversation_list",
137
- conversations: [{ pendingQuestions: 1 }, { pendingQuestions: 2 }],
138
- });
139
- expect(activity.pendingQuestions.value).toBe(3);
140
- expect(activity.pendingApprovals.value).toBe(0);
141
- expect(activity.isBusy.value).toBe(true);
142
- activity.stop();
143
- });
144
-
145
- it("keeps a finished turn when a status answer from before the turn ended lands after the list (fails if the poll rewinds the list's counts)", async () => {
146
- const { chat, emit } = fakeChat();
147
- const { data, activity } = activityOver(chat);
148
- emit({ type: "conversation_list", conversations: [{ isRunning: true }] });
149
- emit({ type: "conversation_list", conversations: [{ isRunning: false }] });
150
- data.value = { workingConversations: 1, lastError: "late" };
151
- await nextTick();
152
- expect(activity.workingConversations.value).toBe(0);
153
- expect(activity.isBusy.value).toBe(false);
154
- expect(activity.lastError.value).toBe("late");
155
- activity.stop();
156
- });
157
-
158
- it("keeps a running turn when a stale status answer says all is idle (fails if the poll overwrites the list's counts)", async () => {
159
- const { chat, emit } = fakeChat();
160
- const { data, activity } = activityOver(chat);
161
- emit({
162
- type: "conversation_list",
163
- conversations: [{ isRunning: true, pendingQuestions: 1 }],
164
- });
165
- data.value = { workingConversations: 0, pendingQuestions: 0 };
166
- await nextTick();
167
- expect(activity.workingConversations.value).toBe(1);
168
- expect(activity.pendingQuestions.value).toBe(1);
169
- activity.stop();
170
- });
171
-
172
- it("takes the counts from the status while a connected stream has sent no list (fails if a bare connection silences the poll)", async () => {
173
- const { chat, emit, announce } = fakeChat();
174
- const { data, activity } = activityOver(chat);
175
- data.value = { workingConversations: 1 };
176
- await nextTick();
177
- expect(activity.workingConversations.value).toBe(1);
178
- emit({ type: "conversation_list", conversations: [] });
179
- announce("reconnecting");
180
- announce("connected");
181
- data.value = { workingConversations: 2 };
182
- await nextTick();
183
- expect(activity.workingConversations.value).toBe(2);
184
- activity.stop();
185
- });
186
-
187
- it("keeps a finished turn when a status answer sent during the turn lands after the stream let go (fails if the release reopens the counts to any answer)", async () => {
188
- const { chat, emit, announce } = fakeChat();
189
- const { data, activity } = activityOverHeldRefresh(chat);
190
- finishTurnThenLoseStream(emit, announce);
191
- data.value = { workingConversations: 1 };
192
- await nextTick();
193
- expect(activity.workingConversations.value).toBe(0);
194
- expect(activity.isBusy.value).toBe(false);
195
- activity.stop();
196
- });
197
-
198
- it("reads the status again when the lists let go (fails if the release leaves the stale answer in flight)", async () => {
199
- const { chat, emit, announce } = fakeChat();
200
- const { activity, refreshes } = activityOverHeldRefresh(chat);
201
- emit({ type: "conversation_list", conversations: [] });
202
- announce("reconnecting");
203
- announce("disconnected");
204
- expect(refreshes).toHaveLength(1);
205
- activity.stop();
206
- });
207
-
208
- it("takes the counts of the fresh read once it answers (fails if the counts stay shut after a release)", async () => {
209
- const { chat, emit, announce } = fakeChat();
210
- const { data, activity, refreshes } = activityOverHeldRefresh(chat);
211
- finishTurnThenLoseStream(emit, announce);
212
- data.value = { workingConversations: 1 };
213
- await nextTick();
214
- data.value = { pendingApprovals: 2, lastError: "fresh" };
215
- refreshes[0]?.resolve();
216
- await nextTick();
217
- expect(activity.pendingApprovals.value).toBe(2);
218
- expect(activity.workingConversations.value).toBe(0);
219
- expect(activity.lastError.value).toBe("fresh");
220
- data.value = { workingConversations: 1 };
221
- await nextTick();
222
- expect(activity.workingConversations.value).toBe(1);
223
- activity.stop();
224
- });
225
-
226
- it("keeps the counts when the fresh read resolves with no new answer (fails if it applies the answer it replaced)", async () => {
227
- const { chat, emit, announce } = fakeChat();
228
- const { data, activity, refreshes } = activityOverHeldRefresh(chat);
229
- data.value = { workingConversations: 1 };
230
- await nextTick();
231
- finishTurnThenLoseStream(emit, announce);
232
- refreshes[0]?.resolve();
233
- await nextTick();
234
- expect(activity.workingConversations.value).toBe(0);
235
- activity.stop();
236
- });
237
-
238
- it("takes the next answer after a fresh read that fails (fails if a rejected refresh freezes the counts)", async () => {
239
- const { chat, emit, announce } = fakeChat();
240
- const { data, activity, refreshes } = activityOverHeldRefresh(chat);
241
- finishTurnThenLoseStream(emit, announce);
242
- refreshes[0]?.reject(new Error("offline"));
243
- await nextTick();
244
- data.value = { workingConversations: 1 };
245
- await nextTick();
246
- expect(activity.workingConversations.value).toBe(1);
247
- activity.stop();
248
- });
249
-
250
- it("keeps a list's counts when the stream is back before the fresh read lands (fails if the read is applied over a newer list)", async () => {
251
- const { chat, emit, announce } = fakeChat();
252
- const { data, activity, refreshes } = activityOverHeldRefresh(chat);
253
- finishTurnThenLoseStream(emit, announce);
254
- announce("connected");
255
- emit({ type: "conversation_list", conversations: [{ isRunning: true }] });
256
- data.value = { workingConversations: 0 };
257
- refreshes[0]?.resolve();
258
- await nextTick();
259
- expect(activity.workingConversations.value).toBe(1);
260
- activity.stop();
261
- });
262
-
263
- it("takes only the latest release's read (fails if an earlier read's answer lifts the later release's gate)", async () => {
264
- const { chat, emit, announce } = fakeChat();
265
- const { data, activity, refreshes } = activityOverHeldRefresh(chat);
266
- finishTurnThenLoseStream(emit, announce);
267
- announce("connected");
268
- emit({ type: "conversation_list", conversations: [{ isRunning: true }] });
269
- announce("disconnected");
270
- expect(refreshes).toHaveLength(2);
271
- refreshes[0]?.resolve();
272
- await nextTick();
273
- data.value = { workingConversations: 0 };
274
- await nextTick();
275
- expect(activity.workingConversations.value).toBe(1);
276
- refreshes[1]?.resolve();
277
- await nextTick();
278
- expect(activity.workingConversations.value).toBe(0);
279
- activity.stop();
280
- });
281
- });
@@ -1,130 +0,0 @@
1
- import {
2
- mkdirSync,
3
- mkdtempSync,
4
- realpathSync,
5
- rmSync,
6
- symlinkSync,
7
- writeFileSync,
8
- } from "node:fs";
9
- import { tmpdir } from "node:os";
10
- import { join } from "node:path";
11
- import { build, type Plugin } from "vite";
12
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
13
- import { backendBoundary } from "../build/backend-boundary.ts";
14
-
15
- let root: string;
16
-
17
- function write(file: string, text: string): void {
18
- const path = join(root, file);
19
- mkdirSync(join(path, ".."), { recursive: true });
20
- writeFileSync(path, text);
21
- }
22
-
23
- function manifest(directory: string, name: string): void {
24
- write(`${directory}/package.json`, JSON.stringify({ name }));
25
- }
26
-
27
- /** A frontend entry with `source` as its only import, built for real. */
28
- async function buildEntry(source: string, extra: Plugin[] = []): Promise<void> {
29
- write(
30
- "frontend/entry.ts",
31
- `import "${source}";\nexport const frontend = 1;\n`,
32
- );
33
- await build({
34
- root: join(root, "frontend"),
35
- configFile: false,
36
- logLevel: "silent",
37
- plugins: [backendBoundary(), ...extra],
38
- build: {
39
- write: false,
40
- lib: { entry: join(root, "frontend/entry.ts"), formats: ["es"] },
41
- },
42
- });
43
- }
44
-
45
- beforeEach(() => {
46
- root = realpathSync(mkdtempSync(join(tmpdir(), "dms-assistant-boundary-")));
47
- manifest("backend", "@antelopejs/dms-assistant");
48
- write("backend/src/routes/status.ts", "export const status = 1;\n");
49
- write("backend/dist/index.js", "export const built = 1;\n");
50
- write("backend/srcfoo/index.ts", "export const sibling = 1;\n");
51
- manifest("other", "another-package");
52
- write("other/src/index.ts", "export const other = 1;\n");
53
- manifest("frontend", "@antelopejs/dms-assistant-frontend-vue");
54
- });
55
-
56
- afterEach(() => {
57
- rmSync(root, { recursive: true, force: true });
58
- });
59
-
60
- describe("the backend boundary of a real build", () => {
61
- it("fails when the frontend imports a file under the backend's src", async () => {
62
- await expect(buildEntry("../backend/src/routes/status.ts")).rejects.toThrow(
63
- /frontend\/entry\.ts imports .*backend\/src\/routes\/status\.ts/,
64
- );
65
- });
66
-
67
- it("fails when the import carries a query", async () => {
68
- await expect(
69
- buildEntry("../backend/src/routes/status.ts?raw"),
70
- ).rejects.toThrow(/Backend boundary/);
71
- });
72
-
73
- it("follows a symlink a resolver returns to the file it points at", async () => {
74
- symlinkSync(
75
- join(root, "backend/src/routes"),
76
- join(root, "frontend/routes"),
77
- );
78
- const linked: Plugin = {
79
- name: "test:linked",
80
- enforce: "pre",
81
- resolveId: (source) =>
82
- source === "@linked/status"
83
- ? join(root, "frontend/routes/status.ts")
84
- : null,
85
- };
86
- await expect(buildEntry("@linked/status", [linked])).rejects.toThrow(
87
- /backend\/src\/routes\/status\.ts/,
88
- );
89
- });
90
-
91
- it("sees through an alias another plugin resolves", async () => {
92
- const alias: Plugin = {
93
- name: "test:alias",
94
- enforce: "pre",
95
- resolveId: (source) =>
96
- source === "@backend/status"
97
- ? join(root, "backend/src/routes/status.ts")
98
- : null,
99
- };
100
- await expect(buildEntry("@backend/status", [alias])).rejects.toThrow(
101
- /Backend boundary/,
102
- );
103
- });
104
-
105
- it("lets the backend's built output through", async () => {
106
- await expect(
107
- buildEntry("../backend/dist/index.js"),
108
- ).resolves.toBeUndefined();
109
- });
110
-
111
- it("lets a sibling directory whose name starts with src through", async () => {
112
- await expect(
113
- buildEntry("../backend/srcfoo/index.ts"),
114
- ).resolves.toBeUndefined();
115
- });
116
-
117
- it("lets the src of another package through", async () => {
118
- await expect(buildEntry("../other/src/index.ts")).resolves.toBeUndefined();
119
- });
120
-
121
- it("ignores a virtual module", async () => {
122
- const virtual: Plugin = {
123
- name: "test:virtual",
124
- enforce: "pre",
125
- resolveId: (source) => (source === "virtual:ok" ? "\0virtual:ok" : null),
126
- load: (id) => (id === "\0virtual:ok" ? "export const v = 1;" : null),
127
- };
128
- await expect(buildEntry("virtual:ok", [virtual])).resolves.toBeUndefined();
129
- });
130
- });
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { createBackoff, nextDelay, resetBackoff } from "../app/runtime/backoff";
3
- import { CHANNEL_RECONNECT_DELAYS_MS } from "../app/runtime/constants";
4
-
5
- describe("backoff helper", () => {
6
- it("returns each schedule entry in order then caps at the last value", () => {
7
- const state = createBackoff();
8
- const observed: number[] = [];
9
- for (let i = 0; i < CHANNEL_RECONNECT_DELAYS_MS.length + 3; i += 1) {
10
- observed.push(nextDelay(state, CHANNEL_RECONNECT_DELAYS_MS));
11
- }
12
- const expected = [
13
- ...CHANNEL_RECONNECT_DELAYS_MS,
14
- CHANNEL_RECONNECT_DELAYS_MS[CHANNEL_RECONNECT_DELAYS_MS.length - 1],
15
- CHANNEL_RECONNECT_DELAYS_MS[CHANNEL_RECONNECT_DELAYS_MS.length - 1],
16
- CHANNEL_RECONNECT_DELAYS_MS[CHANNEL_RECONNECT_DELAYS_MS.length - 1],
17
- ];
18
- expect(observed).toEqual(expected);
19
- });
20
-
21
- it("resetBackoff returns the schedule to schedule[0]", () => {
22
- const state = createBackoff();
23
- nextDelay(state, CHANNEL_RECONNECT_DELAYS_MS);
24
- nextDelay(state, CHANNEL_RECONNECT_DELAYS_MS);
25
- resetBackoff(state);
26
- expect(nextDelay(state, CHANNEL_RECONNECT_DELAYS_MS)).toBe(
27
- CHANNEL_RECONNECT_DELAYS_MS[0],
28
- );
29
- });
30
-
31
- it("uses the configured 30s ceiling on the last delay", () => {
32
- const state = createBackoff();
33
- const lastIndex = CHANNEL_RECONNECT_DELAYS_MS.length - 1;
34
- for (let i = 0; i < lastIndex; i += 1) {
35
- nextDelay(state, CHANNEL_RECONNECT_DELAYS_MS);
36
- }
37
- expect(nextDelay(state, CHANNEL_RECONNECT_DELAYS_MS)).toBe(30_000);
38
- expect(nextDelay(state, CHANNEL_RECONNECT_DELAYS_MS)).toBe(30_000);
39
- });
40
- });
@@ -1,142 +0,0 @@
1
- // @vitest-environment jsdom
2
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
- import {
4
- BLOCK_SETTLE_BUDGET_MS,
5
- awaitSettledBlocks,
6
- readBlocks,
7
- } from "../app/runtime/block-health";
8
-
9
- function addBlock(
10
- state: string,
11
- type: string,
12
- path?: string,
13
- parent: Element = document.body,
14
- ): HTMLElement {
15
- const element = document.createElement("div");
16
- element.setAttribute("data-dms-block-state", state);
17
- element.setAttribute("data-dms-block-type", type);
18
- if (path !== undefined) element.setAttribute("data-dms-block", path);
19
- parent.append(element);
20
- return element;
21
- }
22
-
23
- const never = new AbortController().signal;
24
-
25
- describe("readBlocks", () => {
26
- beforeEach(() => {
27
- document.body.replaceChildren();
28
- });
29
-
30
- it("reads the state, kind and layout path each block states on its root", () => {
31
- addBlock("empty", "ChartCard", "revenue");
32
- addBlock("ok", "KpiCard");
33
- document.body.append(document.createElement("section"));
34
- expect(readBlocks(document)).toEqual([
35
- { path: "revenue", type: "ChartCard", state: "empty" },
36
- { type: "KpiCard", state: "ok" },
37
- ]);
38
- });
39
-
40
- it("finds none on a host that states nothing", () => {
41
- document.body.append(document.createElement("section"));
42
- expect(readBlocks(document)).toEqual([]);
43
- });
44
- });
45
-
46
- describe("awaitSettledBlocks", () => {
47
- beforeEach(() => {
48
- document.body.replaceChildren();
49
- vi.useFakeTimers();
50
- });
51
-
52
- afterEach(() => {
53
- vi.useRealTimers();
54
- });
55
-
56
- it("reports the blocks showing no data once the page stopped changing", async () => {
57
- addBlock("ok", "KpiCard", "orders");
58
- addBlock("empty", "ChartCard", "revenue");
59
- addBlock("error", "TopListCard", "top");
60
- const settled = awaitSettledBlocks({ root: document, signal: never });
61
- await vi.advanceTimersByTimeAsync(BLOCK_SETTLE_BUDGET_MS);
62
- await expect(settled).resolves.toEqual({
63
- status: "settled",
64
- checked: 3,
65
- blocks: [
66
- { path: "revenue", type: "ChartCard", state: "empty" },
67
- { path: "top", type: "TopListCard", state: "error" },
68
- ],
69
- });
70
- });
71
-
72
- it("waits for a loading block and reports what it turned into", async () => {
73
- const chart = addBlock("loading", "ChartCard", "revenue");
74
- let result: Awaited<ReturnType<typeof awaitSettledBlocks>> | undefined;
75
- void awaitSettledBlocks({ root: document, signal: never }).then((value) => {
76
- result = value;
77
- });
78
- await vi.advanceTimersByTimeAsync(4_000);
79
- expect(result).toBeUndefined();
80
- chart.setAttribute("data-dms-block-state", "empty");
81
- await vi.advanceTimersByTimeAsync(4_000);
82
- expect(result).toEqual({
83
- status: "settled",
84
- checked: 1,
85
- blocks: [{ path: "revenue", type: "ChartCard", state: "empty" }],
86
- });
87
- });
88
-
89
- it("waits for a block that mounts after the others settled", async () => {
90
- addBlock("ok", "KpiCard", "orders");
91
- const settled = awaitSettledBlocks({ root: document, signal: never });
92
- await vi.advanceTimersByTimeAsync(300);
93
- addBlock("loading", "ChartCard", "late");
94
- await vi.advanceTimersByTimeAsync(BLOCK_SETTLE_BUDGET_MS);
95
- await expect(settled).resolves.toMatchObject({
96
- status: "timeout",
97
- checked: 2,
98
- blocks: [{ path: "late", type: "ChartCard", state: "loading" }],
99
- });
100
- });
101
-
102
- it("gives up at the budget and names the blocks still loading", async () => {
103
- addBlock("loading", "Chart", "slow");
104
- let finishedAt = -1;
105
- const started = Date.now();
106
- const settled = awaitSettledBlocks({ root: document, signal: never });
107
- void settled.then(() => {
108
- finishedAt = Date.now() - started;
109
- });
110
- await vi.advanceTimersByTimeAsync(BLOCK_SETTLE_BUDGET_MS - 1);
111
- expect(finishedAt).toBe(-1);
112
- await vi.advanceTimersByTimeAsync(1);
113
- await expect(settled).resolves.toEqual({
114
- status: "timeout",
115
- checked: 1,
116
- blocks: [{ path: "slow", type: "Chart", state: "loading" }],
117
- });
118
- expect(finishedAt).toBe(BLOCK_SETTLE_BUDGET_MS);
119
- });
120
-
121
- it("reports a page without data blocks as having none", async () => {
122
- const settled = awaitSettledBlocks({ root: document, signal: never });
123
- await vi.advanceTimersByTimeAsync(BLOCK_SETTLE_BUDGET_MS);
124
- await expect(settled).resolves.toEqual({
125
- status: "settled",
126
- checked: 0,
127
- blocks: [],
128
- });
129
- });
130
-
131
- it("answers at once as superseded when another navigation starts", async () => {
132
- addBlock("loading", "Chart", "slow");
133
- const controller = new AbortController();
134
- const settled = awaitSettledBlocks({
135
- root: document,
136
- signal: controller.signal,
137
- });
138
- await vi.advanceTimersByTimeAsync(100);
139
- controller.abort();
140
- await expect(settled).resolves.toMatchObject({ status: "superseded" });
141
- });
142
- });