@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,540 +0,0 @@
1
- // @vitest-environment jsdom
2
- import { afterEach, describe, expect, it, vi } from "vitest";
3
- import {
4
- CONNECTABLE_ENGINES,
5
- connectForm,
6
- engineNames,
7
- } from "../app/onboarding/connect-database";
8
- import { ENGINES } from "../builder/app/runtime/database-connect";
9
- import {
10
- analysisWith,
11
- fakeBuilder,
12
- LISTED,
13
- mountConnect,
14
- PROJECT,
15
- schemaCheck,
16
- unmountConnect,
17
- URL,
18
- WRITER,
19
- } from "./support/database-connect";
20
-
21
- vi.mock("../builder/app/runtime/i18n", async (importOriginal) => ({
22
- ...(await importOriginal<Record<string, unknown>>()),
23
- t: (key: string, params?: Record<string, unknown>) =>
24
- params === undefined ? key : `${key} ${JSON.stringify(params)}`,
25
- }));
26
-
27
- const SCHEMAS_QUESTION = {
28
- id: "schemas:shop",
29
- kind: "schemas",
30
- question: "which",
31
- options: [
32
- { value: "public", title: "public (4)" },
33
- { value: "sales", title: "sales (9)" },
34
- ],
35
- proposed: null,
36
- };
37
-
38
- function dmsDatabaseConfig(fake: ReturnType<typeof fakeBuilder>) {
39
- const steps = fake.configureProject.mock.calls[0]?.[0] ?? [];
40
- return steps.find((step) => step.id === "dms-database")?.entry?.config;
41
- }
42
-
43
- afterEach(() => {
44
- unmountConnect();
45
- vi.useRealTimers();
46
- });
47
-
48
- describe("the popup's connect form", () => {
49
- it.each([
50
- ["a database name with no letter or digit", "postgres://app:secret@h/___"],
51
- [
52
- "a database name of non-ASCII letters only",
53
- "postgres://app:secret@h/%E9%A1%A7%E5%AE%A2",
54
- ],
55
- ])("names no connection for %s", (_, url) => {
56
- expect(connectForm("postgres", url)).toEqual({ kind: "no-name" });
57
- });
58
-
59
- it("refuses a URL without a user, with the builder's own words", () => {
60
- const form = connectForm("postgres", "postgres://db.example.com/orders");
61
- expect(form).toEqual({
62
- kind: "invalid",
63
- message: expect.stringContaining("database.connect.missing_user"),
64
- });
65
- });
66
-
67
- it("refuses a host the builder's form would refuse", () => {
68
- const form = connectForm("postgres", "postgres://app:secret@a_b!c/shop");
69
- expect(form).toEqual({
70
- kind: "invalid",
71
- message: "database.connect.problem_host",
72
- });
73
- });
74
-
75
- it("names the connection after the database when the builder's form accepts the URL", () => {
76
- expect(connectForm("postgres", URL)).toMatchObject({
77
- name: "shop",
78
- engine: "postgres",
79
- });
80
- });
81
-
82
- it("writes nothing into the project for a URL it refuses", async () => {
83
- const fake = fakeBuilder();
84
- const connect = mountConnect(fake.api);
85
- const problem = await connect.connect(
86
- "postgres",
87
- "postgres://app:secret@db.example.com/___",
88
- );
89
- expect(problem).toEqual({ kind: "no-name" });
90
- expect(fake.configureProject).not.toHaveBeenCalled();
91
- expect(connect.phase.value).toEqual({ kind: "form" });
92
- });
93
-
94
- it("points a connection an earlier visit already wrote at the new URL instead of adding its module again", async () => {
95
- const setConnectionUrl = vi.fn(async () => ({
96
- ok: true,
97
- data: { variable: "SHOP_URL" },
98
- }));
99
- const fake = fakeBuilder({
100
- projectModules: async () => ({
101
- ...PROJECT,
102
- modules: ["builder-db-shop"],
103
- }),
104
- setConnectionUrl,
105
- });
106
- const connect = mountConnect(fake.api);
107
- await connect.connect("postgres", URL);
108
- expect(fake.configureProject).not.toHaveBeenCalled();
109
- expect(setConnectionUrl).toHaveBeenCalledWith(
110
- "shop",
111
- "postgres://app:secret@db.example.com:5432/shop",
112
- );
113
- expect(connect.refusal.value).toBeNull();
114
- expect(connect.phase.value).toMatchObject({
115
- kind: "analysing",
116
- connection: "shop",
117
- });
118
- });
119
- });
120
-
121
- describe("the live check before anything is written", () => {
122
- it.each([
123
- [
124
- "no server answers",
125
- {
126
- reachable: false,
127
- canRead: false,
128
- canWrite: false,
129
- reason: "Nothing is listening at this host and port.",
130
- },
131
- "reachable",
132
- ],
133
- [
134
- "the server refuses the sign-in",
135
- {
136
- reachable: true,
137
- canRead: false,
138
- canWrite: false,
139
- reason: "password authentication failed",
140
- },
141
- "signed-in",
142
- ],
143
- [
144
- "the account cannot read",
145
- {
146
- reachable: true,
147
- latencyMs: 3,
148
- user: "nobody",
149
- canRead: false,
150
- canWrite: false,
151
- reason: "This account cannot read this database.",
152
- },
153
- "read",
154
- ],
155
- ])(
156
- "writes nothing when %s, and fails that check with the reason",
157
- async (_, answer, key) => {
158
- const fake = fakeBuilder({ checkConnection: vi.fn(async () => answer) });
159
- const connect = mountConnect(fake.api);
160
- await connect.connect("postgres", URL);
161
- expect(fake.api.checkConnection).toHaveBeenCalledWith("postgres", URL);
162
- expect(fake.configureProject).not.toHaveBeenCalled();
163
- expect(fake.analyseDatabase).not.toHaveBeenCalled();
164
- expect(connect.checks.value.find((check) => check.key === key)).toEqual(
165
- expect.objectContaining({ status: "failed", error: answer.reason }),
166
- );
167
- expect(schemaCheck(connect)?.status).toBe("pending");
168
- },
169
- );
170
-
171
- it("fails the server check with the module's refusal when the check request itself is refused", async () => {
172
- const fake = fakeBuilder({
173
- checkConnection: vi.fn(async () => {
174
- throw new Error("Databases are checked in development only.");
175
- }),
176
- });
177
- const connect = mountConnect(fake.api);
178
- await connect.connect("postgres", URL);
179
- expect(fake.configureProject).not.toHaveBeenCalled();
180
- expect(connect.checks.value[0]).toEqual({
181
- key: "reachable",
182
- status: "failed",
183
- error: "Databases are checked in development only.",
184
- });
185
- });
186
-
187
- it("names the signed-in account and the latency it measured", async () => {
188
- const fake = fakeBuilder();
189
- const connect = mountConnect(fake.api);
190
- await connect.connect("postgres", URL);
191
- expect(connect.checks.value.slice(0, 3)).toEqual([
192
- { key: "reachable", status: "done", latencyMs: 4 },
193
- { key: "signed-in", status: "done", user: "reader" },
194
- { key: "read", status: "done", canWrite: false },
195
- ]);
196
- });
197
- });
198
-
199
- describe("the access written for the connection", () => {
200
- it("writes a read-only account's connection as read without asking", async () => {
201
- const fake = fakeBuilder();
202
- const connect = mountConnect(fake.api);
203
- await connect.connect("postgres", URL);
204
- expect(connect.phase.value.kind).not.toBe("choosing");
205
- expect(dmsDatabaseConfig(fake)).toEqual({
206
- externalConnections: { shop: { access: "read" } },
207
- });
208
- });
209
-
210
- it("waits for a choice when the account can write, then writes the access chosen", async () => {
211
- const fake = fakeBuilder({ checkConnection: vi.fn(async () => WRITER) });
212
- const connect = mountConnect(fake.api);
213
- await connect.connect("postgres", URL);
214
- expect(connect.phase.value).toEqual({ kind: "choosing" });
215
- expect(fake.configureProject).not.toHaveBeenCalled();
216
-
217
- await connect.choose("read-write");
218
- expect(dmsDatabaseConfig(fake)).toEqual({
219
- externalConnections: { shop: { access: "read-write" } },
220
- });
221
- expect(connect.phase.value).toMatchObject({ kind: "analysing" });
222
- });
223
-
224
- it("goes back to the form without writing when the choice is dropped", async () => {
225
- const fake = fakeBuilder({ checkConnection: vi.fn(async () => WRITER) });
226
- const connect = mountConnect(fake.api);
227
- await connect.connect("postgres", URL);
228
- connect.reset();
229
- await connect.choose("read-write");
230
- expect(connect.phase.value).toEqual({ kind: "form" });
231
- expect(fake.configureProject).not.toHaveBeenCalled();
232
- });
233
-
234
- it("offers no choice for a connection an earlier visit wrote, whose access it cannot raise", async () => {
235
- const setConnectionUrl = vi.fn(async () => ({
236
- ok: true,
237
- data: { variable: "SHOP_URL" },
238
- }));
239
- const fake = fakeBuilder({
240
- checkConnection: vi.fn(async () => WRITER),
241
- projectModules: async () => ({
242
- ...PROJECT,
243
- modules: ["builder-db-shop"],
244
- }),
245
- setConnectionUrl,
246
- });
247
- const connect = mountConnect(fake.api);
248
- await connect.connect("postgres", URL);
249
- expect(connect.phase.value).toMatchObject({ kind: "analysing" });
250
- expect(setConnectionUrl).toHaveBeenCalledTimes(1);
251
- expect(fake.configureProject).not.toHaveBeenCalled();
252
- });
253
- });
254
-
255
- describe("the driver a new connection adds", () => {
256
- /** Fails on a popup that writes a driver range of its own instead of the one core gives the project. */
257
- it("adds the driver at the package and range the project's interface-database allows", async () => {
258
- const fake = fakeBuilder();
259
- const connect = mountConnect(fake.api);
260
- await connect.connect("postgres", URL);
261
- const [driver] = fake.configureProject.mock.calls[0]?.[0] ?? [];
262
- expect(driver).toMatchObject({
263
- op: "AddModule",
264
- entry: {
265
- source: {
266
- type: "package",
267
- package: "@antelopejs/postgres",
268
- version: ">=0.2.6 <0.4.0",
269
- },
270
- },
271
- });
272
- });
273
-
274
- /** Fails on a popup that writes an engine the project has no driver for, or that does not say why. */
275
- it("refuses an engine the project has no driver for, says why, and writes nothing", async () => {
276
- const fake = fakeBuilder({
277
- projectModules: async () => ({
278
- ...PROJECT,
279
- interfaceDatabase: "0.4.0",
280
- drivers: {},
281
- }),
282
- });
283
- const connect = mountConnect(fake.api);
284
- await connect.connect("mysql", URL.replace("postgres:", "mysql:"));
285
- expect(fake.configureProject).not.toHaveBeenCalled();
286
- expect(connect.phase.value).toEqual({ kind: "form" });
287
- expect(connect.refusal.value).toBe(
288
- 'database.engines.unavailable {"engine":"MySQL / MariaDB","version":"0.4.0"}',
289
- );
290
- });
291
- });
292
-
293
- describe("following the connection's analysis", () => {
294
- it("answers the analysis's schemas question once, with the schemas the builder pre-checks", async () => {
295
- vi.useFakeTimers();
296
- const fake = fakeBuilder();
297
- const connect = mountConnect(fake.api);
298
- void connect.connect("postgres", URL);
299
- await vi.advanceTimersByTimeAsync(10);
300
- expect(fake.analyseDatabase).toHaveBeenCalledTimes(1);
301
- fake.setAnalysis(analysisWith([SCHEMAS_QUESTION]));
302
- await vi.advanceTimersByTimeAsync(5_000);
303
- expect(fake.analyseDatabase).toHaveBeenCalledTimes(2);
304
- expect(fake.analyseDatabase).toHaveBeenLastCalledWith(
305
- "shop",
306
- expect.any(String),
307
- ["public"],
308
- );
309
- });
310
-
311
- it("fails the schema check with the builder's refusal of the analysis, and stops polling", async () => {
312
- vi.useFakeTimers();
313
- const fake = fakeBuilder({
314
- analyseDatabase: vi.fn(async () => ({
315
- ok: false,
316
- error: { code: "unsupported", detail: "analysis refused" },
317
- })),
318
- });
319
- const connect = mountConnect(fake.api);
320
- void connect.connect("postgres", URL);
321
- await vi.advanceTimersByTimeAsync(5_000);
322
- expect(schemaCheck(connect)).toMatchObject({
323
- status: "failed",
324
- problem: "failed",
325
- error: "analysis refused",
326
- });
327
- expect(fake.api.analyseDatabase).toHaveBeenCalledTimes(1);
328
- });
329
-
330
- it("resolves into a failed schema check when the analysis request throws", async () => {
331
- vi.useFakeTimers();
332
- const fake = fakeBuilder({
333
- analyseDatabase: async () => {
334
- throw new Error("network down");
335
- },
336
- });
337
- const connect = mountConnect(fake.api);
338
- const outcome = connect.connect("postgres", URL).then(
339
- () => "resolved",
340
- (error: Error) => `rejected: ${error.message}`,
341
- );
342
- await vi.advanceTimersByTimeAsync(5_000);
343
- expect(await outcome).toBe("resolved");
344
- expect(schemaCheck(connect)).toMatchObject({
345
- status: "failed",
346
- error: "network down",
347
- });
348
- });
349
-
350
- it("retries a failed analysis against the connection already written", async () => {
351
- vi.useFakeTimers();
352
- let refuse = true;
353
- const fake = fakeBuilder({
354
- analyseDatabase: vi.fn(async () =>
355
- refuse
356
- ? { ok: false, error: { detail: "analysis refused" } }
357
- : { ok: true, data: {} },
358
- ),
359
- });
360
- const connect = mountConnect(fake.api);
361
- void connect.connect("postgres", URL);
362
- await vi.advanceTimersByTimeAsync(5_000);
363
- expect(schemaCheck(connect)?.status).toBe("failed");
364
-
365
- refuse = false;
366
- void connect.connect("postgres", URL);
367
- await vi.advanceTimersByTimeAsync(10);
368
- expect(schemaCheck(connect)?.status).toBe("running");
369
- expect(fake.api.analyseDatabase).toHaveBeenCalledTimes(2);
370
- expect(fake.configureProject).toHaveBeenCalledTimes(1);
371
- });
372
- });
373
-
374
- describe("a project that does not reload by itself", () => {
375
- it("asks for a restart while the project answers without the connection, then analyses once it is loaded", async () => {
376
- vi.useFakeTimers();
377
- let listed: (typeof LISTED)[] = [];
378
- const fake = fakeBuilder({ databaseConnections: async () => listed });
379
- const connect = mountConnect(fake.api);
380
- void connect.connect("postgres", URL);
381
- await vi.advanceTimersByTimeAsync(15_000);
382
- expect(schemaCheck(connect)).toEqual({ key: "schema", status: "running" });
383
-
384
- await vi.advanceTimersByTimeAsync(4 * 60_000);
385
- expect(schemaCheck(connect)).toEqual({
386
- key: "schema",
387
- status: "running",
388
- restart: true,
389
- });
390
- expect(fake.analyseDatabase).not.toHaveBeenCalled();
391
-
392
- listed = [LISTED];
393
- await vi.advanceTimersByTimeAsync(2_000);
394
- expect(schemaCheck(connect)).toEqual({ key: "schema", status: "running" });
395
- expect(fake.analyseDatabase).toHaveBeenCalled();
396
- });
397
-
398
- it("counts the 20 seconds again after the project went down in between", async () => {
399
- vi.useFakeTimers();
400
- let down = false;
401
- const fake = fakeBuilder({
402
- databaseConnections: async () => {
403
- if (down) throw new Error("project down");
404
- return [];
405
- },
406
- });
407
- const connect = mountConnect(fake.api);
408
- void connect.connect("postgres", URL);
409
- await vi.advanceTimersByTimeAsync(10_000);
410
- down = true;
411
- await vi.advanceTimersByTimeAsync(12_000);
412
- down = false;
413
- await vi.advanceTimersByTimeAsync(15_000);
414
- expect(schemaCheck(connect)).toEqual({ key: "schema", status: "running" });
415
-
416
- await vi.advanceTimersByTimeAsync(6_000);
417
- expect(schemaCheck(connect)).toEqual({
418
- key: "schema",
419
- status: "running",
420
- restart: true,
421
- });
422
- });
423
- });
424
-
425
- function deferred<T>() {
426
- let resolve: (value: T) => void = () => undefined;
427
- const promise = new Promise<T>((settle) => {
428
- resolve = settle;
429
- });
430
- return { promise, resolve };
431
- }
432
-
433
- describe("an attempt the owner replaced", () => {
434
- it("writes the new URL of a database already connected under the same name", async () => {
435
- vi.useFakeTimers();
436
- const setConnectionUrl = vi.fn(async () => ({
437
- ok: true,
438
- data: { variable: "SHOP_URL" },
439
- }));
440
- const fake = fakeBuilder({
441
- setConnectionUrl,
442
- analyseDatabase: vi.fn(async () => ({
443
- ok: false,
444
- error: { detail: "analysis refused" },
445
- })),
446
- });
447
- const connect = mountConnect(fake.api);
448
- void connect.connect("postgres", URL);
449
- await vi.advanceTimersByTimeAsync(5_000);
450
- void connect.connect(
451
- "postgres",
452
- "postgres://app:secret@db2.example.com/shop",
453
- );
454
- await vi.advanceTimersByTimeAsync(10);
455
- expect(setConnectionUrl).toHaveBeenCalledWith(
456
- "shop",
457
- "postgres://app:secret@db2.example.com:5432/shop",
458
- );
459
- expect(fake.configureProject).toHaveBeenCalledTimes(1);
460
- });
461
-
462
- it("shows no refusal of a write the owner moved on from", async () => {
463
- const write = deferred<{ ok: false; error: { detail: string } }>();
464
- const fake = fakeBuilder({
465
- checkConnection: vi.fn(async () => WRITER),
466
- configureProject: vi.fn(() => write.promise),
467
- });
468
- const connect = mountConnect(fake.api);
469
- await connect.connect("postgres", URL);
470
- const chosen = connect.choose("read");
471
- connect.reset();
472
- await connect.connect(
473
- "postgres",
474
- "postgres://app:secret@db.example.com/orders",
475
- );
476
- write.resolve({ ok: false, error: { detail: "refusal of shop" } });
477
- await chosen;
478
- expect(connect.refusal.value).toBeNull();
479
- expect(connect.phase.value).toEqual({ kind: "choosing" });
480
- });
481
-
482
- it("starts no analysis once the step is gone", async () => {
483
- const answer = deferred<{ ok: false }>();
484
- let reads = 0;
485
- const fake = fakeBuilder({
486
- latestAnalysis: () => {
487
- reads += 1;
488
- return answer.promise;
489
- },
490
- });
491
- const connect = mountConnect(fake.api);
492
- const run = connect.connect("postgres", URL);
493
- await vi.waitFor(() => expect(reads).toBe(1));
494
- unmountConnect();
495
- answer.resolve({ ok: false });
496
- await run;
497
- expect(fake.analyseDatabase).not.toHaveBeenCalled();
498
- });
499
-
500
- it("leaves the next attempt's steps alone when the replaced one's build answer comes late", async () => {
501
- const answer = deferred<{ ok: false }>();
502
- let reads = 0;
503
- const fake = fakeBuilder({
504
- latestAnalysis: () => {
505
- reads += 1;
506
- return reads === 1 ? answer.promise : Promise.resolve({ ok: false });
507
- },
508
- });
509
- const connect = mountConnect(fake.api);
510
- const first = connect.connect("postgres", URL);
511
- await vi.waitFor(() => expect(reads).toBe(1));
512
- connect.reset();
513
- fake.api.checkConnection.mockImplementation(async () => WRITER);
514
- await connect.connect(
515
- "postgres",
516
- "postgres://app:secret@db.example.com/orders",
517
- );
518
- answer.resolve({ ok: false });
519
- await first;
520
- expect(fake.analyseDatabase).not.toHaveBeenCalled();
521
- expect(schemaCheck(connect)?.status).toBe("pending");
522
- });
523
- });
524
-
525
- describe("the engines the popup offers", () => {
526
- it.each([
527
- ["en-GB", " or "],
528
- ["fr-FR", " ou "],
529
- ])(
530
- "names every engine the builder connects, as a choice, in %s",
531
- (locale, or) => {
532
- const names = engineNames(locale);
533
- for (const engine of CONNECTABLE_ENGINES) {
534
- expect(names).toContain(ENGINES[engine].label);
535
- }
536
- expect(CONNECTABLE_ENGINES).toHaveLength(Object.keys(ENGINES).length);
537
- expect(names).toContain(or);
538
- },
539
- );
540
- });
@@ -1,51 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { nextTick, ref } from "vue";
3
- import { linkedStep, withoutLinkedStep } from "../app/onboarding/deep-link";
4
- import { installDeepLink } from "../app/onboarding/runtime";
5
-
6
- describe("?assistant=connect", () => {
7
- it("asks for the connect form, and nothing else does", () => {
8
- expect(linkedStep("http://dms.test/orders?assistant=connect")).toBe(
9
- "connect-database",
10
- );
11
- expect(linkedStep("http://dms.test/orders?assistant=chat")).toBeNull();
12
- expect(linkedStep("http://dms.test/orders?tab=connect")).toBeNull();
13
- });
14
-
15
- it("leaves the address with every other parameter as written, in place, and the hash", () => {
16
- expect(
17
- withoutLinkedStep(
18
- "http://dms.test/orders?tab=open&assistant=connect&q=a%20b&tag=x&tag=y#totals",
19
- ),
20
- ).toBe("/orders?tab=open&q=a%20b&tag=x&tag=y#totals");
21
- expect(withoutLinkedStep("http://dms.test/orders?assistant=connect")).toBe(
22
- "/orders",
23
- );
24
- });
25
-
26
- it("opens the popup on load and after a later client navigation, then takes the parameter out", async () => {
27
- const href = ref("http://dms.test/orders?assistant=connect&tab=open");
28
- const param = ref<string | undefined>("connect");
29
- const open = vi.fn();
30
- const replace = vi.fn((path: string) => {
31
- href.value = `http://dms.test${path}`;
32
- param.value = undefined;
33
- });
34
- const stop = installDeepLink({
35
- href: () => href.value,
36
- param: () => param.value,
37
- replace,
38
- open,
39
- });
40
- expect(open).toHaveBeenCalledWith("connect-database");
41
- expect(replace).toHaveBeenLastCalledWith("/orders?tab=open");
42
- await nextTick();
43
-
44
- href.value = "http://dms.test/customers?assistant=connect#list";
45
- param.value = "connect";
46
- await nextTick();
47
- expect(open).toHaveBeenCalledTimes(2);
48
- expect(replace).toHaveBeenLastCalledWith("/customers#list");
49
- stop();
50
- });
51
- });