@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,174 +0,0 @@
1
- // @vitest-environment jsdom
2
- import { afterEach, describe, expect, it, vi } from "vitest";
3
- import type { DatabaseConnect } from "../app/onboarding/connect-database";
4
- import {
5
- type ConnectMemory,
6
- connectMemory,
7
- } from "../app/onboarding/connect-memory";
8
- import {
9
- analysisWith,
10
- fakeBuilder,
11
- LISTED,
12
- mountConnect,
13
- PROJECT,
14
- schemaCheck,
15
- unmountConnect,
16
- } from "./support/database-connect";
17
-
18
- vi.mock("../builder/app/runtime/i18n", async (importOriginal) => ({
19
- ...(await importOriginal<Record<string, unknown>>()),
20
- t: (key: string) => key,
21
- }));
22
-
23
- afterEach(() => {
24
- unmountConnect();
25
- vi.useRealTimers();
26
- window.sessionStorage.clear();
27
- });
28
-
29
- const CORRECTED = "postgres://app:fixed@db2.example.com/shop";
30
-
31
- const ANALYSED = {
32
- ...analysisWith([]),
33
- proposal: {
34
- ...analysisWith([]).proposal,
35
- resources: [{ relation: "orders", tableView: { value: true } }],
36
- },
37
- };
38
-
39
- /**
40
- * A project that loaded `.env` with the old URL of `shop`, so it lists `shop` with that URL's error
41
- * and failed analysis until it restarts on the `.env` the popup writes, as `ajs project dev -w`
42
- * does once `.env` changed.
43
- */
44
- function failedConnection() {
45
- const OLD = "postgres://app:old@db.example.com:5432/shop";
46
- let env = OLD;
47
- let loaded = OLD;
48
- const fake = fakeBuilder({
49
- projectModules: async () => ({ ...PROJECT, modules: ["builder-db-shop"] }),
50
- setConnectionUrl: vi.fn(async (_connection: string, url: string) => {
51
- env = url;
52
- return { ok: true, data: { variable: "SHOP_URL" } };
53
- }),
54
- reloadDue: async () => ({ due: env !== loaded }),
55
- databaseConnections: async () =>
56
- loaded === OLD
57
- ? [{ ...LISTED, error: "password authentication failed" }]
58
- : [LISTED],
59
- });
60
- fake.setAnalysis({ id: "old-job", status: "failed", progress: {} });
61
- return {
62
- fake,
63
- restart: () => {
64
- loaded = env;
65
- fake.setAnalysis(null);
66
- },
67
- };
68
- }
69
-
70
- function tabMemory(): ConnectMemory {
71
- return connectMemory(
72
- () => window.sessionStorage,
73
- () => "owner-1",
74
- );
75
- }
76
-
77
- function noCheckFailed(connect: DatabaseConnect): boolean {
78
- return connect.checks.value.every((check) => check.status !== "failed");
79
- }
80
-
81
- describe("a corrected URL for a connection that failed", () => {
82
- it("waits for the project to load it, then shows its analysis", async () => {
83
- vi.useFakeTimers();
84
- const { fake, restart } = failedConnection();
85
- const connect = mountConnect(fake.api, tabMemory());
86
- void connect.connect("postgres", CORRECTED);
87
- await vi.advanceTimersByTimeAsync(5_000);
88
- expect(connect.phase.value.kind).toBe("analysing");
89
- expect(noCheckFailed(connect)).toBe(true);
90
- expect(fake.analyseDatabase).not.toHaveBeenCalled();
91
-
92
- restart();
93
- await vi.advanceTimersByTimeAsync(2_000);
94
- expect(fake.analyseDatabase).toHaveBeenCalledWith(
95
- "shop",
96
- "builder-db-shop-tables",
97
- undefined,
98
- );
99
- fake.setAnalysis(ANALYSED);
100
- await vi.advanceTimersByTimeAsync(2_000);
101
- expect(connect.phase.value).toMatchObject({
102
- kind: "analysed",
103
- connection: "shop",
104
- });
105
- });
106
-
107
- it("asks for a restart when the project keeps answering with the old URL", async () => {
108
- vi.useFakeTimers();
109
- const { fake } = failedConnection();
110
- const connect = mountConnect(fake.api, tabMemory());
111
- void connect.connect("postgres", CORRECTED);
112
- await vi.advanceTimersByTimeAsync(25_000);
113
- expect(schemaCheck(connect)).toEqual({
114
- key: "schema",
115
- status: "running",
116
- restart: true,
117
- });
118
- });
119
-
120
- it("resumes after a reload of the page while the project still answers with the old URL", async () => {
121
- vi.useFakeTimers();
122
- const { fake, restart } = failedConnection();
123
- const memory = tabMemory();
124
- void mountConnect(fake.api, memory).connect("postgres", CORRECTED);
125
- await vi.advanceTimersByTimeAsync(1_000);
126
-
127
- unmountConnect();
128
- const resumed = mountConnect(fake.api, memory);
129
- await vi.advanceTimersByTimeAsync(3_000);
130
- expect(resumed.phase.value.kind).toBe("analysing");
131
- expect(noCheckFailed(resumed)).toBe(true);
132
- expect(memory.read()).toMatchObject({ connection: "shop" });
133
-
134
- restart();
135
- await vi.advanceTimersByTimeAsync(2_000);
136
- fake.setAnalysis(ANALYSED);
137
- await vi.advanceTimersByTimeAsync(2_000);
138
- expect(resumed.phase.value).toMatchObject({
139
- kind: "analysed",
140
- connection: "shop",
141
- });
142
- expect(fake.api.setConnectionUrl).toHaveBeenCalledTimes(1);
143
- });
144
- });
145
-
146
- describe("the URL the project already loaded, entered again", () => {
147
- it("follows the running project, which has nothing new to load", async () => {
148
- vi.useFakeTimers();
149
- const LOADED = "postgres://app:secret@db.example.com:5432/shop";
150
- let env = LOADED;
151
- const fake = fakeBuilder({
152
- projectModules: async () => ({
153
- ...PROJECT,
154
- modules: ["builder-db-shop"],
155
- }),
156
- setConnectionUrl: vi.fn(async (_connection: string, url: string) => {
157
- env = url;
158
- return { ok: true, data: { variable: "SHOP_URL" } };
159
- }),
160
- reloadDue: async () => ({ due: env !== LOADED }),
161
- });
162
- const connect = mountConnect(fake.api, tabMemory());
163
- void connect.connect("postgres", LOADED);
164
- await vi.advanceTimersByTimeAsync(2_000);
165
- expect(fake.api.setConnectionUrl).toHaveBeenCalledWith("shop", LOADED);
166
- expect(fake.analyseDatabase).toHaveBeenCalled();
167
- fake.setAnalysis(ANALYSED);
168
- await vi.advanceTimersByTimeAsync(2_000);
169
- expect(connect.phase.value).toMatchObject({
170
- kind: "analysed",
171
- connection: "shop",
172
- });
173
- });
174
- });
@@ -1,229 +0,0 @@
1
- // @vitest-environment jsdom
2
- import { afterEach, describe, expect, it, vi } from "vitest";
3
- import type { DatabaseConnect } from "../app/onboarding/connect-database";
4
- import {
5
- CONNECT_MEMORY_LIMIT_MS,
6
- type ConnectMemory,
7
- connectMemory,
8
- } from "../app/onboarding/connect-memory";
9
- import {
10
- analysisWith,
11
- fakeBuilder,
12
- READER,
13
- mountConnect,
14
- unmountConnect,
15
- URL,
16
- } from "./support/database-connect";
17
- import { memoryConnects } from "./support/onboarding";
18
-
19
- vi.mock("../builder/app/runtime/i18n", async (importOriginal) => ({
20
- ...(await importOriginal<Record<string, unknown>>()),
21
- t: (key: string) => key,
22
- }));
23
-
24
- afterEach(() => {
25
- unmountConnect();
26
- vi.useRealTimers();
27
- window.sessionStorage.clear();
28
- window.localStorage.clear();
29
- });
30
-
31
- function browserStorage(): string {
32
- const entries = [window.sessionStorage, window.localStorage].flatMap(
33
- (storage) =>
34
- Array.from({ length: storage.length }, (_, index) => {
35
- const key = storage.key(index) ?? "";
36
- return `${key}=${storage.getItem(key) ?? ""}`;
37
- }),
38
- );
39
- return [...entries, document.cookie].join("\n");
40
- }
41
-
42
- describe("a reload of the page while the connection loads", () => {
43
- const ANALYSED = {
44
- ...analysisWith([]),
45
- proposal: {
46
- ...analysisWith([]).proposal,
47
- resources: [{ relation: "orders", tableView: { value: true } }],
48
- },
49
- };
50
-
51
- function reload(api: unknown, memory: ConnectMemory): DatabaseConnect {
52
- unmountConnect();
53
- return mountConnect(api, memory);
54
- }
55
-
56
- it("follows the connection it wrote to its analysis, with the live check's answer, keeping no part of the URL in the browser", async () => {
57
- vi.useFakeTimers();
58
- const fake = fakeBuilder();
59
- const memory = connectMemory(
60
- () => window.sessionStorage,
61
- () => "owner-1",
62
- );
63
- void mountConnect(fake.api, memory).connect("postgres", URL);
64
- await vi.advanceTimersByTimeAsync(10);
65
-
66
- const resumed = reload(fake.api, memory);
67
- expect(resumed.phase.value).toEqual({
68
- kind: "analysing",
69
- connection: "shop",
70
- module: "builder-db-shop-tables",
71
- });
72
- expect(resumed.checks.value.slice(0, 3)).toEqual([
73
- { key: "reachable", status: "done", latencyMs: 4 },
74
- { key: "signed-in", status: "done", user: "reader" },
75
- { key: "read", status: "done", canWrite: false },
76
- ]);
77
- const stored = browserStorage();
78
- expect(stored).toContain('"connection":"shop"');
79
- for (const part of [URL, "secret", "db.example.com"]) {
80
- expect(stored).not.toContain(part);
81
- }
82
-
83
- fake.setAnalysis(ANALYSED);
84
- await vi.advanceTimersByTimeAsync(2_000);
85
- expect(resumed.phase.value).toMatchObject({
86
- kind: "analysed",
87
- connection: "shop",
88
- });
89
- expect(fake.api.checkConnection).toHaveBeenCalledTimes(1);
90
- expect(fake.configureProject).toHaveBeenCalledTimes(1);
91
- });
92
-
93
- it("opens on the form once the analysis it followed is ready", async () => {
94
- vi.useFakeTimers();
95
- const fake = fakeBuilder();
96
- fake.setAnalysis(ANALYSED);
97
- const memory = memoryConnects();
98
- const connect = mountConnect(fake.api, memory);
99
- void connect.connect("postgres", URL);
100
- await vi.advanceTimersByTimeAsync(10);
101
- expect(connect.phase.value.kind).toBe("analysed");
102
-
103
- expect(reload(fake.api, memory).phase.value).toEqual({ kind: "form" });
104
- });
105
-
106
- it("opens on the form after the owner went back to it", async () => {
107
- vi.useFakeTimers();
108
- const fake = fakeBuilder();
109
- const memory = memoryConnects();
110
- const connect = mountConnect(fake.api, memory);
111
- void connect.connect("postgres", URL);
112
- await vi.advanceTimersByTimeAsync(10);
113
- connect.reset();
114
-
115
- expect(reload(fake.api, memory).phase.value).toEqual({ kind: "form" });
116
- });
117
-
118
- it.each([
119
- ["its analysis failed", { id: "job1", status: "failed", progress: {} }],
120
- ["the database has no table", analysisWith([])],
121
- ])("opens on the form once %s", async (_, analysis) => {
122
- vi.useFakeTimers();
123
- const fake = fakeBuilder();
124
- fake.setAnalysis(analysis);
125
- const memory = memoryConnects();
126
- void mountConnect(fake.api, memory).connect("postgres", URL);
127
- await vi.advanceTimersByTimeAsync(10);
128
-
129
- expect(memory.read()).toBeNull();
130
- });
131
-
132
- function slowWrite() {
133
- let answer: (result: { ok: true }) => void = () => undefined;
134
- const fake = fakeBuilder({
135
- configureProject: vi.fn(
136
- () =>
137
- new Promise<{ ok: true }>((resolve) => {
138
- answer = resolve;
139
- }),
140
- ),
141
- });
142
- return { api: fake.api, answer: () => answer({ ok: true }) };
143
- }
144
-
145
- it("follows the connection it wrote when the popup closed before the write answered", async () => {
146
- vi.useFakeTimers();
147
- const closed = slowWrite();
148
- const memory = memoryConnects();
149
- void mountConnect(closed.api, memory).connect("postgres", URL);
150
- await vi.advanceTimersByTimeAsync(10);
151
- unmountConnect();
152
- closed.answer();
153
- await vi.advanceTimersByTimeAsync(10);
154
-
155
- expect(mountConnect(closed.api, memory).phase.value).toEqual({
156
- kind: "analysing",
157
- connection: "shop",
158
- module: "builder-db-shop-tables",
159
- });
160
- });
161
-
162
- it("keeps the connection a reopened popup wrote over a write the closed one answers later", async () => {
163
- vi.useFakeTimers();
164
- const closed = slowWrite();
165
- const memory = memoryConnects();
166
- void mountConnect(closed.api, memory).connect("postgres", URL);
167
- await vi.advanceTimersByTimeAsync(10);
168
- const reopened = reload(fakeBuilder().api, memory);
169
- void reopened.connect(
170
- "postgres",
171
- "postgres://app:secret@db.example.com/crm",
172
- );
173
- await vi.advanceTimersByTimeAsync(10);
174
- closed.answer();
175
- await vi.advanceTimersByTimeAsync(10);
176
-
177
- expect(memory.read()?.connection).toBe("crm");
178
- });
179
-
180
- it("keeps nothing from a write the closed popup answers after the reopened one went back to its form", async () => {
181
- vi.useFakeTimers();
182
- const closed = slowWrite();
183
- const memory = memoryConnects();
184
- void mountConnect(closed.api, memory).connect("postgres", URL);
185
- await vi.advanceTimersByTimeAsync(10);
186
- reload(fakeBuilder().api, memory).reset();
187
- closed.answer();
188
- await vi.advanceTimersByTimeAsync(10);
189
-
190
- expect(memory.read()).toBeNull();
191
- });
192
-
193
- it("returns to the form and forgets a remembered connection the project no longer declares", async () => {
194
- vi.useFakeTimers();
195
- const fake = fakeBuilder({
196
- databaseConnection: async () => {
197
- throw { data: { code: "not_found" } };
198
- },
199
- databaseConnections: async () => [],
200
- });
201
- const memory = memoryConnects({
202
- engine: "postgres",
203
- connection: "gone",
204
- access: READER,
205
- });
206
- const resumed = mountConnect(fake.api, memory);
207
- await vi.advanceTimersByTimeAsync(10);
208
-
209
- expect(resumed.phase.value).toEqual({ kind: "form" });
210
- expect(memory.read()).toBeNull();
211
- });
212
-
213
- it("returns to the form and forgets a remembered connection once the time to follow it again ran out", async () => {
214
- vi.useFakeTimers();
215
- const fake = fakeBuilder();
216
- const memory = memoryConnects({
217
- engine: "postgres",
218
- connection: "shop",
219
- access: READER,
220
- });
221
- const resumed = mountConnect(fake.api, memory);
222
- await vi.advanceTimersByTimeAsync(CONNECT_MEMORY_LIMIT_MS - 2_000);
223
- expect(resumed.phase.value.kind).toBe("analysing");
224
-
225
- await vi.advanceTimersByTimeAsync(2_000);
226
- expect(resumed.phase.value).toEqual({ kind: "form" });
227
- expect(memory.read()).toBeNull();
228
- });
229
- });
@@ -1,184 +0,0 @@
1
- // @vitest-environment jsdom
2
- import { mount, type VueWrapper } from "@vue/test-utils";
3
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
- import { defineComponent } from "vue";
5
- import {
6
- type DatabaseConnect,
7
- useDatabaseConnect,
8
- } from "../app/onboarding/connect-database";
9
- import { analysisWith, fakeBuilder, READER } from "./support/database-connect";
10
- import { memoryConnects } from "./support/onboarding";
11
-
12
- vi.mock("../builder/app/runtime/i18n", async (importOriginal) => ({
13
- ...(await importOriginal<Record<string, unknown>>()),
14
- t: (key: string) => key,
15
- }));
16
-
17
- const SCHEMAS_QUESTION = {
18
- id: "schemas:shop",
19
- kind: "schemas",
20
- question: "which",
21
- options: [{ value: "public", title: "public (4)" }],
22
- proposed: null,
23
- };
24
-
25
- const ANALYSED = {
26
- ...analysisWith([]),
27
- proposal: {
28
- ...analysisWith([]).proposal,
29
- resources: [{ relation: "orders", tableView: { value: true } }],
30
- },
31
- };
32
-
33
- /**
34
- * The browser's Web Locks, which every tab of the origin shares and a closed tab releases. A lock
35
- * is granted `grantMs` after the request, in a later task, as the browser grants it.
36
- */
37
- function sharedLocks(grantMs = 0) {
38
- const held = new Set<string>();
39
- return {
40
- request: async (
41
- name: string,
42
- _options: { ifAvailable: boolean },
43
- callback: (lock: { name: string } | null) => unknown,
44
- ): Promise<unknown> => {
45
- if (held.has(name)) return callback(null);
46
- held.add(name);
47
- await new Promise((granted) => setTimeout(granted, grantMs));
48
- try {
49
- return await callback({ name });
50
- } finally {
51
- held.delete(name);
52
- }
53
- },
54
- };
55
- }
56
-
57
- const tabs: VueWrapper[] = [];
58
-
59
- /**
60
- * A tab that follows `shop`, remembered in its copy of the tab's storage, with its own analysis
61
- * requests counted.
62
- */
63
- function tab(api: ReturnType<typeof fakeBuilder>["api"]) {
64
- const analyseDatabase = vi.fn(
65
- (...args: Parameters<typeof api.analyseDatabase>) =>
66
- api.analyseDatabase(...args),
67
- );
68
- let connect: DatabaseConnect | undefined;
69
- const memory = memoryConnects({
70
- engine: "postgres",
71
- connection: "shop",
72
- access: READER,
73
- });
74
- const wrapper = mount(
75
- defineComponent({
76
- setup() {
77
- connect = useDatabaseConnect(
78
- { ...api, analyseDatabase } as never,
79
- memory,
80
- );
81
- return () => null;
82
- },
83
- }),
84
- );
85
- tabs.push(wrapper);
86
- if (connect === undefined) throw new Error("the tab did not set up");
87
- return { connect, analyseDatabase, close: () => wrapper.unmount() };
88
- }
89
-
90
- beforeEach(() => {
91
- vi.useFakeTimers();
92
- Object.defineProperty(window.navigator, "locks", {
93
- value: sharedLocks(),
94
- configurable: true,
95
- });
96
- });
97
-
98
- afterEach(() => {
99
- for (const wrapper of tabs.splice(0)) wrapper.unmount();
100
- Reflect.deleteProperty(window.navigator, "locks");
101
- vi.useRealTimers();
102
- });
103
-
104
- describe("a tab duplicated while a connection loads", () => {
105
- it("starts one analysis for both tabs, and both show it", async () => {
106
- const fake = fakeBuilder();
107
- const first = tab(fake.api);
108
- const duplicate = tab(fake.api);
109
- await vi.advanceTimersByTimeAsync(3_000);
110
- expect(
111
- first.analyseDatabase.mock.calls.length +
112
- duplicate.analyseDatabase.mock.calls.length,
113
- ).toBeGreaterThan(0);
114
- expect(
115
- Math.min(
116
- first.analyseDatabase.mock.calls.length,
117
- duplicate.analyseDatabase.mock.calls.length,
118
- ),
119
- ).toBe(0);
120
-
121
- fake.setAnalysis(ANALYSED);
122
- await vi.advanceTimersByTimeAsync(2_000);
123
- expect(first.connect.phase.value.kind).toBe("analysed");
124
- expect(duplicate.connect.phase.value.kind).toBe("analysed");
125
- });
126
-
127
- it("answers the analysis's schemas question from one tab only", async () => {
128
- const fake = fakeBuilder();
129
- fake.setAnalysis(analysisWith([SCHEMAS_QUESTION]));
130
- const first = tab(fake.api);
131
- const duplicate = tab(fake.api);
132
- await vi.advanceTimersByTimeAsync(3_000);
133
- const calls = [
134
- ...first.analyseDatabase.mock.calls,
135
- ...duplicate.analyseDatabase.mock.calls,
136
- ];
137
- expect(calls).toEqual([["shop", "builder-db-shop-tables", ["public"]]]);
138
- });
139
-
140
- it("starts the analysis from the other tab once the one that led it closes", async () => {
141
- const fake = fakeBuilder();
142
- const first = tab(fake.api);
143
- const duplicate = tab(fake.api);
144
- await vi.advanceTimersByTimeAsync(2_000);
145
- const [leading, other] =
146
- first.analyseDatabase.mock.calls.length > 0
147
- ? [first, duplicate]
148
- : [duplicate, first];
149
- expect(other.analyseDatabase).not.toHaveBeenCalled();
150
-
151
- leading.close();
152
- await vi.advanceTimersByTimeAsync(2_000);
153
- expect(other.analyseDatabase).toHaveBeenCalled();
154
- });
155
-
156
- it("leaves the lead to the other tab when it stops before its lock is granted", async () => {
157
- Object.defineProperty(window.navigator, "locks", {
158
- value: sharedLocks(50),
159
- configurable: true,
160
- });
161
- const fake = fakeBuilder();
162
- const first = tab(fake.api);
163
- await vi.advanceTimersByTimeAsync(10);
164
- first.connect.reset();
165
- const duplicate = tab(fake.api);
166
- await vi.advanceTimersByTimeAsync(3_000);
167
- expect(first.analyseDatabase).not.toHaveBeenCalled();
168
- expect(duplicate.analyseDatabase).toHaveBeenCalled();
169
- });
170
-
171
- it("follows and analyses where the browser refuses its Web Locks", async () => {
172
- Object.defineProperty(window.navigator, "locks", {
173
- value: {
174
- request: () =>
175
- Promise.reject(new DOMException("denied", "SecurityError")),
176
- },
177
- configurable: true,
178
- });
179
- const fake = fakeBuilder();
180
- const only = tab(fake.api);
181
- await vi.advanceTimersByTimeAsync(2_000);
182
- expect(only.analyseDatabase).toHaveBeenCalled();
183
- });
184
- });