mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 07:57:40 +00:00
Tests: stabilize provider runtime contract imports
This commit is contained in:
@@ -55,7 +55,7 @@ vi.mock(providerRuntimeContractModules.openAICodexProviderRuntimeModuleId, () =>
|
||||
}));
|
||||
|
||||
async function importBundledProviderPlugin<T>(moduleUrl: string): Promise<T> {
|
||||
return (await import(`${moduleUrl}?t=${Date.now()}`)) as T;
|
||||
return (await import(moduleUrl)) as T;
|
||||
}
|
||||
|
||||
function createModel(overrides: Partial<ProviderRuntimeModel> & Pick<ProviderRuntimeModel, "id">) {
|
||||
@@ -156,6 +156,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
|
||||
] as const;
|
||||
|
||||
const providerRuntimeContractProviders = new Map<string, ProviderPlugin>();
|
||||
let providerRuntimeContractLoadPromise: Promise<void> | null = null;
|
||||
|
||||
function requireProviderContractProvider(providerId: string): ProviderPlugin {
|
||||
const provider = providerRuntimeContractProviders.get(providerId);
|
||||
@@ -165,32 +166,42 @@ function requireProviderContractProvider(providerId: string): ProviderPlugin {
|
||||
return provider;
|
||||
}
|
||||
|
||||
async function ensureProviderRuntimeContractProvidersLoaded() {
|
||||
if (!providerRuntimeContractLoadPromise) {
|
||||
providerRuntimeContractLoadPromise = (async () => {
|
||||
providerRuntimeContractProviders.clear();
|
||||
const registeredFixtures = await Promise.all(
|
||||
PROVIDER_RUNTIME_CONTRACT_FIXTURES.map(async (fixture) => {
|
||||
const plugin = await fixture.load();
|
||||
return {
|
||||
fixture,
|
||||
providers: (
|
||||
await registerProviderPlugin({
|
||||
plugin: plugin.default,
|
||||
id: fixture.pluginId,
|
||||
name: fixture.name,
|
||||
})
|
||||
).providers,
|
||||
};
|
||||
}),
|
||||
);
|
||||
for (const { fixture, providers } of registeredFixtures) {
|
||||
for (const providerId of fixture.providerIds) {
|
||||
providerRuntimeContractProviders.set(
|
||||
providerId,
|
||||
requireRegisteredProvider(providers, providerId, "provider"),
|
||||
);
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
await providerRuntimeContractLoadPromise;
|
||||
}
|
||||
|
||||
function installRuntimeHooks() {
|
||||
beforeAll(async () => {
|
||||
providerRuntimeContractProviders.clear();
|
||||
const registeredFixtures = await Promise.all(
|
||||
PROVIDER_RUNTIME_CONTRACT_FIXTURES.map(async (fixture) => {
|
||||
const plugin = await fixture.load();
|
||||
return {
|
||||
fixture,
|
||||
providers: (
|
||||
await registerProviderPlugin({
|
||||
plugin: plugin.default,
|
||||
id: fixture.pluginId,
|
||||
name: fixture.name,
|
||||
})
|
||||
).providers,
|
||||
};
|
||||
}),
|
||||
);
|
||||
for (const { fixture, providers } of registeredFixtures) {
|
||||
for (const providerId of fixture.providerIds) {
|
||||
providerRuntimeContractProviders.set(
|
||||
providerId,
|
||||
requireRegisteredProvider(providers, providerId, "provider"),
|
||||
);
|
||||
}
|
||||
}
|
||||
await ensureProviderRuntimeContractProvidersLoaded();
|
||||
}, CONTRACT_SETUP_TIMEOUT_MS);
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user