Merge pull request #275 from yunyingk/mac15/fix-update-clean-test-isolation
test(update): 为 cleanStaleBinaries 增加临时目录沙箱隔离
This commit is contained in:
2 files changed
+26
-9
No files matched your search
@@ -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 });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user