diff --git a/src/gateway/call.test.ts b/src/gateway/call.test.ts index a4aff647ac0..f6c5afb607a 100644 --- a/src/gateway/call.test.ts +++ b/src/gateway/call.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { captureEnv } from "../test-utils/env.js"; const loadConfig = vi.fn(); const resolveGatewayPort = vi.fn(); @@ -331,7 +332,10 @@ describe("callGateway error details", () => { }); describe("callGateway url override auth requirements", () => { + let envSnapshot: ReturnType; + beforeEach(() => { + envSnapshot = captureEnv(["OPENCLAW_GATEWAY_TOKEN", "OPENCLAW_GATEWAY_PASSWORD"]); loadConfig.mockReset(); resolveGatewayPort.mockReset(); pickPrimaryTailnetIPv4.mockReset(); @@ -345,8 +349,7 @@ describe("callGateway url override auth requirements", () => { }); afterEach(() => { - delete process.env.OPENCLAW_GATEWAY_TOKEN; - delete process.env.OPENCLAW_GATEWAY_PASSWORD; + envSnapshot.restore(); }); it("throws when url override is set without explicit credentials", async () => { @@ -366,9 +369,10 @@ describe("callGateway url override auth requirements", () => { }); describe("callGateway password resolution", () => { - const originalEnvPassword = process.env.OPENCLAW_GATEWAY_PASSWORD; + let envSnapshot: ReturnType; beforeEach(() => { + envSnapshot = captureEnv(["OPENCLAW_GATEWAY_PASSWORD"]); loadConfig.mockReset(); resolveGatewayPort.mockReset(); pickPrimaryTailnetIPv4.mockReset(); @@ -383,11 +387,7 @@ describe("callGateway password resolution", () => { }); afterEach(() => { - if (originalEnvPassword == null) { - delete process.env.OPENCLAW_GATEWAY_PASSWORD; - } else { - process.env.OPENCLAW_GATEWAY_PASSWORD = originalEnvPassword; - } + envSnapshot.restore(); }); it("uses local config password when env is unset", async () => { @@ -468,9 +468,10 @@ describe("callGateway password resolution", () => { }); describe("callGateway token resolution", () => { - const originalEnvToken = process.env.OPENCLAW_GATEWAY_TOKEN; + let envSnapshot: ReturnType; beforeEach(() => { + envSnapshot = captureEnv(["OPENCLAW_GATEWAY_TOKEN"]); loadConfig.mockReset(); resolveGatewayPort.mockReset(); pickPrimaryTailnetIPv4.mockReset(); @@ -485,11 +486,7 @@ describe("callGateway token resolution", () => { }); afterEach(() => { - if (originalEnvToken == null) { - delete process.env.OPENCLAW_GATEWAY_TOKEN; - } else { - process.env.OPENCLAW_GATEWAY_TOKEN = originalEnvToken; - } + envSnapshot.restore(); }); it("uses explicit token when url override is set", async () => {