diff --git a/Sources/SplashGUI/Core/AppModel.swift b/Sources/SplashGUI/Core/AppModel.swift
index 982ca46..f57774e 100644
--- a/Sources/SplashGUI/Core/AppModel.swift
+++ b/Sources/SplashGUI/Core/AppModel.swift
@@ -566,8 +566,14 @@ final class AppModel: ObservableObject {
// partial fields keep the pre-picker pinned behavior), .pinned never sees the override
// fields, and .latest keeps the installed engine on a failed check — the compiled-in pin
// would silently DOWNGRADE — while nothing-installed falls back to the compiled pin.
+ // `externalVersion` (Homebrew, if present) satisfies .pinned/.latest without a download
+ // when it is at or above the wanted build; .custom names an explicit payload and never
+ // accepts a stand-in. When external is true, start() adopts it (points `current` at the
+ // brew libexec) instead of calling ensureInstalled.
nonisolated static func enginePlan(mode: EngineMode, customOverride: EnginePin?, installed: Bool,
- checkUpdate: Bool, latest: EnginePin?) -> (ensure: Bool, override: EnginePin?) {
+ checkUpdate: Bool, latest: EnginePin?,
+ pinnedVersion: String, externalVersion: String?)
+ -> (ensure: Bool, override: EnginePin?, external: Bool) {
var ensure = !installed || checkUpdate
var override: EnginePin?
switch mode {
@@ -584,7 +590,13 @@ final class AppModel: ObservableObject {
ensure = false
}
}
- return (ensure, override)
+ var external = false
+ if mode != .custom, let ext = externalVersion {
+ let wanted = override?.version ?? pinnedVersion
+ if EngineInstaller.versionOrder(ext, wanted) != .orderedAscending { external = true }
+ }
+ if external { ensure = false }
+ return (ensure, override, external)
}
func start() {
@@ -619,13 +631,25 @@ final class AppModel: ObservableObject {
// (enginePlan) so the harness can pin it.
var resolved: EnginePin?
if case .latest = self.config.engineMode { resolved = await EngineResolver.latest() }
- let (ensure, override) = Self.enginePlan(
+ let externalVersion = EngineInstaller.externalEngineVersion()
+ let (ensure, override, external) = Self.enginePlan(
mode: self.config.engineMode, customOverride: self.config.enginePinOverride(),
- installed: installed, checkUpdate: self.config.checkEngineUpdate, latest: resolved)
- if !ensure, case .latest = self.config.engineMode {
+ installed: installed, checkUpdate: self.config.checkEngineUpdate, latest: resolved,
+ pinnedVersion: EngineInstaller.defaultPin.version, externalVersion: externalVersion)
+ if !ensure, !external, case .latest = self.config.engineMode {
self.server.note("- engine update check: GitHub unreachable, keeping the installed engine")
}
- if ensure {
+ if external {
+ // Skip the download: point `current` at the Homebrew payload.
+ do {
+ try EngineInstaller.adoptExternalEngine()
+ } catch {
+ self.startBlocked((error as? LocalizedError)?.errorDescription ?? "\(error)")
+ self.phase = .stopped
+ return
+ }
+ self.server.note("- engine: using the Homebrew install (\(externalVersion ?? "?")) — no download")
+ } else if ensure {
do {
try await self.engine.ensureInstalled(
port: self.config.run.port,
diff --git a/Sources/SplashGUI/Core/EngineInstaller.swift b/Sources/SplashGUI/Core/EngineInstaller.swift
index 81642f8..a39c534 100644
--- a/Sources/SplashGUI/Core/EngineInstaller.swift
+++ b/Sources/SplashGUI/Core/EngineInstaller.swift
@@ -27,9 +27,9 @@ final class EngineInstaller: ObservableObject {
// Bumping the engine is an app release; AppConfig's engine*Override fields are the escape hatch.
static let defaultPin = EnginePin(
- version: "1.5.0",
- sha256: "1ddc28bf7bfda8833859a913d7072e2aac9072addb9eb5664f3bf1a83a8d6ee2",
- url: "https://github.com/incoai/splash/releases/download/1.5.0/splash-1.5.0-arm64-macos26.tar.gz"
+ version: "1.6.0",
+ sha256: "da3aef0a581491b0eb4c1168bda07f520e5ca8368764abff426d95ac1c77e5c4",
+ url: "https://github.com/incoai/splash/releases/download/1.6.0/splash-1.6.0-arm64-macos26.tar.gz"
)
static let fm = FileManager.default
@@ -42,6 +42,58 @@ final class EngineInstaller: ObservableObject {
static var pythonPath: URL { currentLink.appendingPathComponent("python/bin/python3") }
static var launcherPath: URL { currentLink.appendingPathComponent("install/launcher.py") }
+ // A Homebrew-casked engine (`brew install splash`, incoai/tap). The bottle's `libexec/`
+ // mirrors the OTA tarball root exactly (python/bin/python3, install/launcher.py,
+ // release.json), so `current` can simply point at it and every downstream reader —
+ // isInstalled, release.json, the launcher argv — works unchanged. The `opt` symlink is
+ // version-independent, so `brew upgrade` needs no app cooperation; `brew uninstall`
+ // leaves it dangling and externalEngineVersion() returns nil.
+ static var externalEngineRoot: URL {
+ URL(fileURLWithPath: "/opt/homebrew/opt/splash/libexec", isDirectory: true)
+ }
+
+ // The version of a usable Homebrew engine, or nil (not installed, uninstalled, or an
+ // unexpected layout). `at` lets the harness feed a fixture directory.
+ static func externalEngineVersion(at root: URL? = nil) -> String? {
+ let root = root ?? externalEngineRoot
+ guard fm.isExecutableFile(atPath: root.appendingPathComponent("python/bin/python3").path),
+ fm.fileExists(atPath: root.appendingPathComponent("install/launcher.py").path),
+ let data = try? Data(contentsOf: root.appendingPathComponent("release.json")),
+ let obj = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
+ let v = obj["version"] as? String, !v.isEmpty else { return nil }
+ return v
+ }
+
+ // Numeric-aware compare of dotted versions: "1.10.0" > "1.6.0"; non-numeric suffixes
+ // ("1.6.0+build7") compare on their leading digits. Missing segments count as 0.
+ nonisolated static func versionOrder(_ a: String, _ b: String) -> ComparisonResult {
+ func parts(_ s: String) -> [Int] {
+ s.split(separator: ".").map { Int($0.prefix { $0.isNumber }) ?? 0 }
+ }
+ let pa = parts(a), pb = parts(b)
+ for i in 0..<max(pa.count, pb.count) {
+ let x = i < pa.count ? pa[i] : 0, y = i < pb.count ? pb[i] : 0
+ if x != y { return x < y ? .orderedAscending : .orderedDescending }
+ }
+ return .orderedSame
+ }
+
+ // Point `current` at the Homebrew payload instead of downloading a managed copy.
+ // The managed directories (if any) stay on disk untouched — this only moves a symlink.
+ // True when `current` points at the adopted Homebrew payload rather than a managed dir.
+ static var currentIsExternal: Bool {
+ (try? fm.destinationOfSymbolicLink(atPath: currentLink.path)) == externalEngineRoot.path
+ }
+
+ static func adoptExternalEngine() throws {
+ guard let v = externalEngineVersion() else {
+ throw InstallError.preflight("No usable Homebrew Splash engine found at \(externalEngineRoot.path).")
+ }
+ try fm.createDirectory(at: engineRoot, withIntermediateDirectories: true)
+ try flipCurrent(to: externalEngineRoot.path)
+ _ = v
+ }
+
static func currentReleaseVersion() -> String? {
let rel = currentLink.appendingPathComponent("release.json")
guard let data = try? Data(contentsOf: rel),
@@ -63,10 +115,14 @@ final class EngineInstaller: ObservableObject {
let pin = override ?? Self.defaultPin
await MainActor.run { self.resolvedVersion = pin.version }
- // Reuse only when `current` points at exactly this pin's dir — an override of the same
- // version from another URL installs into its own dir and must not be skipped.
+ // Reuse when `current` already runs exactly this pin's version from the right place:
+ // this pin's own directory, or the adopted Homebrew payload (a same-version override
+ // from ANOTHER URL must still install into its own dir, so overrides never match the
+ // external path).
+ let currentDest = try? Self.fm.destinationOfSymbolicLink(atPath: Self.currentLink.path)
if let have = Self.currentReleaseVersion(), have == pin.version, Self.isInstalled,
- (try? Self.fm.destinationOfSymbolicLink(atPath: Self.currentLink.path)) == Self.dirName(for: pin) {
+ currentDest == Self.dirName(for: pin)
+ || (override == nil && currentDest == Self.externalEngineRoot.path) {
await MainActor.run { self.installedVersion = have; self.step = .ready }
return
}
@@ -82,9 +138,11 @@ final class EngineInstaller: ObservableObject {
let stagedTar = Self.stagedDir.appendingPathComponent(name + ".tar.gz")
let stagedRoot = Self.stagedDir.appendingPathComponent(name, isDirectory: true)
+ // Wipe the staging area first: a previous failed attempt can leave an extracted
+ // payload under the archive's own directory name (see findExtractedRoot), and a
+ // stale one would confuse the discovery below.
+ try? Self.fm.removeItem(at: Self.stagedDir)
try Self.fm.createDirectory(at: Self.stagedDir, withIntermediateDirectories: true)
- try? Self.fm.removeItem(at: stagedTar)
- try? Self.fm.removeItem(at: stagedRoot)
do {
try await download(pin: pin, to: stagedTar)
@@ -96,33 +154,36 @@ final class EngineInstaller: ObservableObject {
await MainActor.run { self.step = .extracting }
try Self.run("/usr/bin/tar", ["-xzf", stagedTar.path, "-C", Self.stagedDir.path])
- let release = stagedRoot.appendingPathComponent("release.json")
- guard Self.fm.fileExists(atPath: release.path) else {
- throw InstallError.preflight("Extracted archive is missing release.json; unexpected payload.")
+ // The archive's top-level directory is always named for the VERSION, while
+ // `name` gains a URL hash whenever pin.url differs from the compiled default
+ // (a resolved-latest or custom pin). Expecting stagedRoot there meant every
+ // such install died on the release.json check AFTER the download — and
+ // re-downloaded on every retry. Discover what was actually extracted.
+ guard let extractedRoot = Self.findExtractedRoot(in: Self.stagedDir, preferring: stagedRoot) else {
+ throw InstallError.preflight("Extracted archive has no release.json in any payload directory; unexpected archive layout.")
}
for rel in ["python/bin/python3", "engine/splash"] {
try? Self.fm.setAttributes([.posixPermissions: 0o755],
- ofItemAtPath: stagedRoot.appendingPathComponent(rel).path)
+ ofItemAtPath: extractedRoot.appendingPathComponent(rel).path)
}
await MainActor.run { self.step = .validating }
- try Self.run(stagedRoot.appendingPathComponent("python/bin/python3").path,
- ["-u", stagedRoot.appendingPathComponent("install/launcher.py").path, "--help"])
+ try Self.run(extractedRoot.appendingPathComponent("python/bin/python3").path,
+ ["-u", extractedRoot.appendingPathComponent("install/launcher.py").path, "--help"])
await MainActor.run { self.step = .switching }
let finalDir = Self.engineRoot.appendingPathComponent(name, isDirectory: true)
try? Self.fm.removeItem(at: finalDir)
try Self.fm.createDirectory(at: Self.engineRoot, withIntermediateDirectories: true)
- try Self.fm.moveItem(at: stagedRoot, to: finalDir)
+ try Self.fm.moveItem(at: extractedRoot, to: finalDir)
try Self.flipCurrent(to: name)
Self.prune(keeping: name)
- try? Self.fm.removeItem(at: stagedTar)
+ try? Self.fm.removeItem(at: Self.stagedDir)
let v = Self.currentReleaseVersion()
await MainActor.run { self.installedVersion = v; self.step = .ready }
} catch {
- try? Self.fm.removeItem(at: stagedRoot)
- try? Self.fm.removeItem(at: stagedTar)
+ try? Self.fm.removeItem(at: Self.stagedDir)
await MainActor.run {
if self.step != .ready {
self.step = .failed((error as? LocalizedError)?.errorDescription ?? "\(error)")
@@ -229,6 +290,19 @@ final class EngineInstaller: ObservableObject {
return "splash-\(pin.version)-\(h)-arm64-macos26"
}
+ // The payload directory inside the staging area: the preferred (name-keyed) path when
+ // it carries a release.json, otherwise the one directory that does — the archive's own
+ // top-level name, which the install moves from.
+ static func findExtractedRoot(in staged: URL, preferring: URL) -> URL? {
+ if fm.fileExists(atPath: preferring.appendingPathComponent("release.json").path) { return preferring }
+ guard let names = try? fm.contentsOfDirectory(atPath: staged.path) else { return nil }
+ for n in names where n.hasPrefix("splash-") {
+ let c = staged.appendingPathComponent(n, isDirectory: true)
+ if fm.fileExists(atPath: c.appendingPathComponent("release.json").path) { return c }
+ }
+ return nil
+ }
+
static func sha256(of url: URL) throws -> String {
let handle = try FileHandle(forReadingFrom: url)
defer { try? handle.close() }
@@ -287,6 +361,19 @@ extension EngineInstaller {
// main runloop so MainActor hops run, prints phase changes, exits 0/1.
static func runCLI(port: Int) -> Int32 {
setbuf(stdout, nil)
+ // Same preference as the GUI: a Homebrew engine at or above the pin is adopted
+ // instead of downloading a duplicate payload.
+ if let ext = externalEngineVersion(),
+ versionOrder(ext, defaultPin.version) != .orderedAscending {
+ do {
+ try adoptExternalEngine()
+ print("adopted Homebrew engine \(ext) at \(externalEngineRoot.path)")
+ print("engine \(currentReleaseVersion() ?? "?") → \(currentLink.path)")
+ return 0
+ } catch {
+ FileHandle.standardError.write(Data("adopt failed: \(error) — falling back to managed install\n".utf8))
+ }
+ }
let inst = EngineInstaller()
var code: Int32 = 1
let done = DispatchSemaphore(value: 0)
diff --git a/Sources/SplashGUI/Views/StatusTab.swift b/Sources/SplashGUI/Views/StatusTab.swift
index 5102dbd..739beda 100644
--- a/Sources/SplashGUI/Views/StatusTab.swift
+++ b/Sources/SplashGUI/Views/StatusTab.swift
@@ -41,8 +41,9 @@ struct StatusTab: View {
Card("Free disk", MachineInfo.gb(MachineInfo.freeDisk),
note: "volume hosting the SSD cache tier",
help: "Free space on the volume that holds the SSD cache.")
- Card("Engine", model.engineVersion, note: "app-managed",
- help: "The Splash engine version the app installed and manages, at \(EngineInstaller.currentLink.path).")
+ Card("Engine", model.engineVersion,
+ note: EngineInstaller.currentIsExternal ? "Homebrew install" : "app-managed",
+ help: "The Splash engine in use\(EngineInstaller.currentIsExternal ? ", adopted from the Homebrew install" : " that the app downloaded and manages"), at \(EngineInstaller.currentLink.path).")
}
Text("Prefix cache is in RAM, and the SSD tier keeps its KV pages and GDN states on disk, including across restarts when “Keep SSD cache across restarts” is on. Restarting the server clears the RAM part; the disk part survives it.")
diff --git a/scripts/profile-test/main.swift b/scripts/profile-test/main.swift
index c5b6976..86cc1ed 100644
--- a/scripts/profile-test/main.swift
+++ b/scripts/profile-test/main.swift
@@ -465,21 +465,34 @@ func runTests() {
} else {
check("engineMode round-trips", false, "encode/decode threw")
}
- // The resolver's pure half, fed the real 1.5.0 release fixture. A latest that equals the
- // compiled-in pin must produce the identical URL so EngineInstaller reuses its directory
- // instead of keying a hash-named twin off the URL.
- let v150 = "1ddc28bf7bfda8833859a913d7072e2aac9072addb9eb5664f3bf1a83a8d6ee2"
- let assets150 = ["splash-1.5.0-arm64-macos26.tar.gz", "splash-1.5.0-arm64-macos26.tar.gz.sha256",
- "Splash-1.5.0.dmg", "SHA256SUMS", "appcast.xml"]
- if let lp = EngineResolver.pin(tagName: "1.5.0", assetNames: assets150, sha256Text: v150 + "\n") {
- check("latest 1.5.0 resolves to the compiled-in pin exactly",
+ // The resolver's pure half, fed a fixture built FROM the compiled-in pin (so a pin bump
+ // cannot stale this check). A latest that equals the pin must produce the identical URL
+ // so EngineInstaller reuses its directory instead of keying a hash-named twin off the URL.
+ let pinV = EngineInstaller.defaultPin.version
+ let assetsPin = ["splash-\(pinV)-arm64-macos26.tar.gz", "splash-\(pinV)-arm64-macos26.tar.gz.sha256",
+ "Splash-\(pinV).dmg", "SHA256SUMS", "appcast.xml"]
+ if let lp = EngineResolver.pin(tagName: pinV, assetNames: assetsPin, sha256Text: EngineInstaller.defaultPin.sha256 + "\n") {
+ check("latest equal to the compiled-in pin resolves to the identical pin",
lp == EngineInstaller.defaultPin, "\(lp.version) \(lp.url)")
check("latest-equals-pinned reuses the pinned install dir",
EngineInstaller.dirName(for: lp) == EngineInstaller.dirName(for: EngineInstaller.defaultPin))
} else {
- check("latest 1.5.0 resolves to the compiled-in pin exactly", false, "pin() returned nil")
+ check("latest equal to the compiled-in pin resolves to the identical pin", false, "pin() returned nil")
check("latest-equals-pinned reuses the pinned install dir", false)
}
+ // A latest NEWER than the pin (the 1.5.0-pinned era's 1.6.0 release): the URL diverges, so
+ // dirName keys a hash-named twin — and the payload still installs because the extracted
+ // directory is DISCOVERED (findExtractedRoot, above), not assumed (the redownload-loop bug).
+ let v150 = "1ddc28bf7bfda8833859a913d7072e2aac9072addb9eb5664f3bf1a83a8d6ee2"
+ let assets150 = ["splash-1.5.0-arm64-macos26.tar.gz", "splash-1.5.0-arm64-macos26.tar.gz.sha256"]
+ if let older = EngineResolver.pin(tagName: "1.5.0", assetNames: assets150, sha256Text: v150 + "\n") {
+ check("a resolved pin with a URL diverging from the compiled pin keys a hash-named dir",
+ EngineInstaller.dirName(for: older) != EngineInstaller.dirName(for: EngineInstaller.defaultPin)
+ && EngineInstaller.dirName(for: older).hasPrefix("splash-1.5.0-"),
+ EngineInstaller.dirName(for: older))
+ } else {
+ check("a resolved pin with a URL diverging from the compiled pin keys a hash-named dir", false, "pin() returned nil")
+ }
if let vp = EngineResolver.pin(tagName: "v1.6.1", assetNames: ["splash-1.6.1-arm64-macos26.tar.gz",
"splash-1.6.1-arm64-macos26.tar.gz.sha256"],
sha256Text: String(repeating: "A", count: 64)) {
@@ -511,34 +524,119 @@ func runTests() {
// The mode table start() installs by: the custom pin applies only in custom mode, pinned
// mode ignores the override fields, and latest falls back to the installed engine, never
- // downward to the compiled pin.
+ // downward to the compiled pin. No Homebrew engine (externalVersion nil) in these rows.
let stale = EnginePin(version: "1.4.1", sha256: String(repeating: "b", count: 64),
url: "https://github.com/incoai/splash/releases/download/1.4.1/splash-1.4.1-arm64-macos26.tar.gz")
+ let PIN = "1.6.0"
let pinnedPlan = AppModel.enginePlan(mode: .pinned, customOverride: stale, installed: true,
- checkUpdate: true, latest: nil)
+ checkUpdate: true, latest: nil, pinnedVersion: PIN, externalVersion: nil)
check("pinned mode ignores complete custom fields",
pinnedPlan.override == nil && pinnedPlan.ensure == true, "\(pinnedPlan)")
let customPlan = AppModel.enginePlan(mode: .custom, customOverride: stale, installed: true,
- checkUpdate: false, latest: nil)
+ checkUpdate: false, latest: nil, pinnedVersion: PIN, externalVersion: nil)
check("custom mode installs the custom pin regardless of the update toggle",
customPlan.ensure == true && customPlan.override == stale)
let partialPlan = AppModel.enginePlan(mode: .custom, customOverride: nil, installed: true,
- checkUpdate: false, latest: nil)
+ checkUpdate: false, latest: nil, pinnedVersion: PIN, externalVersion: nil)
check("custom mode with partial fields keeps pinned behavior",
partialPlan.ensure == false && partialPlan.override == nil)
let latestHit = AppModel.enginePlan(mode: .latest, customOverride: nil, installed: true,
- checkUpdate: false, latest: stale)
+ checkUpdate: false, latest: stale, pinnedVersion: PIN, externalVersion: nil)
check("latest mode installs the resolver answer",
latestHit.ensure == true && latestHit.override == stale)
let latestKeep = AppModel.enginePlan(mode: .latest, customOverride: nil, installed: true,
- checkUpdate: false, latest: nil)
+ checkUpdate: false, latest: nil, pinnedVersion: PIN, externalVersion: nil)
check("latest mode offline keeps the installed engine",
latestKeep.ensure == false && latestKeep.override == nil)
let latestBootstrap = AppModel.enginePlan(mode: .latest, customOverride: nil, installed: false,
- checkUpdate: false, latest: nil)
+ checkUpdate: false, latest: nil, pinnedVersion: PIN, externalVersion: nil)
check("latest mode offline with nothing installed installs the compiled pin",
latestBootstrap.ensure == true && latestBootstrap.override == nil)
+ // Homebrew adoption rows: an engine at or above the wanted build satisfies pinned and
+ // latest without a download; an older one does not; custom never accepts a stand-in;
+ // and latest compares against the RESOLVED newest, not the compiled pin.
+ let extPinned = AppModel.enginePlan(mode: .pinned, customOverride: nil, installed: false,
+ checkUpdate: true, latest: nil, pinnedVersion: PIN, externalVersion: "1.6.0")
+ check("brew engine equal to the pin is adopted, nothing installed",
+ extPinned.external && extPinned.ensure == false, "\(extPinned)")
+ let extNewer = AppModel.enginePlan(mode: .pinned, customOverride: nil, installed: true,
+ checkUpdate: true, latest: nil, pinnedVersion: PIN, externalVersion: "1.7.2")
+ check("brew engine newer than the pin is adopted too",
+ extNewer.external && extNewer.ensure == false)
+ let extOlder = AppModel.enginePlan(mode: .pinned, customOverride: nil, installed: false,
+ checkUpdate: true, latest: nil, pinnedVersion: PIN, externalVersion: "1.5.0")
+ check("brew engine older than the pin installs the managed copy",
+ !extOlder.external && extOlder.ensure == true)
+ let future = EnginePin(version: "9.9.9", sha256: String(repeating: "c", count: 64),
+ url: "https://github.com/incoai/splash/releases/download/9.9.9/splash-9.9.9-arm64-macos26.tar.gz")
+ let extLatestOk = AppModel.enginePlan(mode: .latest, customOverride: nil, installed: true,
+ checkUpdate: false, latest: stale, pinnedVersion: PIN, externalVersion: "1.6.0")
+ check("brew at or above the resolved latest satisfies it",
+ extLatestOk.external && extLatestOk.ensure == false && extLatestOk.override == stale)
+ let extLatestOlder = AppModel.enginePlan(mode: .latest, customOverride: nil, installed: true,
+ checkUpdate: false, latest: future, pinnedVersion: PIN, externalVersion: "1.6.0")
+ check("brew older than the resolved latest installs the managed copy",
+ !extLatestOlder.external && extLatestOlder.ensure == true)
+ let extCustom = AppModel.enginePlan(mode: .custom, customOverride: stale, installed: true,
+ checkUpdate: false, latest: nil, pinnedVersion: PIN, externalVersion: "9.9.9")
+ check("custom mode never substitutes the brew engine",
+ !extCustom.external && extCustom.ensure == true && extCustom.override == stale)
+
+ // Dotted version compare: numeric segments, not lexicographic.
+ check("versionOrder is numeric per segment",
+ EngineInstaller.versionOrder("1.10.0", "1.6.0") == .orderedDescending
+ && EngineInstaller.versionOrder("1.6.0", "1.10.0") == .orderedAscending
+ && EngineInstaller.versionOrder("1.6.0", "1.6.0") == .orderedSame
+ && EngineInstaller.versionOrder("1.6", "1.6.0") == .orderedSame
+ && EngineInstaller.versionOrder("1.6.0+build7", "1.6.0") == .orderedSame
+ && EngineInstaller.versionOrder("1.5.9", "1.6.0") == .orderedAscending)
+
+ // Brew probe against a fixture libexec: complete layout reports its version, any
+ // missing piece (or a dangling brew symlink) returns nil.
+ let brewFixture = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
+ .appendingPathComponent("splash-brew-fixture-\(UUID().uuidString)", isDirectory: true)
+ func brewProbe(_ root: URL) -> String? { EngineInstaller.externalEngineVersion(at: root) }
+ try? FileManager.default.createDirectory(at: brewFixture.appendingPathComponent("python/bin", isDirectory: true),
+ withIntermediateDirectories: true)
+ try? FileManager.default.createDirectory(at: brewFixture.appendingPathComponent("install", isDirectory: true),
+ withIntermediateDirectories: true)
+ FileManager.default.createFile(atPath: brewFixture.appendingPathComponent("python/bin/python3").path,
+ contents: Data())
+ try? FileManager.default.setAttributes([.posixPermissions: 0o755],
+ ofItemAtPath: brewFixture.appendingPathComponent("python/bin/python3").path)
+ FileManager.default.createFile(atPath: brewFixture.appendingPathComponent("install/launcher.py").path,
+ contents: Data())
+ FileManager.default.createFile(atPath: brewFixture.appendingPathComponent("release.json").path,
+ contents: Data("{ \"version\": \"9.9.9\" }".utf8))
+ check("brew fixture reports its version", brewProbe(brewFixture) == "9.9.9", "\(brewProbe(brewFixture) ?? "nil")")
+ try? FileManager.default.removeItem(at: brewFixture.appendingPathComponent("install/launcher.py"))
+ check("brew fixture without launcher.py is not usable", brewProbe(brewFixture) == nil)
+ check("a dangling path is not a brew engine",
+ brewProbe(brewFixture.appendingPathComponent("nope")) == nil)
+ try? FileManager.default.removeItem(at: brewFixture)
+
+ // Extracted-payload discovery: the archive's top dir is named for the version while a
+ // URL-diverging pin stages under a hashed name — the install must find the real payload
+ // (this was the redownload-every-restart bug), and a payload-free staging area is nil.
+ let stageFixture = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
+ .appendingPathComponent("splash-stage-fixture-\(UUID().uuidString)", isDirectory: true)
+ let hashed = stageFixture.appendingPathComponent("splash-9.9.9-abcd1234-arm64-macos26", isDirectory: true)
+ let canonical = stageFixture.appendingPathComponent("splash-9.9.9-arm64-macos26", isDirectory: true)
+ try? FileManager.default.createDirectory(at: canonical, withIntermediateDirectories: true)
+ FileManager.default.createFile(atPath: canonical.appendingPathComponent("release.json").path, contents: Data())
+ check("findExtractedRoot discovers the archive-named payload",
+ EngineInstaller.findExtractedRoot(in: stageFixture, preferring: hashed)?.lastPathComponent
+ == "splash-9.9.9-arm64-macos26")
+ try? FileManager.default.createDirectory(at: hashed, withIntermediateDirectories: true)
+ FileManager.default.createFile(atPath: hashed.appendingPathComponent("release.json").path, contents: Data())
+ check("findExtractedRoot prefers the name-keyed payload when it exists",
+ EngineInstaller.findExtractedRoot(in: stageFixture, preferring: hashed)?.lastPathComponent
+ == "splash-9.9.9-abcd1234-arm64-macos26")
+ try? FileManager.default.removeItem(at: stageFixture)
+ check("an empty staging area yields no payload dir",
+ EngineInstaller.findExtractedRoot(in: stageFixture, preferring: hashed) == nil)
+
// N: the catalog must track the installed engine's suggested list (the sync guard for the
// Splash-defaults swap). Skips with a PASS when no engine is installed on the test machine.
let tsv = EngineInstaller.currentLink.appendingPathComponent("install/suggested-models.tsv")
Engine: pin 1.6.0, fix the diverging-URL redownload loop, adopt Homebrew installs
- defaultPin 1.5.0 -> 1.6.0 (sha256 from the release's .sha256 asset). - Redownload-every-restart bug: tar's top-level dir is always splash-<version>-arm64-macos26, but a resolved-latest/custom pin whose URL diverges from the compiled default stages under a URL-hashed name; the release.json check never found the payload, so the install died AFTER the download (and the catch deleted paths that did not exist, stranding the extracted dir). Now the extracted payload is DISCOVERED (findExtractedRoot), the staging area is wiped up front, and reuse accepts an adopted external engine of the same version. - Homebrew adoption: brew's libexec mirrors the OTA tarball root, so when /opt/homebrew/opt/ splash/libexec carries a usable engine at or above the wanted build, enginePlan says 'external' and the app points current at it instead of downloading. All modes except custom (explicit-payload escape hatch). Version compare is numeric per segment. The headless --install-engine CLI prefers the same adoption. - Status Engine card names its source (Homebrew install vs app-managed). - Harness 134 -> 148: six enginePlan rows rebuilt on the new signature + six brew-adoption rows, versionOrder, externalEngineVersion fixtures, findExtractedRoot fixtures; the latest-equals-pinned resolver fixture is now derived from defaultPin so pin bumps cannot stale it. Mutation-proven: discovery-off and the >= gate flipped each fail exactly their targeted checks. Live: adopted brew 1.6.0 via --install-engine with zero downloads; serve + chat ran entirely out of Cellar/splash/1.6.0.
c4bd121634d3852cef53927fe198067f3d817711
cjosie <administrator@josie-c.com> · 2026-11-10T16:33 ·
browse files at this commit
parents:
6886f79