Share a warmed Pi model runtime across engine catalog tests. - Add an isolated in-memory model registry fixture backed by a per-file shared runtime. - Warm the runtime before catalog tests and verify custom-provider registry isolation. - Document the required fixture pattern for real Pi SDK catalog tests. Files changed: docs/testing.md | 1 + .../engine/src/__tests__/_model-runtime-fixture.ts | 40 ++++++++++++++++++++++ .../custom-providers-openai-completions.test.ts | 15 +++----- .../custom-providers-openai-responses.test.ts | 15 +++----- .../src/__tests__/provider-registration.test.ts | 33 ++++++++++++------ 5 files changed, 73 insertions(+), 31 deletions(-) Fusion-Task-Id: FN-8670 Fusion-Task-Lineage: 7410d114-1853-44cc-a09b-a997fbc7f119 Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { ModelRegistry, ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
|
|
/*
|
|
FNXC:ModelCatalog 2026-08-01-08:14:
|
|
FN-8670 moves real Pi SDK catalog construction out of timed test bodies into beforeAll. The runtime is
|
|
memoized per test file because Vitest file-level isolation gives each file its own module graph.
|
|
ModelRegistry.registerProvider writes into its shared ModelRuntime, so each handed-out registry clears
|
|
prior extension providers before use. The SDK remains real, not stubbed, because this coverage catches
|
|
catalog regressions such as FN-8564's native Kimi K3; widening timeouts or adding retries is forbidden here.
|
|
*/
|
|
let sharedModelRuntime: Promise<ModelRuntime> | undefined;
|
|
|
|
export function getSharedModelRuntime(): Promise<ModelRuntime> {
|
|
sharedModelRuntime ??= ModelRuntime.create({
|
|
credentials: {
|
|
read: async () => undefined,
|
|
list: async () => [],
|
|
modify: async (_id, fn) => fn(undefined),
|
|
delete: async () => undefined,
|
|
},
|
|
modelsPath: null,
|
|
allowModelNetwork: false,
|
|
});
|
|
return sharedModelRuntime;
|
|
}
|
|
|
|
export async function warmSharedModelRuntime(): Promise<void> {
|
|
await getSharedModelRuntime();
|
|
}
|
|
|
|
export async function createInMemoryModelRegistry(): Promise<ModelRegistry> {
|
|
const modelRegistry = new ModelRegistry(await getSharedModelRuntime());
|
|
|
|
for (const providerId of modelRegistry.getRegisteredProviderIds()) {
|
|
modelRegistry.unregisterProvider(providerId);
|
|
}
|
|
await modelRegistry.refresh();
|
|
|
|
return modelRegistry;
|
|
}
|