test(secrets): reuse snapshot hooks in web state tests

This commit is contained in:
Vincent Koc
2026-04-12 04:27:34 +01:00
parent ea1d483fe6
commit 3d0ddccf73
2 changed files with 8 additions and 43 deletions

View File

@@ -1,10 +1,8 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import { describe, expect, it, vi } from "vitest";
import {
asConfig,
getResolvePluginWebSearchProvidersMock,
resetPluginWebSearchProvidersMock,
setupSecretsRuntimeSnapshotTestHooks,
} from "./runtime.test-support.ts";
vi.mock("../channels/plugins/bootstrap-registry.js", () => {
@@ -26,29 +24,10 @@ vi.mock("../channels/plugins/bootstrap-registry.js", () => {
};
});
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();
const EMPTY_LOADABLE_PLUGIN_ORIGINS = new Map();
describe("secrets runtime snapshot legacy x_search", () => {
beforeAll(async () => {
({ clearConfigCache, clearRuntimeConfigSnapshot } = await import("../config/config.js"));
({ clearSecretsRuntimeSnapshot, prepareSecretsRuntimeSnapshot } = await import("./runtime.js"));
});
beforeEach(() => {
resetPluginWebSearchProvidersMock();
});
afterEach(() => {
setActivePluginRegistry(createEmptyPluginRegistry());
clearSecretsRuntimeSnapshot();
clearRuntimeConfigSnapshot();
clearConfigCache();
});
it("keeps legacy x_search SecretRefs in place until doctor repairs them", async () => {
const snapshot = await prepareSecretsRuntimeSnapshot({
config: asConfig({

View File

@@ -1,6 +1,6 @@
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { beforeAll, describe, expect, it, vi } from "vitest";
import type { PluginWebSearchProviderEntry } from "../plugins/types.js";
import { asConfig } from "./runtime.test-support.ts";
import { asConfig, setupSecretsRuntimeSnapshotTestHooks } from "./runtime.test-support.ts";
const { resolvePluginWebSearchProvidersMock } = vi.hoisted(() => ({
resolvePluginWebSearchProvidersMock: vi.fn<() => PluginWebSearchProviderEntry[]>(() => [
@@ -39,28 +39,14 @@ vi.mock("../plugins/web-search-providers.runtime.js", () => ({
resolvePluginWebSearchProviders: resolvePluginWebSearchProvidersMock,
}));
let clearConfigCache: typeof import("../config/config.js").clearConfigCache;
let clearRuntimeConfigSnapshot: typeof import("../config/config.js").clearRuntimeConfigSnapshot;
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;
const { prepareSecretsRuntimeSnapshot } = setupSecretsRuntimeSnapshotTestHooks();
describe("runtime web tools state", () => {
beforeAll(async () => {
({ clearConfigCache, clearRuntimeConfigSnapshot } = await import("../config/config.js"));
({
activateSecretsRuntimeSnapshot,
clearSecretsRuntimeSnapshot,
getActiveRuntimeWebToolsMetadata,
prepareSecretsRuntimeSnapshot,
} = await import("./runtime.js"));
});
afterEach(() => {
clearSecretsRuntimeSnapshot();
clearRuntimeConfigSnapshot();
clearConfigCache();
({ activateSecretsRuntimeSnapshot, getActiveRuntimeWebToolsMetadata } =
await import("./runtime.js"));
});
it("exposes active runtime web tool metadata as a defensive clone", async () => {