feat(FN-2620): add plugin test-time engine resolution stubs

- Add engine-guard-stub test modules for hermes, openclaw, and paperclip runtime plugins to fail fast on unmocked @fusion/engine imports
- Update each plugin Vitest config to alias @fusion/engine to the local guard stub during test runs
- Keep setup-engine-guard behavior while removing dependency on built engine dist artifacts for plugin-local tests
This commit is contained in:
Fusion
2026-04-26 21:49:47 -07:00
committed by gsxdsm
parent b56571e082
commit b918ba5ee6
6 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
/**
* Resolution stub for @fusion/engine in plugin test mode.
*
* Vitest resolves mocked module IDs before applying vi.mock factories. The
* real @fusion/engine workspace package points to dist outputs that are not
* built for plugin-local test runs, so we alias to this stub in vitest config.
*
* Any direct import of @fusion/engine in plugin tests should still fail fast.
*/
const guardError = () =>
new Error(
"Guard: @fusion/engine was imported without an explicit mock. Runtime plugin tests must mock '../pi-module.js' to prevent loading the real engine.",
);
export const createFnAgent = () => {
throw guardError();
};
export const promptWithFallback = async () => {
throw guardError();
};
export const describeModel = () => {
throw guardError();
};

View File

@@ -5,6 +5,8 @@ const requestedMaxWorkers = Number.parseInt(process.env.VITEST_MAX_WORKERS ?? "2
const maxWorkers = Math.max(1, Math.min(4, Number.isFinite(requestedMaxWorkers) ? requestedMaxWorkers : 2));
process.env.VITEST_MAX_WORKERS = String(maxWorkers);
const engineGuardStub = fileURLToPath(new URL("./src/__tests__/engine-guard-stub.ts", import.meta.url));
export default defineConfig({
resolve: {
alias: {
@@ -28,5 +30,10 @@ export default defineConfig({
// 3. Add a vi.mock("@fusion/engine", ...) override in the test file
// or a dedicated setup file to replace the throwing mock
setupFiles: ["./src/__tests__/setup-engine-guard.ts"],
alias: {
// Resolve @fusion/engine to a local test stub so Vitest can register the
// guard mock without requiring built dist artifacts from packages/engine.
"@fusion/engine": engineGuardStub,
},
},
});