From fffe587e27e3ae3faf34970417f521b772a88479 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 23:47:22 +0000 Subject: [PATCH] test: tighten brew helper coverage --- src/infra/brew.test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/infra/brew.test.ts b/src/infra/brew.test.ts index 92317ef6019..ea601603f13 100644 --- a/src/infra/brew.test.ts +++ b/src/infra/brew.test.ts @@ -88,6 +88,35 @@ describe("brew helpers", () => { }); }); + it("ignores blank HOMEBREW_BREW_FILE and HOMEBREW_PREFIX values", async () => { + await withBrewRoot(async (tmp) => { + const homebrewBin = path.join(tmp, ".linuxbrew", "bin"); + const brewPath = path.join(homebrewBin, "brew"); + await writeExecutable(brewPath); + + const env: NodeJS.ProcessEnv = { + HOMEBREW_BREW_FILE: " ", + HOMEBREW_PREFIX: "\t", + }; + + expect(resolveBrewExecutable({ homeDir: tmp, env })).toBe(brewPath); + + const dirs = resolveBrewPathDirs({ homeDir: tmp, env }); + expect(dirs).not.toContain(path.join("", "bin")); + expect(dirs).not.toContain(path.join("", "sbin")); + }); + }); + + it("always includes the standard macOS brew dirs after linuxbrew candidates", () => { + const env: NodeJS.ProcessEnv = { + HOMEBREW_BREW_FILE: " ", + HOMEBREW_PREFIX: " ", + }; + const dirs = resolveBrewPathDirs({ homeDir: "/home/test", env }); + + expect(dirs.slice(-2)).toEqual(["/opt/homebrew/bin", "/usr/local/bin"]); + }); + it("includes Linuxbrew bin/sbin in path candidates", () => { const env: NodeJS.ProcessEnv = { HOMEBREW_PREFIX: "/custom/prefix" }; const dirs = resolveBrewPathDirs({ homeDir: "/home/test", env });