feat(FN-3053): consolidate mock helpers across CLI, dashboard, and engine p

The merge consolidates mock helpers across packages by creating a new shared `mockCoreEngine.ts` in the CLI package and strengthening the core/engine helpers, then migrating both CLI command tests and the dashboard's `AgentsView` tests to use the canonical helpers. It also publishes SSE architecture

Fusion-Task-Id: FN-3053
This commit is contained in:
Fusion
2026-05-01 05:02:16 -07:00
committed by gsxdsm
parent 5e51542a1d
commit eaf9d6adf9
10 changed files with 226 additions and 47 deletions

View File

@@ -1,21 +1,45 @@
/**
* Canonical @fusion/core mock helper for engine tests.
*
* Prefer extending this helper over suite-local full export lists.
* Prefer extending this helper over suite-local full export lists; this is the
* first place to update when new @fusion/core exports are consumed by engine tests.
*/
import type { Mock } from "vitest";
import { vi, type Mock } from "vitest";
type AnyModule = Record<string, unknown>;
const fallbackFns = new Map<string, Mock>();
function getFallback(name: string): Mock {
if (!fallbackFns.has(name)) fallbackFns.set(name, vi.fn());
return fallbackFns.get(name)!;
}
export async function createEngineCoreMock(
importActual: () => Promise<AnyModule>,
overrides: AnyModule = {},
): Promise<AnyModule> {
const actual = await importActual();
return {
...actual,
...overrides,
};
const merged = { ...actual, ...overrides };
return new Proxy(merged, {
get(target, prop, receiver) {
if (typeof prop !== "string") return Reflect.get(target, prop, receiver);
if (Reflect.has(target, prop)) return Reflect.get(target, prop, receiver);
if (["then", "catch", "finally"].includes(prop)) return undefined;
const actualValue = actual[prop];
if (typeof actualValue === "function" || actualValue === undefined) {
const fn = getFallback(prop);
target[prop] = fn;
return fn;
}
return actualValue;
},
});
}
export function resetEngineCoreMockState(): void {
for (const fn of fallbackFns.values()) fn.mockReset();
}
export type MockFn = Mock;