diff --git a/src/agents/embedded-agent-runner/openrouter-model-capabilities.test.ts b/src/agents/embedded-agent-runner/openrouter-model-capabilities.test.ts index 95f68dc0c93f..37d385565a18 100644 --- a/src/agents/embedded-agent-runner/openrouter-model-capabilities.test.ts +++ b/src/agents/embedded-agent-runner/openrouter-model-capabilities.test.ts @@ -5,27 +5,33 @@ import { join } from "node:path"; import { resetPluginStateStoreForTests } from "openclaw/plugin-sdk/plugin-state-test-runtime"; import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures"; import { afterEach, describe, expect, it, vi } from "vitest"; +import { withEnvAsync } from "../../test-utils/env.js"; async function withOpenRouterStateDir(run: (stateDir: string) => Promise) { // Each case gets an isolated state dir because the module persists capability // rows through the plugin state store across imports. const stateDir = mkdtempSync(join(tmpdir(), "openclaw-openrouter-capabilities-")); resetPluginStateStoreForTests(); - process.env.OPENCLAW_STATE_DIR = stateDir; - for (const key of [ - "ALL_PROXY", - "all_proxy", - "HTTP_PROXY", - "http_proxy", - "HTTPS_PROXY", - "https_proxy", - ]) { - vi.stubEnv(key, ""); - } try { - await run(stateDir); + await withEnvAsync( + { + OPENCLAW_STATE_DIR: stateDir, + ALL_PROXY: "", + all_proxy: "", + HTTP_PROXY: "", + http_proxy: "", + HTTPS_PROXY: "", + https_proxy: "", + }, + async () => { + try { + await run(stateDir); + } finally { + resetPluginStateStoreForTests(); + } + }, + ); } finally { - resetPluginStateStoreForTests(); rmSync(stateDir, { recursive: true, force: true }); } } @@ -42,7 +48,6 @@ describe("openrouter-model-capabilities", () => { afterEach(() => { resetPluginStateStoreForTests(); vi.unstubAllGlobals(); - delete process.env.OPENCLAW_STATE_DIR; }); it("uses top-level OpenRouter max token fields when top_provider is absent", async () => {