mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 11:50:20 +00:00
test: harden no-isolate test module resets
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { PluginWebSearchProviderEntry } from "../plugins/types.js";
|
||||
import * as bundledWebSearchProviders from "../plugins/web-search-providers.js";
|
||||
import * as runtimeWebSearchProviders from "../plugins/web-search-providers.runtime.js";
|
||||
import * as secretResolve from "./resolve.js";
|
||||
import { createResolverContext } from "./runtime-shared.js";
|
||||
import { resolveRuntimeWebTools } from "./runtime-web-tools.js";
|
||||
|
||||
type ProviderUnderTest = "brave" | "gemini" | "grok" | "kimi" | "perplexity" | "duckduckgo";
|
||||
|
||||
@@ -22,6 +17,12 @@ const mockedModuleIds = [
|
||||
"../plugins/web-search-providers.runtime.js",
|
||||
] as const;
|
||||
|
||||
let bundledWebSearchProviders: typeof import("../plugins/web-search-providers.js");
|
||||
let runtimeWebSearchProviders: typeof import("../plugins/web-search-providers.runtime.js");
|
||||
let secretResolve: typeof import("./resolve.js");
|
||||
let createResolverContext: typeof import("./runtime-shared.js").createResolverContext;
|
||||
let resolveRuntimeWebTools: typeof import("./runtime-web-tools.js").resolveRuntimeWebTools;
|
||||
|
||||
vi.mock("../plugins/web-search-providers.js", () => ({
|
||||
resolveBundledPluginWebSearchProviders: resolveBundledPluginWebSearchProvidersMock,
|
||||
}));
|
||||
@@ -194,7 +195,13 @@ function expectInactiveFirecrawlSecretRef(params: {
|
||||
}
|
||||
|
||||
describe("runtime web tools resolution", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
bundledWebSearchProviders = await import("../plugins/web-search-providers.js");
|
||||
runtimeWebSearchProviders = await import("../plugins/web-search-providers.runtime.js");
|
||||
secretResolve = await import("./resolve.js");
|
||||
({ createResolverContext } = await import("./runtime-shared.js"));
|
||||
({ resolveRuntimeWebTools } = await import("./runtime-web-tools.js"));
|
||||
vi.mocked(bundledWebSearchProviders.resolveBundledPluginWebSearchProviders).mockClear();
|
||||
vi.mocked(runtimeWebSearchProviders.resolvePluginWebSearchProviders).mockClear();
|
||||
});
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { AuthProfileStore } from "../agents/auth-profiles.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { PluginWebSearchProviderEntry } from "../plugins/types.js";
|
||||
import { getPath, setPathCreateStrict } from "./path-utils.js";
|
||||
import { clearSecretsRuntimeSnapshot, prepareSecretsRuntimeSnapshot } from "./runtime.js";
|
||||
import { listSecretTargetRegistryEntries } from "./target-registry.js";
|
||||
|
||||
type SecretRegistryEntry = ReturnType<typeof listSecretTargetRegistryEntries>[number];
|
||||
@@ -19,6 +18,9 @@ const mockedModuleIds = [
|
||||
"../plugins/web-search-providers.runtime.js",
|
||||
] as const;
|
||||
|
||||
let clearSecretsRuntimeSnapshot: typeof import("./runtime.js").clearSecretsRuntimeSnapshot;
|
||||
let prepareSecretsRuntimeSnapshot: typeof import("./runtime.js").prepareSecretsRuntimeSnapshot;
|
||||
|
||||
vi.mock("../plugins/web-search-providers.js", () => ({
|
||||
resolveBundledPluginWebSearchProviders: resolveBundledPluginWebSearchProvidersMock,
|
||||
}));
|
||||
@@ -251,6 +253,11 @@ describe("secrets runtime target coverage", () => {
|
||||
resolvePluginWebSearchProvidersMock.mockReset();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ clearSecretsRuntimeSnapshot, prepareSecretsRuntimeSnapshot } = await import("./runtime.js"));
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
for (const id of mockedModuleIds) {
|
||||
vi.doUnmock(id);
|
||||
|
||||
@@ -3,14 +3,8 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { AuthProfileStore } from "../agents/auth-profiles.js";
|
||||
import { clearConfigCache, type OpenClawConfig } from "../config/config.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { PluginWebSearchProviderEntry } from "../plugins/types.js";
|
||||
import {
|
||||
activateSecretsRuntimeSnapshot,
|
||||
clearSecretsRuntimeSnapshot,
|
||||
getActiveRuntimeWebToolsMetadata,
|
||||
prepareSecretsRuntimeSnapshot,
|
||||
} from "./runtime.js";
|
||||
|
||||
type WebProviderUnderTest = "brave" | "gemini" | "grok" | "kimi" | "perplexity" | "firecrawl";
|
||||
|
||||
@@ -103,6 +97,12 @@ function buildTestWebSearchProviders(): PluginWebSearchProviderEntry[] {
|
||||
|
||||
const OPENAI_ENV_KEY_REF = { source: "env", provider: "default", id: "OPENAI_API_KEY" } as const;
|
||||
|
||||
let clearConfigCache: typeof import("../config/config.js").clearConfigCache;
|
||||
let activateSecretsRuntimeSnapshot: typeof import("./runtime.js").activateSecretsRuntimeSnapshot;
|
||||
let clearSecretsRuntimeSnapshot: typeof import("./runtime.js").clearSecretsRuntimeSnapshot;
|
||||
let getActiveRuntimeWebToolsMetadata: typeof import("./runtime.js").getActiveRuntimeWebToolsMetadata;
|
||||
let prepareSecretsRuntimeSnapshot: typeof import("./runtime.js").prepareSecretsRuntimeSnapshot;
|
||||
|
||||
function createOpenAiFileModelsConfig(): NonNullable<OpenClawConfig["models"]> {
|
||||
return {
|
||||
providers: {
|
||||
@@ -123,7 +123,15 @@ function loadAuthStoreWithProfiles(profiles: AuthProfileStore["profiles"]): Auth
|
||||
}
|
||||
|
||||
describe("secrets runtime snapshot", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ clearConfigCache } = await import("../config/config.js"));
|
||||
({
|
||||
activateSecretsRuntimeSnapshot,
|
||||
clearSecretsRuntimeSnapshot,
|
||||
getActiveRuntimeWebToolsMetadata,
|
||||
prepareSecretsRuntimeSnapshot,
|
||||
} = await import("./runtime.js"));
|
||||
resolveBundledPluginWebSearchProvidersMock.mockReset();
|
||||
resolveBundledPluginWebSearchProvidersMock.mockReturnValue(buildTestWebSearchProviders());
|
||||
resolvePluginWebSearchProvidersMock.mockReset();
|
||||
|
||||
Reference in New Issue
Block a user