@antelopejs/dms-assistant 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -17
- package/dist/builder/config.d.ts +1 -0
- package/dist/builder/config.js +9 -0
- package/dist/builder/config.js.map +1 -1
- package/dist/builder/constants/routes.d.ts +1 -0
- package/dist/builder/constants/routes.js +1 -0
- package/dist/builder/constants/routes.js.map +1 -1
- package/dist/builder/index.js +2 -0
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/reload.d.ts +2 -0
- package/dist/builder/reload.js +24 -0
- package/dist/builder/reload.js.map +1 -0
- package/dist/builder/routes/database.d.ts +3 -0
- package/dist/builder/routes/database.js +11 -0
- package/dist/builder/routes/database.js.map +1 -1
- package/dist/constants/i18n.d.ts +1 -1
- package/dist/constants/i18n.js +1 -1
- package/dist/constants/i18n.js.map +1 -1
- package/dist/constants/project-mcp.d.ts +0 -2
- package/dist/constants/project-mcp.js +1 -3
- package/dist/constants/project-mcp.js.map +1 -1
- package/dist/constants/sidecar.d.ts +6 -6
- package/dist/constants/sidecar.js +6 -6
- package/dist/constants/sidecar.js.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/lifecycle/project-mcp-json.js +6 -37
- package/dist/lifecycle/project-mcp-json.js.map +1 -1
- package/dist/lifecycle/sidecar-unavailable-error.js +1 -1
- package/dist/lifecycle/sidecar-unavailable-error.js.map +1 -1
- package/dist/pages/activity/page.js +1 -1
- package/dist/pages/activity/page.js.map +1 -1
- package/dist/pages/changes/page.js +1 -1
- package/dist/pages/changes/page.js.map +1 -1
- package/dist/routes/activity.js +1 -1
- package/dist/routes/activity.js.map +1 -1
- package/dist/vocabulary/enumerations.js +0 -1
- package/dist/vocabulary/enumerations.js.map +1 -1
- package/dist/vocabulary/tools.js +1 -1
- package/dist/vocabulary/tools.js.map +1 -1
- package/frontend-vue/app/chat/components/AnswerRecord.vue +3 -3
- package/frontend-vue/app/chat/components/ApprovalDock.vue +15 -11
- package/frontend-vue/app/chat/components/BlockOutline.vue +10 -10
- package/frontend-vue/app/chat/components/BlockPreviewCard.vue +9 -7
- package/frontend-vue/app/chat/components/BlockPreviewModal.vue +15 -14
- package/frontend-vue/app/chat/components/BlockPreviewThumb.vue +1 -1
- package/frontend-vue/app/chat/components/BuildDialog.vue +16 -13
- package/frontend-vue/app/chat/components/ChangeSetCard.vue +15 -13
- package/frontend-vue/app/chat/components/ChatEmpty.vue +4 -4
- package/frontend-vue/app/chat/components/ChatView.vue +45 -101
- package/frontend-vue/app/chat/components/Composer.vue +42 -34
- package/frontend-vue/app/chat/components/ConnectionBanner.vue +6 -5
- package/frontend-vue/app/chat/components/ConversationDrawer.vue +33 -27
- package/frontend-vue/app/chat/components/DiffView.vue +1 -1
- package/frontend-vue/app/chat/components/FoldBar.vue +34 -28
- package/frontend-vue/app/chat/components/MessageList.vue +10 -10
- package/frontend-vue/app/chat/components/NoticeCard.vue +17 -17
- package/frontend-vue/app/chat/components/PanelHeader.vue +16 -15
- package/frontend-vue/app/chat/components/PermissionCard.vue +11 -11
- package/frontend-vue/app/chat/components/PlanCard.vue +5 -5
- package/frontend-vue/app/chat/components/ProviderNotice.vue +6 -4
- package/frontend-vue/app/chat/components/QuestionDock.vue +13 -10
- package/frontend-vue/app/chat/components/QueueDock.vue +17 -15
- package/frontend-vue/app/chat/components/RulesList.vue +9 -5
- package/frontend-vue/app/chat/components/StepsDock.vue +2 -2
- package/frontend-vue/app/chat/components/ToolCluster.vue +3 -3
- package/frontend-vue/app/chat/components/ToolRow.vue +4 -4
- package/frontend-vue/app/chat/components/TurnErrorCard.vue +5 -5
- package/frontend-vue/app/chat/components/UndoConflictModal.vue +4 -4
- package/frontend-vue/app/chat/components/chat-tokens.css +83 -0
- package/frontend-vue/app/chat/composables/useChatI18n.ts +2 -1
- package/frontend-vue/app/chat/composables/useComposerAttachments.ts +3 -3
- package/frontend-vue/app/chat/constants/conversation.ts +4 -4
- package/frontend-vue/app/chat/constants/protocol.ts +2 -1
- package/frontend-vue/app/chat/constants/run-status.ts +6 -6
- package/frontend-vue/app/chat/types/protocol.ts +0 -7
- package/frontend-vue/app/chat/utils/permission-view.ts +44 -36
- package/frontend-vue/app/chat/utils/status-label.ts +7 -5
- package/frontend-vue/app/chat/utils/suggestions.ts +9 -9
- package/frontend-vue/app/chat/utils/tool-lexicon.ts +4 -4
- package/frontend-vue/app/components/ActivityDetail.vue +15 -13
- package/frontend-vue/app/components/ChangesView.vue +20 -20
- package/frontend-vue/app/components/ChatPanel.vue +31 -31
- package/frontend-vue/app/components/LauncherIcon.vue +44 -38
- package/frontend-vue/app/components/Onboarding.vue +3 -3
- package/frontend-vue/app/components/OnboardingWidget.vue +8 -4
- package/frontend-vue/app/components/PaletteAnswer.vue +27 -23
- package/frontend-vue/app/onboarding/analysis-lead.ts +66 -0
- package/frontend-vue/app/onboarding/connect-database.ts +92 -21
- package/frontend-vue/app/onboarding/connect-memory.ts +204 -0
- package/frontend-vue/app/onboarding/controller.ts +44 -6
- package/frontend-vue/app/onboarding/install.ts +7 -2
- package/frontend-vue/app/onboarding/runtime.ts +4 -4
- package/frontend-vue/app/plugins/ai.client.ts +8 -8
- package/frontend-vue/app/plugins/side-panel.ts +1 -1
- package/frontend-vue/app/runtime/assistant-actions.ts +6 -4
- package/frontend-vue/app/runtime/assistant-commands.ts +31 -16
- package/frontend-vue/app/runtime/assistant-notifications.ts +17 -9
- package/frontend-vue/app/runtime/assistant-session.ts +1 -1
- package/frontend-vue/app/runtime/channel-client.ts +1 -1
- package/frontend-vue/app/runtime/constants.ts +11 -11
- package/frontend-vue/app/runtime/sidecar-status.ts +1 -1
- package/frontend-vue/app/views/ChangeSetPanel.vue +20 -20
- package/frontend-vue/app/views/DecisionLabel.vue +1 -1
- package/frontend-vue/app/views/DiffView.vue +6 -6
- package/frontend-vue/app/views/ResultPill.vue +4 -2
- package/frontend-vue/app/views/RowStepper.vue +3 -3
- package/frontend-vue/app/views/UnavailableState.vue +5 -5
- package/frontend-vue/app/views/composables/useAiData.ts +1 -1
- package/frontend-vue/app/views/composables/useChangeSetActions.ts +13 -5
- package/frontend-vue/app/views/composables/useViewFormat.ts +1 -1
- package/frontend-vue/app/views/constants.ts +0 -1
- package/frontend-vue/app/views/onboarding/OnboardingAi.vue +15 -15
- package/frontend-vue/app/views/onboarding/OnboardingAnalysis.vue +13 -13
- package/frontend-vue/app/views/onboarding/OnboardingClaude.vue +14 -14
- package/frontend-vue/app/views/onboarding/OnboardingCodex.vue +11 -11
- package/frontend-vue/app/views/onboarding/OnboardingConnected.vue +4 -4
- package/frontend-vue/app/views/onboarding/OnboardingContinue.vue +18 -18
- package/frontend-vue/app/views/onboarding/OnboardingDatabase.vue +37 -33
- package/frontend-vue/app/views/onboarding/OnboardingDontShow.vue +1 -1
- package/frontend-vue/app/views/onboarding/OnboardingPaths.vue +7 -7
- package/frontend-vue/app/views/onboarding/OnboardingReady.vue +5 -5
- package/frontend-vue/app/views/onboarding/OnboardingScratch.vue +9 -9
- package/frontend-vue/app/views/onboarding/OnboardingWelcome.vue +11 -11
- package/frontend-vue/app/views/onboarding/login-text.ts +6 -6
- package/frontend-vue/app/views/types.ts +0 -1
- package/frontend-vue/app/views/utils/moment.ts +2 -2
- package/frontend-vue/builder/app/runtime/api.ts +2 -0
- package/frontend-vue/builder/app/runtime/database-build.ts +23 -1
- package/frontend-vue/builder/app/runtime/database-connect.ts +5 -0
- package/frontend-vue/builder/tests/database-connect.test.ts +1 -1
- package/frontend-vue/dms.frontend.ts +2 -2
- package/frontend-vue/i18n/locales/builder-en-GB.json +1 -1
- package/frontend-vue/i18n/locales/builder-fr-FR.json +1 -1
- package/frontend-vue/i18n/locales/{dms-ai-pages-en-GB.json → dms-assistant-pages-en-GB.json} +2 -3
- package/frontend-vue/i18n/locales/{dms-ai-pages-fr-FR.json → dms-assistant-pages-fr-FR.json} +2 -3
- package/frontend-vue/i18n/locales/{dms-ai-panel-en-GB.json → dms-assistant-panel-en-GB.json} +1 -2
- package/frontend-vue/i18n/locales/{dms-ai-panel-fr-FR.json → dms-assistant-panel-fr-FR.json} +1 -2
- package/frontend-vue/i18n/locales/{dms-ai-views-en-GB.json → dms-assistant-views-en-GB.json} +2 -3
- package/frontend-vue/i18n/locales/{dms-ai-views-fr-FR.json → dms-assistant-views-fr-FR.json} +2 -3
- package/frontend-vue/package.json +2 -2
- package/frontend-vue/pnpm-lock.yaml +71 -21
- package/frontend-vue/tests/chat/block-target.test.ts +1 -1
- package/frontend-vue/tests/chat/build-view.test.ts +9 -5
- package/frontend-vue/tests/chat/chat-scroll.test.ts +1 -1
- package/frontend-vue/tests/chat/held-card.test.ts +2 -2
- package/frontend-vue/tests/chat/provider-notice.test.ts +1 -1
- package/frontend-vue/tests/chat/tool-lexicon.test.ts +16 -10
- package/frontend-vue/tests/chat-panel.test.ts +10 -10
- package/frontend-vue/tests/chat-transport.test.ts +1 -1
- package/frontend-vue/tests/launcher-icon.test.ts +1 -1
- package/frontend-vue/tests/launcher-label.test.ts +40 -0
- package/frontend-vue/tests/onboarding-connect-memory.test.ts +126 -0
- package/frontend-vue/tests/onboarding-controller-restart.test.ts +134 -0
- package/frontend-vue/tests/onboarding-controller.test.ts +58 -0
- package/frontend-vue/tests/onboarding-database-engines.test.ts +2 -2
- package/frontend-vue/tests/onboarding-database-new-url.test.ts +174 -0
- package/frontend-vue/tests/onboarding-database-reload.test.ts +229 -0
- package/frontend-vue/tests/onboarding-database-tabs.test.ts +184 -0
- package/frontend-vue/tests/onboarding-database.test.ts +13 -118
- package/frontend-vue/tests/palette-assistant.test.ts +8 -8
- package/frontend-vue/tests/panel-approvals.test.ts +1 -1
- package/frontend-vue/tests/panel-closed-conversation.test.ts +53 -0
- package/frontend-vue/tests/panel-mockup-prompt.test.ts +2 -2
- package/frontend-vue/tests/panel-modes.test.ts +1 -16
- package/frontend-vue/tests/panel-questions.test.ts +1 -1
- package/frontend-vue/tests/panel-states.test.ts +1 -1
- package/frontend-vue/tests/panel-tools.test.ts +2 -2
- package/frontend-vue/tests/sidecar-guest.test.ts +1 -1
- package/frontend-vue/tests/support/api-error-presenter.ts +4 -2
- package/frontend-vue/tests/support/database-connect.ts +129 -0
- package/frontend-vue/tests/support/i18n.ts +1 -1
- package/frontend-vue/tests/support/onboarding-host.ts +1 -0
- package/frontend-vue/tests/support/onboarding.ts +29 -1
- package/frontend-vue/tests/views/api-data-reads.test.ts +7 -3
- package/frontend-vue/tests/views/diff-view.test.ts +4 -2
- package/package.json +5 -8
- package/sidecar/dist/agent/permission-bus.d.ts +1 -0
- package/sidecar/dist/agent/permission-bus.js +1 -0
- package/sidecar/dist/agent/permission-bus.js.map +1 -1
- package/sidecar/dist/agent/question-bus.d.ts +1 -0
- package/sidecar/dist/agent/question-bus.js +3 -0
- package/sidecar/dist/agent/question-bus.js.map +1 -1
- package/sidecar/dist/audit/activity-query.js +0 -1
- package/sidecar/dist/audit/activity-query.js.map +1 -1
- package/sidecar/dist/audit/activity.js +11 -3
- package/sidecar/dist/audit/activity.js.map +1 -1
- package/sidecar/dist/constants/audit.d.ts +1 -1
- package/sidecar/dist/constants/audit.js +0 -1
- package/sidecar/dist/constants/audit.js.map +1 -1
- package/sidecar/dist/constants/chatgpt.d.ts +7 -7
- package/sidecar/dist/constants/chatgpt.js +6 -6
- package/sidecar/dist/constants/chatgpt.js.map +1 -1
- package/sidecar/dist/constants/checkpoints.d.ts +2 -2
- package/sidecar/dist/constants/checkpoints.js +2 -2
- package/sidecar/dist/constants/checkpoints.js.map +1 -1
- package/sidecar/dist/constants/codex.d.ts +9 -9
- package/sidecar/dist/constants/codex.js +8 -8
- package/sidecar/dist/constants/codex.js.map +1 -1
- package/sidecar/dist/constants/daemon.d.ts +2 -2
- package/sidecar/dist/constants/daemon.js +2 -2
- package/sidecar/dist/constants/daemon.js.map +1 -1
- package/sidecar/dist/constants/env.d.ts +1 -1
- package/sidecar/dist/constants/env.js +1 -1
- package/sidecar/dist/constants/env.js.map +1 -1
- package/sidecar/dist/constants/mcp.d.ts +4 -4
- package/sidecar/dist/constants/mcp.js +2 -2
- package/sidecar/dist/constants/mcp.js.map +1 -1
- package/sidecar/dist/constants/paths.d.ts +1 -1
- package/sidecar/dist/constants/paths.js +5 -1
- package/sidecar/dist/constants/paths.js.map +1 -1
- package/sidecar/dist/constants/preview.d.ts +2 -2
- package/sidecar/dist/constants/preview.js +2 -17
- package/sidecar/dist/constants/preview.js.map +1 -1
- package/sidecar/dist/constants/providers.d.ts +2 -2
- package/sidecar/dist/constants/providers.js +2 -2
- package/sidecar/dist/constants/providers.js.map +1 -1
- package/sidecar/dist/constants/settings.d.ts +1 -1
- package/sidecar/dist/constants/settings.js +1 -1
- package/sidecar/dist/constants/settings.js.map +1 -1
- package/sidecar/dist/constants/skills.d.ts +1 -1
- package/sidecar/dist/constants/skills.js +1 -1
- package/sidecar/dist/constants/skills.js.map +1 -1
- package/sidecar/dist/constants/state.d.ts +2 -1
- package/sidecar/dist/constants/state.js +2 -1
- package/sidecar/dist/constants/state.js.map +1 -1
- package/sidecar/dist/constants/tool-titles.d.ts +0 -40
- package/sidecar/dist/constants/tool-titles.js +0 -42
- package/sidecar/dist/constants/tool-titles.js.map +1 -1
- package/sidecar/dist/index.js +5 -6
- package/sidecar/dist/index.js.map +1 -1
- package/sidecar/dist/mcp/tools/preview-blocks.js +24 -19
- package/sidecar/dist/mcp/tools/preview-blocks.js.map +1 -1
- package/sidecar/dist/mcp/types.d.ts +1 -1
- package/sidecar/dist/prompts/agent.js +1 -1
- package/sidecar/dist/prompts/agent.js.map +1 -1
- package/sidecar/dist/protocol/events.d.ts +10 -28
- package/sidecar/dist/protocol/events.js +7 -5
- package/sidecar/dist/protocol/events.js.map +1 -1
- package/sidecar/dist/protocol/preview.js +1 -1
- package/sidecar/dist/protocol/preview.js.map +1 -1
- package/sidecar/dist/providers/codex/permission-profiles.d.ts +1 -1
- package/sidecar/dist/providers/codex/permission-profiles.js +1 -1
- package/sidecar/dist/providers/codex/permission-profiles.js.map +1 -1
- package/sidecar/dist/server/chat-socket-registry.d.ts +1 -0
- package/sidecar/dist/server/chat-socket-registry.js +14 -0
- package/sidecar/dist/server/chat-socket-registry.js.map +1 -1
- package/sidecar/dist/server/host-command-router.d.ts +9 -2
- package/sidecar/dist/server/host-command-router.js +5 -2
- package/sidecar/dist/server/host-command-router.js.map +1 -1
- package/sidecar/dist/server/host-page.d.ts +3 -0
- package/sidecar/dist/server/host-page.js +5 -0
- package/sidecar/dist/server/host-page.js.map +1 -0
- package/sidecar/dist/server/host-socket-registry.d.ts +1 -1
- package/sidecar/dist/server/host-socket-registry.js +6 -6
- package/sidecar/dist/server/host-socket-registry.js.map +1 -1
- package/sidecar/dist/server/routing.js +62 -20
- package/sidecar/dist/server/routing.js.map +1 -1
- package/sidecar/dist/server/turns.js +11 -3
- package/sidecar/dist/server/turns.js.map +1 -1
- package/sidecar/dist/server/ws.js +10 -2
- package/sidecar/dist/server/ws.js.map +1 -1
- package/sidecar/dist/skills/plugin-wrapper.js +1 -1
- package/sidecar/dist/skills/plugin-wrapper.js.map +1 -1
- package/sidecar/dist/state/conversations.d.ts +3 -1
- package/sidecar/dist/state/conversations.js +54 -3
- package/sidecar/dist/state/conversations.js.map +1 -1
- package/sidecar/dist/state/host-state.d.ts +2 -2
- package/sidecar/dist/state/host-state.js +6 -6
- package/sidecar/dist/state/host-state.js.map +1 -1
- package/sidecar/dist/state/settings-store.js +1 -14
- package/sidecar/dist/state/settings-store.js.map +1 -1
- package/sidecar/dist/state/store.d.ts +1 -0
- package/sidecar/dist/state/store.js +16 -9
- package/sidecar/dist/state/store.js.map +1 -1
- package/sidecar/dist/state/stored-schemas.js +0 -4
- package/sidecar/dist/state/stored-schemas.js.map +1 -1
- package/sidecar/dist/state/types.d.ts +2 -5
- package/sidecar/dist/state/types.js.map +1 -1
- package/sidecar/package.json +3 -2
- package/skills/{dms-ai → dms-assistant}/SKILL.md +6 -6
- package/skills/{dms-ai → dms-assistant}/cases.json +13 -13
- package/skills/{dms-ai-code-mode → dms-assistant-code-mode}/SKILL.md +7 -7
- package/skills/{dms-ai-code-mode → dms-assistant-code-mode}/cases.json +11 -11
- package/dist/lifecycle/builder-settings-move.d.ts +0 -1
- package/dist/lifecycle/builder-settings-move.js +0 -182
- package/dist/lifecycle/builder-settings-move.js.map +0 -1
- package/dist/lifecycle/builder-settings-plan.d.ts +0 -59
- package/dist/lifecycle/builder-settings-plan.js +0 -176
- package/dist/lifecycle/builder-settings-plan.js.map +0 -1
- package/dist/lifecycle/builder-settings-text.d.ts +0 -19
- package/dist/lifecycle/builder-settings-text.js +0 -82
- package/dist/lifecycle/builder-settings-text.js.map +0 -1
- package/dist/lifecycle/entry-verdict.d.ts +0 -15
- package/dist/lifecycle/entry-verdict.js +0 -30
- package/dist/lifecycle/entry-verdict.js.map +0 -1
- package/dist/lifecycle/environment-bindings.d.ts +0 -8
- package/dist/lifecycle/environment-bindings.js +0 -154
- package/dist/lifecycle/environment-bindings.js.map +0 -1
- package/dist/lifecycle/legacy-entries.d.ts +0 -8
- package/dist/lifecycle/legacy-entries.js +0 -126
- package/dist/lifecycle/legacy-entries.js.map +0 -1
- package/sidecar/dist/mcp/sketch-refusals.d.ts +0 -2
- package/sidecar/dist/mcp/sketch-refusals.js +0 -6
- package/sidecar/dist/mcp/sketch-refusals.js.map +0 -1
- package/sidecar/dist/state/legacy-tool-names.d.ts +0 -3
- package/sidecar/dist/state/legacy-tool-names.js +0 -34
- package/sidecar/dist/state/legacy-tool-names.js.map +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,229 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
});
|