refactor(test): simplify env scoping in exec and usage tests

This commit is contained in:
Peter Steinberger
2026-02-21 13:17:06 +00:00
parent aff272ec35
commit ae70bf4dca
2 changed files with 40 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { captureEnv } from "../test-utils/env.js";
import { withEnvAsync } from "../test-utils/env.js";
import { runCommandWithTimeout, shouldSpawnWithShell } from "./exec.js";
describe("runCommandWithTimeout", () => {
@@ -13,9 +13,7 @@ describe("runCommandWithTimeout", () => {
});
it("merges custom env with process.env", async () => {
const envSnapshot = captureEnv(["OPENCLAW_BASE_ENV"]);
process.env.OPENCLAW_BASE_ENV = "base";
try {
await withEnvAsync({ OPENCLAW_BASE_ENV: "base" }, async () => {
const result = await runCommandWithTimeout(
[
process.execPath,
@@ -31,9 +29,7 @@ describe("runCommandWithTimeout", () => {
expect(result.code).toBe(0);
expect(result.stdout).toBe("base|ok");
expect(result.termination).toBe("exit");
} finally {
envSnapshot.restore();
}
});
});
it("kills command when no output timeout elapses", async () => {