import os from "node:os"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { withTempHome } from "../config/home-env.test-harness.js"; import { beginSecretsRuntimeIsolationForTest, createOpenAIFileRuntimeConfig, createOpenAIFileRuntimeFixture, EMPTY_LOADABLE_PLUGIN_ORIGINS, endSecretsRuntimeIsolationForTest, expectResolvedOpenAIRuntime, type SecretsRuntimeEnvSnapshot, } from "./runtime-auth.integration.test-helpers.js"; import { activateSecretsRuntimeSnapshot, prepareSecretsRuntimeSnapshot } from "./runtime.js"; vi.unmock("../version.js"); describe("secrets runtime snapshot auth write refresh", () => { let envSnapshot: SecretsRuntimeEnvSnapshot; beforeEach(() => { envSnapshot = beginSecretsRuntimeIsolationForTest(); }); afterEach(() => { endSecretsRuntimeIsolationForTest(envSnapshot); }); it("keeps active secrets runtime snapshots resolved after refreshes", async () => { if (os.platform() === "win32") { return; } await withTempHome("openclaw-secrets-runtime-write-", async (home) => { const { secretFile, agentDir } = await createOpenAIFileRuntimeFixture(home); const prepared = await prepareSecretsRuntimeSnapshot({ config: createOpenAIFileRuntimeConfig(secretFile), agentDirs: [agentDir], loadablePluginOrigins: EMPTY_LOADABLE_PLUGIN_ORIGINS, }); activateSecretsRuntimeSnapshot(prepared); expectResolvedOpenAIRuntime(agentDir); const refreshed = await prepareSecretsRuntimeSnapshot({ config: { ...createOpenAIFileRuntimeConfig(secretFile), gateway: { auth: { mode: "token" } }, }, agentDirs: [agentDir], loadablePluginOrigins: EMPTY_LOADABLE_PLUGIN_ORIGINS, }); activateSecretsRuntimeSnapshot(refreshed); expectResolvedOpenAIRuntime(agentDir); expect(refreshed.config.gateway?.auth).toEqual({ mode: "token" }); expect(refreshed.sourceConfig.gateway?.auth).toEqual({ mode: "token" }); }); }); });