fix(startup): reduce initial loading and unblock app restoration
This commit is contained in:
23 files changed
+745
-123
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
settingsImported: vi.fn(),
|
||||
migrationStatus: vi.fn(),
|
||||
listInstalledAgents: vi.fn(),
|
||||
installAgent: vi.fn(),
|
||||
upgradeAllAgents: vi.fn(),
|
||||
reinstallJre: vi.fn(),
|
||||
}));
|
||||
vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => true }));
|
||||
vi.mock("@/lib/backend/tauri", () => mocks);
|
||||
vi.mock("@/lib/backend/debugLog", () => ({ appendDebugLog: vi.fn() }));
|
||||
|
||||
const settings = { editorSettings: { updateDownloadSource: "github" } };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.resetAllMocks();
|
||||
settings.editorSettings.updateDownloadSource = "github";
|
||||
vi.doMock("@/stores/settingsStore", () => {
|
||||
mocks.settingsImported();
|
||||
return { useSettingsStore: () => settings };
|
||||
});
|
||||
});
|
||||
|
||||
describe("startup API dependency boundary", () => {
|
||||
it("does not import the business settings store for migration preflight", async () => {
|
||||
mocks.migrationStatus.mockResolvedValue({ state: "not_required" });
|
||||
const api = await import("../api");
|
||||
await expect(api.migrationStatus()).resolves.toEqual({ state: "not_required" });
|
||||
expect(mocks.settingsImported).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("continues using the current configured source for agent operations", async () => {
|
||||
const api = await import("../api");
|
||||
await api.listInstalledAgents();
|
||||
expect(mocks.listInstalledAgents).toHaveBeenCalledWith("github");
|
||||
settings.editorSettings.updateDownloadSource = "cloudflare";
|
||||
await api.installAgent("mysql", "install-1");
|
||||
await api.upgradeAllAgents("upgrade-1");
|
||||
await api.reinstallJre("java-21", "jre-1");
|
||||
expect(mocks.installAgent).toHaveBeenCalledWith("mysql", "cloudflare", "install-1");
|
||||
expect(mocks.upgradeAllAgents).toHaveBeenCalledWith("cloudflare", "upgrade-1");
|
||||
expect(mocks.reinstallJre).toHaveBeenCalledWith("java-21", "cloudflare", "jre-1");
|
||||
expect(mocks.settingsImported).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,6 @@
|
||||
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
|
||||
import type * as TauriModule from "@/lib/backend/tauri";
|
||||
import { appendDebugLog } from "@/lib/backend/debugLog";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import type { AiConfigItem } from "@/types/ai";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -135,6 +134,7 @@ export const uninstallJdbcPlugin = forward("uninstallJdbcPlugin");
|
||||
export const listInstalledAgentsLocal = forward("listInstalledAgentsLocal");
|
||||
export async function listInstalledAgents() {
|
||||
const backend = await getBackend();
|
||||
const { useSettingsStore } = await import("@/stores/settingsStore");
|
||||
return backend.listInstalledAgents(useSettingsStore().editorSettings.updateDownloadSource);
|
||||
}
|
||||
export const isAgentInstalled = forward("isAgentInstalled");
|
||||
@@ -145,10 +145,12 @@ export const stopDriverRuntime = forward("stopDriverRuntime");
|
||||
export const restartDriverRuntime = forward("restartDriverRuntime");
|
||||
export async function installAgent(dbType: string, operationId?: string) {
|
||||
const backend = await getBackend();
|
||||
const { useSettingsStore } = await import("@/stores/settingsStore");
|
||||
return backend.installAgent(dbType, useSettingsStore().editorSettings.updateDownloadSource, operationId);
|
||||
}
|
||||
export async function upgradeAllAgents(operationId?: string) {
|
||||
const backend = await getBackend();
|
||||
const { useSettingsStore } = await import("@/stores/settingsStore");
|
||||
return backend.upgradeAllAgents(useSettingsStore().editorSettings.updateDownloadSource, operationId);
|
||||
}
|
||||
export const cancelAgentInstall = forward("cancelAgentInstall");
|
||||
@@ -168,6 +170,7 @@ export const importAgentDriver = forward("importAgentDriver");
|
||||
export const importAgentJar = importAgentDriver;
|
||||
export async function reinstallJre(jreKey?: string, operationId?: string) {
|
||||
const backend = await getBackend();
|
||||
const { useSettingsStore } = await import("@/stores/settingsStore");
|
||||
return backend.reinstallJre(jreKey, useSettingsStore().editorSettings.updateDownloadSource, operationId);
|
||||
}
|
||||
export const uninstallJre = forward("uninstallJre");
|
||||
|
||||
Reference in new issue
Block a user