Fix Homebrew update detection and skill guidance

This commit is contained in:
gitea committed 2026-09-20 17:49:29 +08:00
1 parent 53453cf512
commit 48ebccd086
10 files changed
+274 -222

No files matched your search

+25 -13
View File
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { compareSemVer, getMirrorMode, isHomebrewInstall, isNewerVersion, matchAssetForPlatform } from "./update.js";
@@ -187,20 +188,31 @@ describe("update command bgSave and cache integration", () => {
});
describe("isHomebrewInstall", () => {
test("detects Homebrew Cellar paths on Apple Silicon and Intel macOS", () => {
expect(isHomebrewInstall("/opt/homebrew/Cellar/seal-use/0.10.33/bin/seal-use")).toBe(true);
expect(isHomebrewInstall("/usr/local/Cellar/seal-use/0.10.33/bin/seal-use")).toBe(true);
expect(isHomebrewInstall("/opt/homebrew/bin/seal-use")).toBe(true);
test("requires the executable to resolve inside Homebrew's registered formula prefix", () => {
const root = mkdtempSync(join(tmpdir(), "seal-use-homebrew-detect-"));
try {
const formulaPrefix = join(root, "opt", "seal-use");
const cellarBin = join(root, "Cellar", "seal-use", "0.10.33", "bin");
const nativeBin = join(root, "bin");
const formulaExecutable = join(cellarBin, "seal-use");
const nativeExecutable = join(nativeBin, "seal-use");
mkdirSync(cellarBin, { recursive: true });
mkdirSync(nativeBin, { recursive: true });
mkdirSync(join(root, "opt"), { recursive: true });
writeFileSync(formulaExecutable, "homebrew binary");
writeFileSync(nativeExecutable, "native binary");
symlinkSync(join(root, "Cellar", "seal-use", "0.10.33"), formulaPrefix);
expect(isHomebrewInstall(formulaExecutable, formulaPrefix)).toBe(true);
expect(isHomebrewInstall(nativeExecutable, formulaPrefix)).toBe(false);
} finally {
rmSync(root, { recursive: true, force: true });
}
});
test("detects Homebrew Cellar paths on Linuxbrew", () => {
expect(isHomebrewInstall("/home/linuxbrew/.linuxbrew/Cellar/seal-use/0.10.33/bin/seal-use")).toBe(true);
});
test("returns false for non-Homebrew paths", () => {
expect(isHomebrewInstall("/usr/local/bin/seal-use")).toBe(false);
expect(isHomebrewInstall("/Users/alice/.local/bin/seal-use")).toBe(false);
expect(isHomebrewInstall("/tmp/seal-use")).toBe(false);
test("does not infer Homebrew from a matching directory name alone", () => {
expect(isHomebrewInstall("/opt/homebrew/bin/seal-use", "/tmp/not-installed-seal-use")).toBe(false);
});
});
});