test: harden no-isolate test module resets

This commit is contained in:
Peter Steinberger
2026-03-23 01:02:08 -07:00
parent 771a78cc77
commit 9105b3723d
22 changed files with 126 additions and 100 deletions

View File

@@ -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);