From 3fd7dc5046bc92b19651b09e9c83ac841e4c2311 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 18:47:27 +0000 Subject: [PATCH] refactor(test): snapshot shell/path env in bash tools e2e --- src/agents/bash-tools.e2e.test.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/agents/bash-tools.e2e.test.ts b/src/agents/bash-tools.e2e.test.ts index 9cf93ab2bea..da075e447c9 100644 --- a/src/agents/bash-tools.e2e.test.ts +++ b/src/agents/bash-tools.e2e.test.ts @@ -1,6 +1,7 @@ import path from "node:path"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { peekSystemEvents, resetSystemEventsForTest } from "../infra/system-events.js"; +import { captureEnv } from "../test-utils/env.js"; import { getFinishedSession, resetProcessRegistryForTests } from "./bash-process-registry.js"; import { createExecTool, createProcessTool, execTool, processTool } from "./bash-tools.js"; import { buildDockerExecArgs } from "./bash-tools.shared.js"; @@ -61,18 +62,17 @@ beforeEach(() => { }); describe("exec tool backgrounding", () => { - const originalShell = process.env.SHELL; + let envSnapshot: ReturnType; beforeEach(() => { + envSnapshot = captureEnv(["SHELL"]); if (!isWin && defaultShell) { process.env.SHELL = defaultShell; } }); afterEach(() => { - if (!isWin) { - process.env.SHELL = originalShell; - } + envSnapshot.restore(); }); it( @@ -301,18 +301,17 @@ describe("exec tool backgrounding", () => { }); describe("exec exit codes", () => { - const originalShell = process.env.SHELL; + let envSnapshot: ReturnType; beforeEach(() => { + envSnapshot = captureEnv(["SHELL"]); if (!isWin && defaultShell) { process.env.SHELL = defaultShell; } }); afterEach(() => { - if (!isWin) { - process.env.SHELL = originalShell; - } + envSnapshot.restore(); }); it("treats non-zero exits as completed and appends exit code", async () => { @@ -416,20 +415,17 @@ describe("exec notifyOnExit", () => { }); describe("exec PATH handling", () => { - const originalPath = process.env.PATH; - const originalShell = process.env.SHELL; + let envSnapshot: ReturnType; beforeEach(() => { + envSnapshot = captureEnv(["PATH", "SHELL"]); if (!isWin && defaultShell) { process.env.SHELL = defaultShell; } }); afterEach(() => { - process.env.PATH = originalPath; - if (!isWin) { - process.env.SHELL = originalShell; - } + envSnapshot.restore(); }); it("prepends configured path entries", async () => {