Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
Support switching between CrossOver Preview builds
Logan7a220f2d6082
diff --git a/app/Sources/NotProtonApp/App.swift b/app/Sources/NotProtonApp/App.swiftindex a8f16ce..f7b1deb 100644--- a/app/Sources/NotProtonApp/App.swift+++ b/app/Sources/NotProtonApp/App.swift@@ -64,7 +64,7 @@ struct NotProtonApp: App {.disabled(!status.isIdle)Button("Set Up Compatibility Tool") { Task { await status.requestCompatibilityTool() } }- .disabled(!status.isIdle || status.usableCrossOver == nil)+ .disabled(!status.isIdle || status.setupSource == nil)Button("Fetch Valve Binaries") { Task { await status.fetchValveBinaries() } }.disabled(!status.isIdle)diff --git a/app/Sources/NotProtonApp/Model/RunnerInstaller.swift b/app/Sources/NotProtonApp/Model/RunnerInstaller.swiftindex d39b2df..e267231 100644--- a/app/Sources/NotProtonApp/Model/RunnerInstaller.swift+++ b/app/Sources/NotProtonApp/Model/RunnerInstaller.swift@@ -37,7 +37,6 @@ enum RunnerInstaller {let cloned = SupportPaths.clonedRoot(forBuild: build.id, runners: runners)try verifyClone(build: build, root: cloned)- try pointCurrent(atBuild: build.id, runners: runners)return build}@@ -80,7 +79,7 @@ enum RunnerInstaller {}}- private static func verifyClone(build: RunnerBuild, root: URL) throws {+ static func verifyClone(build: RunnerBuild, root: URL) throws {let loader = Clean.copy(of: CrossOverSource.unixLoader(inRoot: root))guard let hash = Digest.sha256IfPresent(loader) else {throw StepFailure(step: step, detail: "The clone has no Wine loader at \(loader.lastPathComponent).")diff --git a/app/Sources/NotProtonApp/Model/RunnerSetup.swift b/app/Sources/NotProtonApp/Model/RunnerSetup.swiftindex 8a5ae9b..c09f26e 100644--- a/app/Sources/NotProtonApp/Model/RunnerSetup.swift+++ b/app/Sources/NotProtonApp/Model/RunnerSetup.swift@@ -37,15 +37,74 @@ enum RunnerSetup {report(.cloning)let build = try RunnerInstaller.clone(from: install, replacingExisting: replacingExisting)+ return try activate(build, report: report)+ }++ static let switchStep = "Switch compatibility tool"++ // Points the tool at a build that is already cloned, so moving between Rosetta+ // and FEX does not copy CrossOver again. The bridge holds the patched ntdll for+ // one build only, so it is staged for the target before the link moves, and put+ // back for the build in use if anything fails on the way.+ static func activate(+ _ build: RunnerBuild,+ runners: URL = SupportPaths.runners,+ bridge: URL = SupportPaths.bridge,+ license: (URL) -> CrossOverLicense.Status = { CrossOverLicense.check(crossOverRoot: $0) },+ verify: (RunnerBuild, URL) throws -> Void = RunnerInstaller.verifyClone,+ stage: (RunnerBuild, URL, URL) throws -> [WineArch] = {+ try NtdllPatcher.stage(build: $0, runnerRoot: $1, bridge: $2)+ },+ patch: (RunnerBuild, URL, URL) throws -> RunnerPatcher.Outcome = {+ try RunnerPatcher.install(build: $0, root: $1, bridge: $2)+ },+ report: @Sendable (Phase) -> Void = { _ in }+ ) throws -> Outcome {+ guard RunnerInstaller.hasClone(forBuild: build.id, runners: runners) else {+ throw StepFailure(+ step: switchStep, detail: "Build \(build.displayVersion) has not been set up."+ )+ }- report(.staging)- let root = SupportPaths.clonedRoot(forBuild: build.id)- let staged = try NtdllPatcher.stage(build: build, runnerRoot: root)+ // The clone carries the same verification key as the bundle it came from,+ // so the check still holds once that copy of CrossOver is gone.+ let root = SupportPaths.clonedRoot(forBuild: build.id, runners: runners)+ let status = license(root)+ guard status.licensed else {+ throw StepFailure(step: "Verify CrossOver license", detail: status.detail)+ }++ let previous = RunnerStore.currentBuild(runners: runners)+ .flatMap(SupportedRunners.build(id:))+ .flatMap { $0 != build && RunnerInstaller.hasClone(forBuild: $0.id, runners: runners) ? $0 : nil }++ try verify(build, root)- report(.patching)- let installed = try RunnerPatcher.install(build: build, root: root)+ do {+ report(.staging)+ let staged = try stage(build, root, bridge)- report(.finished)- return Outcome(build: build, staged: staged, installed: installed)+ report(.patching)+ let installed = try patch(build, root, bridge)+ try RunnerInstaller.pointCurrent(atBuild: build.id, runners: runners)++ report(.finished)+ return Outcome(build: build, staged: staged, installed: installed)+ } catch {+ if let previous {+ do {+ _ = try stage(+ previous, SupportPaths.clonedRoot(forBuild: previous.id, runners: runners), bridge+ )+ } catch let restorationError {+ throw StepFailure(+ step: switchStep,+ detail: "\(error.localizedDescription) Restoring the previous build also failed: "+ + restorationError.localizedDescription+ )+ }+ }+ throw error+ }}}diff --git a/app/Sources/NotProtonApp/Model/RunnerStore.swift b/app/Sources/NotProtonApp/Model/RunnerStore.swiftindex e7b0649..20cc3a2 100644--- a/app/Sources/NotProtonApp/Model/RunnerStore.swift+++ b/app/Sources/NotProtonApp/Model/RunnerStore.swift@@ -81,4 +81,19 @@ enum RunnerStore {.map { String($0.dropFirst("crossover-".count)) }.sorted()}++ // The build runners/current names, without checking that it is usable.+ static func currentBuild(runners: URL = SupportPaths.runners) -> String? {+ let current = runners.appending(path: "current").path(percentEncoded: false)+ return (try? FileManager.default.destinationOfSymbolicLink(atPath: current))+ .flatMap(buildIdentifier(inPath:))+ }++ // Supported builds with a clone on disk, which the tool can be pointed at+ // without copying CrossOver again.+ static func installedBuilds(in runners: URL = SupportPaths.runners) -> [RunnerBuild] {+ clonedBuilds(in: runners)+ .compactMap(SupportedRunners.build(id:))+ .filter { RunnerInstaller.hasClone(forBuild: $0.id, runners: runners) }+ }}diff --git a/app/Sources/NotProtonApp/SystemStatus.swift b/app/Sources/NotProtonApp/SystemStatus.swiftindex 1da4e43..133bf37 100644--- a/app/Sources/NotProtonApp/SystemStatus.swift+++ b/app/Sources/NotProtonApp/SystemStatus.swift@@ -21,6 +21,7 @@ struct StatusSnapshot: Sendable {var crossOverLicense: CrossOverLicense.Status?var runner: RunnerStatevar payload: PayloadState+ var installedRunners: [RunnerBuild] = []static func capture(bundledVersion: String) -> StatusSnapshot {let installs = CrossOverSource.discover()@@ -39,7 +40,8 @@ struct StatusSnapshot: Sendable {runner: runner,payload: PayloadInspector.inspect(build: runner.buildIdentifier.flatMap(SupportedRunners.build(id:))- )+ ),+ installedRunners: RunnerStore.installedBuilds())}}@@ -118,8 +120,22 @@ final class SystemStatus {snapshot?.crossOver.first(where: \.isUsable)}- func checkLicense() async -> CrossOverLicense.Status? {- guard let install = usableCrossOver else { return nil }+ var usableCrossOvers: [CrossOverInstall] {+ snapshot?.crossOver.filter(\.isUsable) ?? []+ }++ // The install a repair of the current tool copies from: the one it was cloned+ // from when that is still around, so a recopy does not swap Rosetta for FEX.+ var setupSource: CrossOverInstall? {+ let current = snapshot?.runner.buildIdentifier+ return usableCrossOvers.first { install in+ if case .supported(let build) = install.support { return build.id == current }+ return false+ } ?? usableCrossOver+ }++ func checkLicense(for chosen: CrossOverInstall? = nil) async -> CrossOverLicense.Status? {+ guard let install = chosen ?? usableCrossOver else { return nil }let status = await Task.detached(priority: .userInitiated) {CrossOverLicense.check(crossOverRoot: install.crossOverRoot)}.value@@ -154,15 +170,28 @@ final class SystemStatus {}}- func requestCompatibilityTool(replacingExisting: Bool = false) async {+ func requestCompatibilityTool(+ from chosen: CrossOverInstall? = nil, replacingExisting: Bool = false+ ) async {+ let install = chosen ?? setupSourceif let question = Self.activationQuestion(.compatibilityTool,- licensed: await checkLicense()?.licensed,+ licensed: await checkLicense(for: install)?.licensed,runner: snapshot?.runner ?? RunnerState.none) {pendingConfirmation = question} else {- await setUpRunner(replacingExisting: replacingExisting)+ await setUpRunner(from: install, replacingExisting: replacingExisting)+ }+ }++ func switchRunner(to build: RunnerBuild) async {+ guard build.id != snapshot?.runner.buildIdentifier else { return }+ await perform(from: RunnerSetup.Phase.staging.label) { progress in+ let result = try await Task.detached(priority: .userInitiated) {+ try RunnerSetup.activate(build, report: { progress($0.label) })+ }.value+ return "Now using build \(result.build.displayVersion)."}}@@ -227,8 +256,8 @@ final class SystemStatus {await refresh()}- private func setUpRunner(replacingExisting: Bool = false) async {- guard let install = usableCrossOver else {+ private func setUpRunner(from install: CrossOverInstall?, replacingExisting: Bool = false) async {+ guard let install else {setFailure("No supported copy of CrossOver found.")AppLog.note("run refused: no supported CrossOver")outcome = nildiff --git a/app/Sources/NotProtonApp/Views/StatusView.swift b/app/Sources/NotProtonApp/Views/StatusView.swiftindex 07c4137..6445157 100644--- a/app/Sources/NotProtonApp/Views/StatusView.swift+++ b/app/Sources/NotProtonApp/Views/StatusView.swift@@ -252,9 +252,21 @@ struct StatusView: View {updateBlockRow(snapshot.updateBlocked)}- Section("Compatibility Tool") {- crossOverRow(snapshot)+ Section {+ crossOverRows(snapshot)runnerRow(snapshot.runner, payload: snapshot.payload)+ if snapshot.installedRunners.count > 1 {+ activeBuildRow(snapshot)+ }+ } header: {+ Text("Compatibility Tool")+ } footer: {+ if status.usableCrossOvers.count > 1 {+ HStack {+ Spacer()+ crossOverLink+ }+ }}componentsSection(snapshot.payload)@@ -383,17 +395,24 @@ struct StatusView: View {)}+ // One copy keeps the choose button on its row. With several, each row sets up+ // its own build and choosing moves to the section footer.@ViewBuilder- private func crossOverRow(_ snapshot: StatusSnapshot) -> some View {- if let install = snapshot.crossOver.first(where: \.isUsable) {- if case .supported(let build) = install.support {- StatusRow(- title: install.name,- value: "Build \(build.displayVersion)",- tone: snapshot.crossOverLicense?.licensed == true ? .ok : .warning,- detail: install.bundle.path(percentEncoded: false),- action: crossOverAction()- )+ private func crossOverRows(_ snapshot: StatusSnapshot) -> some View {+ let installs = snapshot.crossOver.filter(\.isUsable)+ if !installs.isEmpty {+ ForEach(installs) { install in+ if case .supported(let build) = install.support {+ StatusRow(+ title: install.name,+ value: "Build \(build.displayVersion)",+ tone: snapshot.crossOverLicense?.licensed == true ? .ok : .warning,+ detail: install.bundle.path(percentEncoded: false),+ action: installs.count > 1+ ? setUpAction(for: install, build: build, snapshot: snapshot)+ : crossOverAction()+ )+ }}} else {StatusRow(@@ -405,7 +424,7 @@ struct StatusView: View {}}- private func crossOverAction() -> StatusAction {+ private func crossOverAction(chooseLabel: String = "Choose\u{2026}") -> StatusAction {if status.chosenCrossOver != nil {return StatusAction(label: "Use Search",@@ -414,12 +433,65 @@ struct StatusView: View {) { Task { await status.clearCrossOverChoice() } }}return StatusAction(- label: "Choose\u{2026}",+ label: chooseLabel,help: "Pick a CrossOver install.",isEnabled: status.isIdle) { Task { await status.chooseCrossOver() } }}+ @ViewBuilder+ private var crossOverLink: some View {+ let action = crossOverAction(chooseLabel: "Choose Another Copy\u{2026}")+ Button(action.label, action: action.perform)+ .buttonStyle(.link)+ .disabled(!action.isEnabled)+ .help(action.help ?? "")+ }++ // Only for a build with no clone yet. One already cloned is switched to with+ // the active build picker, and recopied from the row below.+ private func setUpAction(+ for install: CrossOverInstall, build: RunnerBuild, snapshot: StatusSnapshot+ ) -> StatusAction? {+ guard !snapshot.installedRunners.contains(build) else { return nil }+ return StatusAction(+ label: "Set Up",+ isProminent: snapshot.runner == .none,+ help: "Set up the compatibility tool from \(install.name).",+ isEnabled: status.isIdle+ ) {+ Task { await status.requestCompatibilityTool(from: install) }+ }+ }++ private func activeBuildRow(_ snapshot: StatusSnapshot) -> some View {+ Picker(selection: activeBuild) {+ ForEach(snapshot.installedRunners) { build in+ Text(build.displayVersion).tag(Optional(build.id))+ }+ } label: {+ VStack(alignment: .leading, spacing: 2) {+ Text("Active build")+ .font(.headline)+ Text("Prefixes made with a different build will need to be rebuilt.")+ .foregroundStyle(.secondary)+ }+ .padding(.leading, StatusMetrics.textInset)+ }+ .disabled(!status.isIdle)+ .help("Choose which CrossOver build games launch with.")+ }++ private var activeBuild: Binding<String?> {+ Binding(+ get: { status.snapshot?.runner.buildIdentifier },+ set: { picked in+ guard let build = picked.flatMap(SupportedRunners.build(id:)) else { return }+ Task { await status.switchRunner(to: build) }+ }+ )+ }+private func runnerAction(label: String = "Set Up", replacingExisting: Bool = false) -> StatusAction {@@ -427,7 +499,7 @@ struct StatusView: View {label: label,isProminent: true,help: "Set up the compatibility tool from CrossOver.",- isEnabled: status.isIdle && status.usableCrossOver != nil+ isEnabled: status.isIdle && status.setupSource != nil) {Task { await status.requestCompatibilityTool(replacingExisting: replacingExisting) }}@@ -442,7 +514,8 @@ struct StatusView: View {title: "Compatibility Tool",value: "Not set up.",tone: .neutral,- action: runnerAction()+ // Each copy of CrossOver above has its own button when there are several.+ action: status.usableCrossOvers.count > 1 ? nil : runnerAction())case .cloned(let build, let supported):let satisfied = supported && !patchedMissingdiff --git a/app/Tests/NotProtonAppTests/RunnerInstallerTests.swift b/app/Tests/NotProtonAppTests/RunnerInstallerTests.swiftindex f09442e..e10be60 100644--- a/app/Tests/NotProtonAppTests/RunnerInstallerTests.swift+++ b/app/Tests/NotProtonAppTests/RunnerInstallerTests.swift@@ -91,7 +91,9 @@ struct RunnerInstallerTests {// A CrossOver bundle holding only the files the clone path hashes, with the build describing// those exact bytes, so verification passes without a real 1.2G install to copy.- private func makeSupportedInstall(in directory: URL) throws -> (CrossOverInstall, RunnerBuild) {+ private func makeSupportedInstall(+ in directory: URL, version: String = "27.0.0.40921"+ ) throws -> (CrossOverInstall, RunnerBuild) {let bundle = directory.appending(path: "source/CrossOver Preview.app")let wine = bundle.appending(path: "Contents/SharedSupport/CrossOver/lib/wine")@@ -117,7 +119,7 @@ struct RunnerInstallerTests {}let build = RunnerBuild(- bundleVersion: "27.0.0.40921",+ bundleVersion: version,releaseVersion: "20260821",flavor: nil,loaderSHA256: try hash(wine.appending(path: "x86_64-unix/wine")),@@ -130,6 +132,26 @@ struct RunnerInstallerTests {return (install, build)}+ @Test("Cloning another build leaves the active link alone until setup finishes")+ func cloneDoesNotActivate() throws {+ let runners = try makeRunners()+ defer { try? FileManager.default.removeItem(at: runners) }++ let (first, firstBuild) = try makeSupportedInstall(+ in: runners.appending(path: "first"), version: "1.0.0.1"+ )+ let (second, _) = try makeSupportedInstall(+ in: runners.appending(path: "second"), version: "2.0.0.2"+ )++ _ = try RunnerInstaller.clone(from: first, runners: runners)+ #expect(RunnerStore.currentBuild(runners: runners) == nil)++ try RunnerInstaller.pointCurrent(atBuild: firstBuild.id, runners: runners)+ _ = try RunnerInstaller.clone(from: second, runners: runners)+ #expect(RunnerStore.currentBuild(runners: runners) == firstBuild.id)+ }+// The first attempt left the build directory holding the payload's contents, not the payload.// Setup read that as a finished clone, skipped the copy, then failed the lookup itself.@Test("A build directory with no payload in it is cloned again rather than trusted")@@ -189,6 +211,7 @@ struct RunnerInstallerTests {let (install, build) = try makeSupportedInstall(in: runners)_ = try RunnerInstaller.clone(from: install, runners: runners)+ try RunnerInstaller.pointCurrent(atBuild: build.id, runners: runners)let payload = SupportPaths.clonedRoot(forBuild: build.bundleVersion, runners: runners)diff --git a/app/Tests/NotProtonAppTests/RunnerSwitchTests.swift b/app/Tests/NotProtonAppTests/RunnerSwitchTests.swiftnew file mode 100644index 0000000..182a39e--- /dev/null+++ b/app/Tests/NotProtonAppTests/RunnerSwitchTests.swift@@ -0,0 +1,249 @@+import Foundation+import Testing++@testable import NotProtonApp++// Switching points runners/current at a clone that already exists. The steps that hash and+// sign real CrossOver files are stood in for, so what is checked is the order they run in and+// what is left behind when one of them fails.+@Suite("Switching between installed builds")+struct RunnerSwitchTests {++ private static let rosetta = SupportedRunners.all.first { $0.flavor == nil }!+ private static let fex = SupportedRunners.all.first { $0.flavor == "fex" }!++ private static let licensed = CrossOverLicense.Status(+ licensed: true, detail: "CrossOver is activated.", diagnostic: "test"+ )+ private static let unlicensed = CrossOverLicense.Status(+ licensed: false, detail: CrossOverLicense.notActivated, diagnostic: "test"+ )++ private final class Calls: @unchecked Sendable {+ var staged: [String] = []+ var patched: [String] = []+ var currentWhilePatching: String?+ }++ private func makeRunners(cloning builds: [RunnerBuild]) throws -> URL {+ let runners = FileManager.default.temporaryDirectory+ .appending(path: "np-switch-\(UUID().uuidString)")+ for build in builds {+ try FileManager.default.createDirectory(+ at: SupportPaths.clonedRoot(forBuild: build.id, runners: runners)+ .appending(path: "lib/wine"),+ withIntermediateDirectories: true+ )+ }+ return runners+ }++ private func activate(+ _ build: RunnerBuild,+ runners: URL,+ calls: Calls,+ license: CrossOverLicense.Status = licensed,+ failPatch: Bool = false+ ) throws -> RunnerSetup.Outcome {+ try RunnerSetup.activate(+ build,+ runners: runners,+ bridge: runners.appending(path: "bridge"),+ license: { _ in license },+ verify: { _, _ in },+ stage: { build, _, _ in+ calls.staged.append(build.id)+ return []+ },+ patch: { build, _, _ in+ calls.patched.append(build.id)+ calls.currentWhilePatching = RunnerStore.currentBuild(runners: runners)+ if failPatch { throw StepFailure(step: "test", detail: "patch failed") }+ return RunnerPatcher.Outcome()+ }+ )+ }++ @Test("Switching moves the link to the other build")+ func switchesBuild() throws {+ let runners = try makeRunners(cloning: [Self.rosetta, Self.fex])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ let calls = Calls()+ let outcome = try activate(Self.fex, runners: runners, calls: calls)++ #expect(outcome.build == Self.fex)+ #expect(RunnerStore.currentBuild(runners: runners) == Self.fex.id)+ #expect(calls.staged == [Self.fex.id])+ #expect(calls.patched == [Self.fex.id])++ // And back again, which is the point of keeping both clones.+ _ = try activate(Self.rosetta, runners: runners, calls: calls)+ #expect(RunnerStore.currentBuild(runners: runners) == Self.rosetta.id)+ }++ // A launch in between would otherwise find the new build before its ntdll is patched.+ @Test("The link only moves once the target is patched")+ func linkMovesLast() throws {+ let runners = try makeRunners(cloning: [Self.rosetta, Self.fex])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ let calls = Calls()+ _ = try activate(Self.fex, runners: runners, calls: calls)++ #expect(calls.currentWhilePatching == Self.rosetta.id)+ }++ // The bridge holds one build's ntdll, and FEX staging prunes the x86_64 copy Rosetta needs.+ @Test("A failed switch keeps the old build and restages its ntdll")+ func failedSwitchRestoresPrevious() throws {+ let runners = try makeRunners(cloning: [Self.rosetta, Self.fex])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ let calls = Calls()+ #expect(throws: StepFailure.self) {+ try activate(Self.fex, runners: runners, calls: calls, failPatch: true)+ }++ #expect(RunnerStore.currentBuild(runners: runners) == Self.rosetta.id)+ #expect(calls.staged == [Self.fex.id, Self.rosetta.id])+ }++ @Test("A failed bridge restore reports both failures")+ func failedRestoreIsReported() throws {+ let runners = try makeRunners(cloning: [Self.rosetta, Self.fex])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ var staged: [String] = []+ let failure = try #require(throws: StepFailure.self) {+ try RunnerSetup.activate(+ Self.fex,+ runners: runners,+ license: { _ in Self.licensed },+ verify: { _, _ in },+ stage: { build, _, _ in+ staged.append(build.id)+ if build == Self.rosetta {+ throw StepFailure(step: "restore", detail: "disk full")+ }+ return []+ },+ patch: { _, _, _ in+ throw StepFailure(step: "patch", detail: "patch failed")+ }+ )+ }++ #expect(staged == [Self.fex.id, Self.rosetta.id])+ #expect(RunnerStore.currentBuild(runners: runners) == Self.rosetta.id)+ #expect(failure.detail.contains("patch failed"))+ #expect(failure.detail.contains("Restoring the previous build also failed"))+ #expect(failure.detail.contains("disk full"))+ }++ @Test("A build with no clone is refused without touching anything")+ func refusesMissingClone() throws {+ let runners = try makeRunners(cloning: [Self.rosetta])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ let calls = Calls()+ let failure = try #require(throws: StepFailure.self) {+ try activate(Self.fex, runners: runners, calls: calls)+ }++ #expect(failure.detail.contains("has not been set up"))+ #expect(calls.staged.isEmpty)+ #expect(RunnerStore.currentBuild(runners: runners) == Self.rosetta.id)+ }++ // Setting up checks the license, so switching to a clone must not be a way around it.+ @Test("Switching is refused when CrossOver is not activated")+ func refusesUnlicensed() throws {+ let runners = try makeRunners(cloning: [Self.rosetta, Self.fex])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ let calls = Calls()+ #expect(throws: StepFailure.self) {+ try activate(Self.fex, runners: runners, calls: calls, license: Self.unlicensed)+ }++ #expect(calls.staged.isEmpty)+ #expect(RunnerStore.currentBuild(runners: runners) == Self.rosetta.id)+ }++ @Test("Installed builds are supported clones that still have their payload")+ func installedBuildsListing() throws {+ let runners = try makeRunners(cloning: [Self.rosetta, Self.fex])+ defer { try? FileManager.default.removeItem(at: runners) }++ // An unknown build and a clone that lost its payload are not switch targets.+ try FileManager.default.createDirectory(+ at: SupportPaths.clonedRoot(forBuild: "1.0.0.1", runners: runners)+ .appending(path: "lib/wine"),+ withIntermediateDirectories: true+ )+ try FileManager.default.removeItem(+ at: SupportPaths.clonedRoot(forBuild: Self.fex.id, runners: runners)+ )++ #expect(RunnerStore.installedBuilds(in: runners) == [Self.rosetta])+ }+}++@MainActor+@Suite("Choosing which CrossOver to set up from")+struct SetupSourceTests {++ private func install(_ name: String, _ build: RunnerBuild) -> CrossOverInstall {+ CrossOverInstall(+ bundle: URL(filePath: "/Applications/\(name).app"),+ releaseVersion: build.releaseVersion,+ support: .supported(build)+ )+ }++ private func status(runner: RunnerState, installs: [CrossOverInstall]) -> SystemStatus {+ let status = SystemStatus()+ status.snapshot = StatusSnapshot(+ steam: .steamMissing,+ steamRunning: false,+ updateBlocked: false,+ crossOver: installs,+ crossOverLicense: nil,+ runner: runner,+ payload: PayloadInspector.inspect(bridge: FileManager.default.temporaryDirectory)+ )+ return status+ }++ // Copy Again on a FEX tool must not quietly recopy the Rosetta CrossOver listed first.+ @Test("A recopy comes from the install the current build was cloned from")+ func prefersCurrentBuild() {+ let rosetta = install("CrossOver", SupportedRunners.all[0])+ let fex = install("CrossOver FEX", SupportedRunners.all[1])++ let status = status(+ runner: .cloned(build: SupportedRunners.all[1].id, supported: true),+ installs: [rosetta, fex]+ )++ #expect(status.setupSource?.id == fex.id)+ }++ @Test("With no tool set up, the preferred install is used")+ func fallsBackToPreferred() {+ let rosetta = install("CrossOver", SupportedRunners.all[0])+ let fex = install("CrossOver FEX", SupportedRunners.all[1])++ let status = status(runner: .none, installs: [rosetta, fex])++ #expect(status.setupSource?.id == rosetta.id)+ #expect(status.usableCrossOvers.map(\.id) == [rosetta.id, fex.id])+ }+}