test(plugins): avoid per-test discovery reloads

This commit is contained in:
Vincent Koc
2026-04-15 12:30:33 +01:00
parent 30895f7135
commit 78f0fb660c

View File

@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { AuthProfileStore } from "../../../src/agents/auth-profiles/types.js";
import type { OpenClawConfig } from "../../../src/config/config.js";
import type { ModelDefinitionConfig } from "../../../src/config/types.models.js";
@@ -171,15 +171,14 @@ function runCatalog(
}
async function importBundledProviderPlugin<T>(moduleUrl: string): Promise<T> {
return (await import(`${moduleUrl}?t=${Date.now()}`)) as T;
return (await import(moduleUrl)) as T;
}
function installDiscoveryHooks(
state: DiscoveryState,
providerIds: readonly BundledProviderUnderTest[],
) {
beforeEach(async () => {
vi.resetModules();
beforeAll(async () => {
vi.doMock("openclaw/plugin-sdk/agent-runtime", () => {
return {
ensureAuthProfileStore: ensureAuthProfileStoreMock,
@@ -315,7 +314,7 @@ function installDiscoveryHooks(
setRuntimeAuthStore();
});
afterEach(() => {
beforeEach(() => {
vi.restoreAllMocks();
resolveCopilotApiTokenMock.mockReset();
buildOllamaProviderMock.mockReset();
@@ -323,6 +322,7 @@ function installDiscoveryHooks(
buildSglangProviderMock.mockReset();
ensureAuthProfileStoreMock.mockReset();
listProfilesForProviderMock.mockReset();
setRuntimeAuthStore();
});
}