From 7ba09e414f98d6cac0ea8cca37cb7a66e3edf835 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 18:43:58 +0000 Subject: [PATCH] refactor(test): snapshot env in shell utils e2e --- src/agents/shell-utils.e2e.test.ts | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/agents/shell-utils.e2e.test.ts b/src/agents/shell-utils.e2e.test.ts index bcf9bc7d5e9..c13ec178a98 100644 --- a/src/agents/shell-utils.e2e.test.ts +++ b/src/agents/shell-utils.e2e.test.ts @@ -2,13 +2,13 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { captureEnv } from "../test-utils/env.js"; import { getShellConfig, resolveShellFromPath } from "./shell-utils.js"; const isWin = process.platform === "win32"; describe("getShellConfig", () => { - const originalShell = process.env.SHELL; - const originalPath = process.env.PATH; + let envSnapshot: ReturnType; const tempDirs: string[] = []; const createTempBin = (files: string[]) => { @@ -23,22 +23,14 @@ describe("getShellConfig", () => { }; beforeEach(() => { + envSnapshot = captureEnv(["SHELL", "PATH"]); if (!isWin) { process.env.SHELL = "/usr/bin/fish"; } }); afterEach(() => { - if (originalShell == null) { - delete process.env.SHELL; - } else { - process.env.SHELL = originalShell; - } - if (originalPath == null) { - delete process.env.PATH; - } else { - process.env.PATH = originalPath; - } + envSnapshot.restore(); for (const dir of tempDirs.splice(0)) { fs.rmSync(dir, { recursive: true, force: true }); } @@ -81,7 +73,7 @@ describe("getShellConfig", () => { }); describe("resolveShellFromPath", () => { - const originalPath = process.env.PATH; + let envSnapshot: ReturnType; const tempDirs: string[] = []; const createTempBin = (name: string, executable: boolean) => { @@ -97,12 +89,12 @@ describe("resolveShellFromPath", () => { return dir; }; + beforeEach(() => { + envSnapshot = captureEnv(["PATH"]); + }); + afterEach(() => { - if (originalPath == null) { - delete process.env.PATH; - } else { - process.env.PATH = originalPath; - } + envSnapshot.restore(); for (const dir of tempDirs.splice(0)) { fs.rmSync(dir, { recursive: true, force: true }); }