feat(FN-3044): add canonical mock helpers and migrate representative test s
This merge introduces canonical mock helper modules across the dashboard and engine packages, and migrates representative test suites to use them for consistency. The changes add four new mock helpers (`mockApi.ts`, `mockLucide.ts`, `mockCore.ts`, `mockCoreEngine.ts`) and harden the API mock proxy's Fusion-Task-Id: FN-3044
This commit is contained in:
@@ -5,11 +5,9 @@ import {
|
||||
createTaskDocumentWriteTool,
|
||||
} from "../agent-tools.js";
|
||||
|
||||
vi.mock("@fusion/core", async () => {
|
||||
const actual = await vi.importActual("@fusion/core");
|
||||
return {
|
||||
...actual,
|
||||
};
|
||||
vi.mock("@fusion/core", async (importOriginal) => {
|
||||
const { createEngineCoreMock } = await import("../test/mockCore.js");
|
||||
return createEngineCoreMock(() => importOriginal<typeof import("@fusion/core")>());
|
||||
});
|
||||
|
||||
const TASK_ID = "FN-1272";
|
||||
|
||||
@@ -25,19 +25,18 @@ const mocks = vi.hoisted(() => ({
|
||||
notificationServiceStop: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@fusion/core", async () => {
|
||||
class MockAutomationStore {
|
||||
constructor(_cwd: string) {}
|
||||
vi.mock("@fusion/core", async (importOriginal) => {
|
||||
const { createEngineCoreMock } = await import("../test/mockCore.js");
|
||||
return createEngineCoreMock(() => importOriginal<typeof import("@fusion/core")>(), {
|
||||
AutomationStore: class MockAutomationStore {
|
||||
constructor(_cwd: string) {}
|
||||
|
||||
init = mocks.automationStoreInit;
|
||||
}
|
||||
|
||||
return {
|
||||
AutomationStore: MockAutomationStore,
|
||||
init = mocks.automationStoreInit;
|
||||
},
|
||||
syncInsightExtractionAutomation: mocks.syncInsightExtractionAutomation,
|
||||
syncAutoSummarizeAutomation: mocks.syncAutoSummarizeAutomation,
|
||||
syncMemoryDreamsAutomation: mocks.syncMemoryDreamsAutomation,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
vi.mock("../cron-runner.js", () => {
|
||||
|
||||
@@ -29,12 +29,11 @@ vi.mock("../pi.js", () => ({
|
||||
promptWithFallback: vi.fn().mockReturnValue("mock-prompt"),
|
||||
}));
|
||||
|
||||
vi.mock("@fusion/core", async () => {
|
||||
const actual = await vi.importActual("@fusion/core");
|
||||
return {
|
||||
...actual,
|
||||
vi.mock("@fusion/core", async (importOriginal) => {
|
||||
const { createEngineCoreMock } = await import("../test/mockCore.js");
|
||||
return createEngineCoreMock(() => importOriginal<typeof import("@fusion/core")>(), {
|
||||
resolveAgentPrompt: vi.fn().mockReturnValue(null),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
async function createTriageFixtureRoot(prefix: string): Promise<string> {
|
||||
|
||||
21
packages/engine/src/test/mockCore.ts
Normal file
21
packages/engine/src/test/mockCore.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Canonical @fusion/core mock helper for engine tests.
|
||||
*
|
||||
* Prefer extending this helper over suite-local full export lists.
|
||||
*/
|
||||
import type { Mock } from "vitest";
|
||||
|
||||
type AnyModule = Record<string, unknown>;
|
||||
|
||||
export async function createEngineCoreMock(
|
||||
importActual: () => Promise<AnyModule>,
|
||||
overrides: AnyModule = {},
|
||||
): Promise<AnyModule> {
|
||||
const actual = await importActual();
|
||||
return {
|
||||
...actual,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export type MockFn = Mock;
|
||||
Reference in New Issue
Block a user