diff --git a/src/secrets/runtime-inactive-core-surfaces.test.ts b/src/secrets/runtime-inactive-core-surfaces.test.ts index 5c3e713da0e..b0624bd9b44 100644 --- a/src/secrets/runtime-inactive-core-surfaces.test.ts +++ b/src/secrets/runtime-inactive-core-surfaces.test.ts @@ -1,30 +1,9 @@ -import { afterEach, beforeAll, describe, expect, it } from "vitest"; -import type { OpenClawConfig } from "../config/config.js"; -import { createEmptyPluginRegistry } from "../plugins/registry.js"; -import { setActivePluginRegistry } from "../plugins/runtime.js"; +import { describe, expect, it } from "vitest"; +import { asConfig, setupSecretsRuntimeSnapshotTestHooks } from "./runtime.test-support.ts"; -function asConfig(value: unknown): OpenClawConfig { - return value as OpenClawConfig; -} - -let clearConfigCache: typeof import("../config/config.js").clearConfigCache; -let clearRuntimeConfigSnapshot: typeof import("../config/config.js").clearRuntimeConfigSnapshot; -let clearSecretsRuntimeSnapshot: typeof import("./runtime.js").clearSecretsRuntimeSnapshot; -let prepareSecretsRuntimeSnapshot: typeof import("./runtime.js").prepareSecretsRuntimeSnapshot; +const { prepareSecretsRuntimeSnapshot } = setupSecretsRuntimeSnapshotTestHooks(); describe("secrets runtime snapshot inactive core surfaces", () => { - beforeAll(async () => { - ({ clearConfigCache, clearRuntimeConfigSnapshot } = await import("../config/config.js")); - ({ clearSecretsRuntimeSnapshot, prepareSecretsRuntimeSnapshot } = await import("./runtime.js")); - }); - - afterEach(() => { - setActivePluginRegistry(createEmptyPluginRegistry()); - clearSecretsRuntimeSnapshot(); - clearRuntimeConfigSnapshot(); - clearConfigCache(); - }); - it("skips inactive core refs and emits diagnostics", async () => { const snapshot = await prepareSecretsRuntimeSnapshot({ config: asConfig({ diff --git a/src/secrets/runtime.loadable-plugin-origins.test.ts b/src/secrets/runtime.loadable-plugin-origins.test.ts index fe11d9f4a63..ee8e6fc5ced 100644 --- a/src/secrets/runtime.loadable-plugin-origins.test.ts +++ b/src/secrets/runtime.loadable-plugin-origins.test.ts @@ -1,5 +1,5 @@ -import { afterEach, beforeAll, describe, expect, it, vi } from "vitest"; -import type { OpenClawConfig } from "../config/config.js"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import { asConfig, setupSecretsRuntimeSnapshotTestHooks } from "./runtime.test-support.ts"; const loadPluginManifestRegistry = vi.hoisted(() => vi.fn()); @@ -7,26 +7,11 @@ vi.mock("./runtime-manifest.runtime.js", () => ({ loadPluginManifestRegistry, })); -function asConfig(value: unknown): OpenClawConfig { - return value as OpenClawConfig; -} - -let clearConfigCache: typeof import("../config/config.js").clearConfigCache; -let clearRuntimeConfigSnapshot: typeof import("../config/config.js").clearRuntimeConfigSnapshot; -let clearSecretsRuntimeSnapshot: typeof import("./runtime.js").clearSecretsRuntimeSnapshot; -let prepareSecretsRuntimeSnapshot: typeof import("./runtime.js").prepareSecretsRuntimeSnapshot; +const { prepareSecretsRuntimeSnapshot } = setupSecretsRuntimeSnapshotTestHooks(); describe("prepareSecretsRuntimeSnapshot loadable plugin origins", () => { - beforeAll(async () => { - ({ clearConfigCache, clearRuntimeConfigSnapshot } = await import("../config/config.js")); - ({ clearSecretsRuntimeSnapshot, prepareSecretsRuntimeSnapshot } = await import("./runtime.js")); - }); - afterEach(() => { loadPluginManifestRegistry.mockReset(); - clearSecretsRuntimeSnapshot(); - clearRuntimeConfigSnapshot(); - clearConfigCache(); }); it("skips manifest registry loading when plugin entries are absent", async () => {