refactor(test): reuse env snapshots in gateway call tests

This commit is contained in:
Peter Steinberger 2026-02-15 23:22:58 +00:00
parent 31980bcaf1
commit a68ed3f64c
1 changed files with 11 additions and 14 deletions

View File

@ -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<typeof captureEnv>;
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<typeof captureEnv>;
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<typeof captureEnv>;
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 () => {