diff --git a/src/cli/commands/update.test.ts b/src/cli/commands/update.test.ts index 7c6d6ab..337f919 100644 --- a/src/cli/commands/update.test.ts +++ b/src/cli/commands/update.test.ts @@ -349,8 +349,23 @@ describe("update installation modes", () => { expect(SYSTEM_BINARY_PATH).toBe("/usr/local/bin/seal-use"); }); - test("cleanStaleBinaries ignores activePath and returns list of cleaned files", () => { - const cleaned = cleanStaleBinaries(SYSTEM_BINARY_PATH); - expect(Array.isArray(cleaned)).toBe(true); + test("cleanStaleBinaries ignores activePath and returns list of cleaned files in isolated sandbox", () => { + const tempDir = mkdtempSync(join(tmpdir(), "seal-use-clean-test-")); + try { + const fakeActive = join(tempDir, "active-bin"); + const fakeStale = join(tempDir, "stale-bin"); + const fakeUntouched = join(tempDir, "untouched-bin"); + writeFileSync(fakeActive, "active"); + writeFileSync(fakeStale, "stale"); + writeFileSync(fakeUntouched, "untouched"); + + const cleaned = cleanStaleBinaries(fakeActive, [fakeActive, fakeStale]); + expect(cleaned).toEqual([fakeStale]); + expect(existsSync(fakeActive)).toBe(true); + expect(existsSync(fakeStale)).toBe(false); + expect(existsSync(fakeUntouched)).toBe(true); + } finally { + rmSync(tempDir, { recursive: true, force: true }); + } }); }); diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index 97889c2..47d1dfb 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -39,7 +39,7 @@ export function isPathWritable(targetPath: string): boolean { } } -export function cleanStaleBinaries(activePath: string): string[] { +export function cleanStaleBinaries(activePath: string, candidateOverrides?: string[]): string[] { const cleaned: string[] = []; const home = homedir(); const userBinary = getUserBinaryPath(); @@ -49,11 +49,13 @@ export function cleanStaleBinaries(activePath: string): string[] { const homebrewBinary = "/opt/homebrew/bin/seal-use"; const homebrewAlias = "/opt/homebrew/bin/seal-home"; - const candidates = [homebrewBinary, homebrewAlias]; - if (activePath === systemBinary) { - candidates.push(userBinary, userAlias); - } else if (activePath === userBinary) { - candidates.push(systemBinary, systemAlias); + const candidates = candidateOverrides ? [...candidateOverrides] : [homebrewBinary, homebrewAlias]; + if (!candidateOverrides) { + if (activePath === systemBinary) { + candidates.push(userBinary, userAlias); + } else if (activePath === userBinary) { + candidates.push(systemBinary, systemAlias); + } } for (const candidate of candidates) {