Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
engine update: never walk a bottle across Wine builds, never delete an engine this build does not know
Gauthier Piarrettec63432aa295b
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 6bb694b..a15886d 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -540,23 +540,35 @@ final class AppState {Task { @MainActor in self.reportDownload(name, received: received, total: total) }}await MainActor.run { self.appendLog("engine \(fresh.id) installed") }- let sameWine = !EngineManifest.needsPrefixRefresh(from: old.manifest, to: fresh.manifest)+ // Whether the prefix survives is a question about THIS bottle's engine, not about the+ // default engine's own step. Comparing old (the previous default) to fresh moved a+ // bottle sitting on a different Wine build across builds whenever the default's own+ // update happened to be component-only: on 2026-09-09 a 0.8.9 build walked bottles+ // from the Wine 11 engine onto its Wine 10 default because r1 to r2 was same-Wine.+ let installedNow = try engineStore.installedEngines()for var bottle in try bottleStore.list() where bottle.settings.engineID != fresh.id {- guard sameWine else {+ guard let bottleEngine = installedNow.first(where: { $0.id == bottle.settings.engineID }) else {+ await MainActor.run { self.appendLog("bottle '\(bottle.name)' stays on \(bottle.settings.engineID): that engine is not installed here, so this build cannot tell whether its Wine matches") }+ continue+ }+ guard EngineStore.canMoveBottle(on: bottleEngine.manifest, to: fresh.manifest) else {await MainActor.run { self.appendLog("bottle '\(bottle.name)' stays on \(bottle.settings.engineID): the new engine has a different Wine build; switch it from the bottle's settings when you want") }continue}- let runnerOld = WineRunner(paths: paths, engine: old, bottle: bottle)+ let runnerOld = WineRunner(paths: paths, engine: bottleEngine, bottle: bottle)try? runnerOld.kill()try? await Task.sleep(for: .seconds(2))bottle.settings.engineID = fresh.idtry bottle.save()await MainActor.run { self.appendLog("bottle '\(bottle.name)' moved to \(fresh.id) (same Wine, no prefix refresh needed)") }}+ // Clean up only the engine this update superseded. Anything else stays, including an+ // engine this build has never heard of: a newer Highball may have installed it, and+ // deleting it throws away a 300 MB download and strands every bottle on it.let referenced = Set(try bottleStore.list().map(\.settings.engineID))- let installed = try engineStore.installedEngines()- let offered = Set(Self.knownManifests.map(\.id))- for stale in EngineStore.unreferencedEngines(installed: installed, referencedIDs: referenced, defaultID: fresh.id, keep: offered) {+ if let stale = EngineStore.engineToRemoveAfterUpdate(+ oldID: oldID, freshID: fresh.id, referencedIDs: referenced,+ installed: try engineStore.installedEngines()) {try? FileManager.default.removeItem(at: stale.root)await MainActor.run { self.appendLog("old engine \(stale.id) removed (no bottle uses it)") }}diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swiftindex 30db66d..6913a53 100644--- a/Sources/HighballKit/EngineStore.swift+++ b/Sources/HighballKit/EngineStore.swift@@ -74,6 +74,28 @@ public struct EngineStore: Sendable {installed.filter { $0.id != defaultID && !referencedIDs.contains($0.id) && !keep.contains($0.id) }}+ /// Whether an engine update may move a bottle onto `fresh` without re-running the Windows+ /// first boot. The question is about the bottle's OWN engine: comparing the previous default+ /// instead walked bottles across Wine builds whenever the default's own step was+ /// component-only (2026-09-09, a 0.8.9 build moved Wine 11 bottles onto its Wine 10 default+ /// because r1 to r2 was same-Wine, and their prefixes are a different format).+ /// A bottle whose engine is not installed here returns false: this build cannot tell.+ public static func canMoveBottle(on bottleEngine: EngineManifest?, to fresh: EngineManifest) -> Bool {+ guard let bottleEngine else { return false }+ return !EngineManifest.needsPrefixRefresh(from: bottleEngine, to: fresh)+ }++ /// The one engine an update may delete: the default it just superseded, and only when no+ /// bottle is left on it. Everything else stays, including an engine this build does not+ /// recognise, because a newer Highball may have installed it and removing it both discards a+ /// large download and strands the bottles that use it.+ public static func engineToRemoveAfterUpdate(oldID: String, freshID: String,+ referencedIDs: Set<String>,+ installed: [InstalledEngine]) -> InstalledEngine? {+ guard oldID != freshID, !referencedIDs.contains(oldID) else { return nil }+ return installed.first { $0.id == oldID }+ }+/// The engine to offer when a program fails on `currentID`: the default engine when the/// bottle is not on it (the newer one, usually), else the newest other installed engine./// nil with a single engine installed.diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swiftindex d46f470..6409cc3 100644--- a/Tests/HighballKitTests/RegressionTests.swift+++ b/Tests/HighballKitTests/RegressionTests.swift@@ -862,6 +862,55 @@ extension RegressionTests {"an engine the app still offers (bundled manifest) is kept for rollback even with no bottle on it")}+ // 2026-09-09, found on the maintainer's own machine: an older Highball started, updated to its+ // bundled default, and walked EVERY bottle onto it, including two on a different Wine build+ // whose prefixes are a different format. It then deleted the engine it did not recognise, so a+ // 300 MB download vanished and the bottles pointed at a Wine 10 engine with Wine 11 prefixes.+ // The move is a question about each bottle's own engine, never about the default's own step.+ func testBottleMovesOnlyWhenItsOwnEngineHasTheSameWine() throws {+ func manifest(_ id: String, wine sha: String) throws -> EngineManifest {+ let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{"wine":{"kind":"engine","url":"https://x/\#(sha).tar.gz","sha256":"\#(sha)"}}}"#+ return try JSONDecoder().decode(EngineManifest.self, from: Data(json.utf8))+ }+ let wine10a = try manifest("x64-sikarugir10.0_6-r1", wine: "aaaa")+ let wine10b = try manifest("x64-sikarugir10.0_6-r2", wine: "aaaa") // same Wine, shim added+ let wine11 = try manifest("x64-crossover26.3-r5", wine: "bbbb") // different Wine++ XCTAssertTrue(EngineStore.canMoveBottle(on: wine10a, to: wine10b),+ "same Wine build: a component-only update may move the bottle")+ XCTAssertFalse(EngineStore.canMoveBottle(on: wine11, to: wine10b),+ "THE BUG: a Wine 11 bottle must never be walked onto a Wine 10 engine")+ XCTAssertFalse(EngineStore.canMoveBottle(on: nil, to: wine10b),+ "engine not installed here: this build cannot tell, so it leaves the bottle alone")+ }++ // The same incident, second half: cleanup removed an engine the running build had never heard+ // of. Only the superseded default may go, and only when nothing runs on it.+ func testUpdateRemovesOnlyTheEngineItSuperseded() throws {+ func engine(_ id: String) throws -> InstalledEngine {+ let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#+ return InstalledEngine(manifest: try JSONDecoder().decode(EngineManifest.self, from: Data(json.utf8)),+ root: URL(fileURLWithPath: "/tmp/\(id)"))+ }+ let old = try engine("x64-sikarugir10.0_6-r1")+ let fresh = try engine("x64-sikarugir10.0_6-r2")+ let newer = try engine("x64-crossover26.3-r5") // installed by a newer Highball+ let all = [old, fresh, newer]++ XCTAssertEqual(EngineStore.engineToRemoveAfterUpdate(oldID: old.id, freshID: fresh.id,+ referencedIDs: [], installed: all)?.id, old.id,+ "the superseded default goes when no bottle is on it")+ XCTAssertNil(EngineStore.engineToRemoveAfterUpdate(oldID: old.id, freshID: fresh.id,+ referencedIDs: [old.id], installed: all),+ "a bottle still runs on it: it stays")+ // The engine this build does not know is never even a candidate.+ for referenced in [Set<String>(), Set([newer.id])] {+ XCTAssertNotEqual(EngineStore.engineToRemoveAfterUpdate(oldID: old.id, freshID: fresh.id,+ referencedIDs: referenced, installed: all)?.id,+ newer.id, "THE BUG: an unrecognised newer engine must never be removed")+ }+ }+// The crash alert's second way out: the default engine when the bottle is not on it, else the// newest other engine, and nothing with a single engine installed.func testAlternateEngineForCrashAlert() throws {