refactor(test): replace ad-hoc env restore blocks with helpers

This commit is contained in:
Peter Steinberger
2026-02-21 18:28:49 +00:00
parent 63488eb981
commit fc43a16d43
3 changed files with 9 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { withEnvAsync } from "../test-utils/env.js";
const mocks = vi.hoisted(() => ({
readCommand: vi.fn(),
@@ -139,9 +140,7 @@ describe("maybeRepairGatewayServiceConfig", () => {
});
it("uses OPENCLAW_GATEWAY_TOKEN when config token is missing", async () => {
const previousToken = process.env.OPENCLAW_GATEWAY_TOKEN;
process.env.OPENCLAW_GATEWAY_TOKEN = "env-token";
try {
await withEnvAsync({ OPENCLAW_GATEWAY_TOKEN: "env-token" }, async () => {
setupGatewayTokenRepairScenario("env-token");
const cfg: OpenClawConfig = {
@@ -161,12 +160,6 @@ describe("maybeRepairGatewayServiceConfig", () => {
}),
);
expect(mocks.install).toHaveBeenCalledTimes(1);
} finally {
if (previousToken === undefined) {
delete process.env.OPENCLAW_GATEWAY_TOKEN;
} else {
process.env.OPENCLAW_GATEWAY_TOKEN = previousToken;
}
}
});
});
});