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
list installed CrossOver builds, add remove button
NotProtonNot7c6137592d7e
diff --git a/app/Sources/NotProtonApp/Model/RunnerInstaller.swift b/app/Sources/NotProtonApp/Model/RunnerInstaller.swiftindex e267231..993494f 100644--- a/app/Sources/NotProtonApp/Model/RunnerInstaller.swift+++ b/app/Sources/NotProtonApp/Model/RunnerInstaller.swift@@ -41,6 +41,25 @@ enum RunnerInstaller {return build}+ static let removeStep = "Remove build"++ static func removeClone(forBuild build: String, runners: URL = SupportPaths.runners) throws {+ let target = SupportPaths.runnerRoot(forBuild: build, runners: runners)+ let path = target.path(percentEncoded: false)++ guard FileManager.default.fileExists(atPath: path) else {+ throw StepFailure(step: removeStep, detail: "Build \(build) is not set up.")+ }+ guard RunnerStore.currentBuild(runners: runners) != build else {+ throw StepFailure(+ step: removeStep,+ detail: "Build \(build) is the active build. Switch to another build first."+ )+ }++ try WriteRefused.catching(path) { try FileManager.default.removeItem(at: target) }+ }+static func hasClone(forBuild build: String, runners: URL = SupportPaths.runners) -> Bool {let root = SupportPaths.clonedRoot(forBuild: build, runners: runners)return FileManager.default.fileExists(diff --git a/app/Sources/NotProtonApp/Model/RunnerSetup.swift b/app/Sources/NotProtonApp/Model/RunnerSetup.swiftindex c09f26e..fd182f4 100644--- a/app/Sources/NotProtonApp/Model/RunnerSetup.swift+++ b/app/Sources/NotProtonApp/Model/RunnerSetup.swift@@ -42,10 +42,6 @@ enum RunnerSetup {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,@@ -66,8 +62,6 @@ enum RunnerSetup {)}- // 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 {diff --git a/app/Sources/NotProtonApp/Model/RunnerStore.swift b/app/Sources/NotProtonApp/Model/RunnerStore.swiftindex a26806d..d8d2ee7 100644--- a/app/Sources/NotProtonApp/Model/RunnerStore.swift+++ b/app/Sources/NotProtonApp/Model/RunnerStore.swift@@ -82,15 +82,42 @@ enum RunnerStore {.sorted()}- // The build that runners/current names, without checking that it is usable.+ static func orphanedClones(in runners: URL = SupportPaths.runners) -> [String] {+ clonedBuilds(in: runners).filter { SupportedRunners.build(id: $0) == nil }+ }++ static func damagedClones(in runners: URL = SupportPaths.runners) -> [String] {+ clonedBuilds(in: runners).filter {+ SupportedRunners.build(id: $0) != nil+ && !RunnerInstaller.hasClone(forBuild: $0, runners: runners)+ }+ }++ static func cloneSize(forBuild build: String, runners: URL = SupportPaths.runners) -> Int64 {+ let root = SupportPaths.runnerRoot(forBuild: build, runners: runners)+ guard let walker = FileManager.default.enumerator(+ at: root,+ includingPropertiesForKeys: [.totalFileAllocatedSizeKey, .fileAllocatedSizeKey],+ options: [.skipsHiddenFiles]+ ) else { return 0 }++ var total: Int64 = 0+ for case let url as URL in walker {+ let values = try? url.resourceValues(+ forKeys: [.totalFileAllocatedSizeKey, .fileAllocatedSizeKey]+ )+ let bytes = values?.totalFileAllocatedSize ?? values?.fileAllocatedSize ?? 0+ total += Int64(bytes)+ }+ return total+ }+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:))diff --git a/app/Sources/NotProtonApp/SystemStatus.swift b/app/Sources/NotProtonApp/SystemStatus.swiftindex e8b46e3..19cf1e5 100644--- a/app/Sources/NotProtonApp/SystemStatus.swift+++ b/app/Sources/NotProtonApp/SystemStatus.swift@@ -22,6 +22,8 @@ struct StatusSnapshot: Sendable {var runner: RunnerStatevar payload: PayloadStatevar installedRunners: [RunnerBuild] = []+ var orphanedRunners: [String] = []+ var damagedRunners: [String] = []static func capture(bundledVersion: String) -> StatusSnapshot {let installs = CrossOverSource.discover()@@ -42,7 +44,9 @@ struct StatusSnapshot: Sendable {payload: PayloadInspector.inspect(build: runner.buildIdentifier.flatMap(SupportedRunners.build(id:))),- installedRunners: RunnerStore.installedBuilds()+ installedRunners: RunnerStore.installedBuilds(),+ orphanedRunners: RunnerStore.orphanedClones(),+ damagedRunners: RunnerStore.damagedClones())}}@@ -69,6 +73,7 @@ final class SystemStatus {case blockUpdatescase installUnlicensedcase toolUnlicensed+ case removeBuildcase removeEverythingvar id: Self { self }@@ -138,14 +143,36 @@ final class SystemStatus {}}- // 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? {+ struct AvailableBuild: Identifiable {+ let install: CrossOverInstall+ let build: RunnerBuild++ var id: String { build.id }+ }++ var repairSource: CrossOverInstall? {let current = snapshot?.runner.buildIdentifierreturn usableCrossOvers.first { install inif case .supported(let build) = install.support { return build.id == current }return false- } ?? usableCrossOver+ }+ }++ var setupSource: CrossOverInstall? { repairSource ?? usableCrossOver }++ var setupSourceIsDeployed: Bool {+ guard case .supported(let build)? = setupSource?.support else { return false }+ return snapshot?.installedRunners.contains(build) ?? false+ }++ var availableBuilds: [AvailableBuild] {+ let installed = snapshot?.installedRunners ?? []+ guard !installed.isEmpty else { return [] }+ return usableCrossOvers.compactMap { install in+ guard case .supported(let build) = install.support,+ !installed.contains(build) else { return nil }+ return AvailableBuild(install: install, build: build)+ }}func checkLicense(for chosen: CrossOverInstall? = nil) async -> CrossOverLicense.Status? {@@ -205,6 +232,29 @@ final class SystemStatus {}}+ private(set) var pendingRemoval: String?++ func requestBuildRemoval(_ build: String) {+ guard isIdle else { return }+ pendingRemoval = build+ pendingConfirmation = .removeBuild+ }++ func cancelBuildRemoval() {+ pendingRemoval = nil+ }++ func removePendingBuild() async {+ guard let build = pendingRemoval else { return }+ pendingRemoval = nil+ await perform(from: RunnerInstaller.removeStep) { _ in+ try await Task.detached(priority: .userInitiated) {+ try RunnerInstaller.removeClone(forBuild: build)+ }.value+ return "Removed build \(SupportedRunners.displayVersion(forID: build))."+ }+ }+func switchRunner(to build: RunnerBuild) async {guard isIdle else { return }guard build.id != snapshot?.runner.buildIdentifier else { return }@@ -396,5 +446,23 @@ final class SystemStatus {}.valuesnapshot = capturedAppLog.note(captured)+ await measureRunnerSizes()+ }++ private(set) var runnerSizes: [String: Int64] = [:]++ func measureRunnerSizes() async {+ let known = Set(runnerSizes.keys)+ let present = await Task.detached(priority: .utility) {+ Set(RunnerStore.clonedBuilds())+ }.value++ for stale in known.subtracting(present) { runnerSizes[stale] = nil }++ for build in present.subtracting(known) {+ runnerSizes[build] = await Task.detached(priority: .utility) {+ RunnerStore.cloneSize(forBuild: build)+ }.value+ }}}diff --git a/app/Sources/NotProtonApp/Views/StatusView.swift b/app/Sources/NotProtonApp/Views/StatusView.swiftindex a9abf89..e752e22 100644--- a/app/Sources/NotProtonApp/Views/StatusView.swift+++ b/app/Sources/NotProtonApp/Views/StatusView.swift@@ -50,6 +50,7 @@ struct StatusRow: View {var tone: StatusTone?var detail: String?+ var secondaryAction: StatusAction?var action: StatusAction?var body: some View {@@ -81,8 +82,17 @@ struct StatusRow: View {}}- if let action {+ if secondaryAction != nil || action != nil {Spacer(minLength: 12)+ }+ if let secondaryAction {+ button(secondaryAction)+ .disabled(!secondaryAction.isEnabled)+ .help(secondaryAction.help ?? "")+ .accessibilityLabel("\(secondaryAction.label), \(title)")+ .padding(.trailing, 8)+ }+ if let action {button(action).disabled(!action.isEnabled).help(action.help ?? "")@@ -159,6 +169,23 @@ struct StatusView: View {+ "the support components used by NotProton.")}+ .confirmationDialog(+ "Are you sure?",+ isPresented: asking(.removeBuild),+ titleVisibility: .visible+ ) {+ Button("Remove", role: .destructive) {+ Task { await status.removePendingBuild() }+ }+ Button("Cancel", role: .cancel) { status.cancelBuildRemoval() }+ } message: {+ if let build = status.pendingRemoval {+ Text(+ "Are you sure you want to remove "+ + "\(SupportedRunners.displayVersion(forID: build))?"+ )+ }+ }.confirmationDialog("Remove everything NotProton has created?",isPresented: asking(.removeEverything),@@ -255,8 +282,9 @@ struct StatusView: View {Section {crossOverRows(snapshot)runnerRow(snapshot.runner, payload: snapshot.payload)- if snapshot.installedRunners.count > 1 {- activeBuildRow(snapshot)+ if snapshot.installedRunners.count > 1 || !snapshot.orphanedRunners.isEmpty+ || !snapshot.damagedRunners.isEmpty || !status.availableBuilds.isEmpty {+ buildRows(snapshot)}} header: {Text("Compatibility Tool")@@ -395,8 +423,6 @@ 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.@ViewBuilderprivate func crossOverRows(_ snapshot: StatusSnapshot) -> some View {let installs = snapshot.crossOver.filter(\.isUsable)@@ -448,8 +474,6 @@ struct StatusView: View {.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? {@@ -464,32 +488,84 @@ struct StatusView: View {}}- 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)+ @ViewBuilder+ private func buildRows(_ snapshot: StatusSnapshot) -> some View {+ let active = snapshot.runner.buildIdentifier+ ForEach(SupportedRunners.all) { build in+ if snapshot.installedRunners.contains(build) {+ let isActive = build.id == active+ StatusRow(+ title: build.displayVersion,+ value: isActive ? "Active build." : buildSize(build.id),+ tone: isActive ? .ok : .neutral,+ secondaryAction: isActive ? nil : removeAction(build.id),+ action: isActive ? nil : useAction(build)+ )+ } else if snapshot.damagedRunners.contains(build.id) {+ StatusRow(+ title: build.displayVersion,+ value: "Damaged Copy",+ tone: .warning,+ detail: buildSize(build.id),+ secondaryAction: removeAction(build.id),+ action: status.availableBuilds.first(where: { $0.id == build.id })+ .map(copyAction)+ )+ } else if let available = status.availableBuilds.first(where: { $0.id == build.id }) {+ StatusRow(+ title: build.displayVersion,+ tone: .neutral,+ action: copyAction(available)+ )}- .padding(.leading, StatusMetrics.textInset)}- .disabled(!status.isIdle)- .help("Choose which CrossOver build games launch with.")+ ForEach(snapshot.orphanedRunners, id: \.self) { build in+ StatusRow(+ title: SupportedRunners.displayVersion(forID: build),+ value: "No longer supported.",+ tone: .warning,+ detail: buildSize(build),+ secondaryAction: removeAction(build)+ )+ }}- 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 buildSize(_ build: String) -> String? {+ status.runnerSizes[build].map {+ ByteCountFormatter.string(fromByteCount: $0, countStyle: .file)+ }+ }++ private func copyAction(_ available: SystemStatus.AvailableBuild) -> StatusAction {+ StatusAction(+ label: "Copy",+ isProminent: true,+ help: "Copy this CrossOver build and use it.",+ isEnabled: status.isIdle+ ) {+ Task { await status.requestCompatibilityTool(from: available.install) }+ }+ }++ private func useAction(_ build: RunnerBuild) -> StatusAction {+ StatusAction(+ label: "Use",+ help: "Launch games with this CrossOver build.",+ isEnabled: status.isIdle+ ) {+ Task { await status.switchRunner(to: build) }+ }+ }++ private func removeAction(_ build: String) -> StatusAction {+ StatusAction(+ label: "Remove",+ role: .destructive,+ help: "Delete this build from disk.",+ isEnabled: status.isIdle+ ) {+ status.requestBuildRemoval(build)+ }}private func runnerAction(@@ -514,18 +590,20 @@ struct StatusView: View {title: "Compatibility Tool",value: "Not set up.",tone: .neutral,- // Each copy of CrossOver above has its own button when there are several.action: status.crossOverRowsOfferSetUp ? nil : runnerAction())case .cloned(let build, let supported):let satisfied = supported && !patchedMissing+ let deployed = status.setupSourceIsDeployedreturn StatusRow(title: "Compatibility Tool",value: "Build \(SupportedRunners.displayVersion(forID: build))"+ (supported ? "" : " (unsupported)"),tone: satisfied ? .ok : .warning,action: satisfied- ? runnerAction(label: "Copy Again", replacingExisting: true)+ ? runnerAction(+ label: deployed ? "Copy Again" : "Copy", replacingExisting: true+ ): runnerAction())case .unpatched(let build, _):diff --git a/app/Tests/NotProtonAppTests/RunnerInstallerTests.swift b/app/Tests/NotProtonAppTests/RunnerInstallerTests.swiftindex e10be60..e8d2ae3 100644--- a/app/Tests/NotProtonAppTests/RunnerInstallerTests.swift+++ b/app/Tests/NotProtonAppTests/RunnerInstallerTests.swift@@ -132,6 +132,26 @@ struct RunnerInstallerTests {return (install, build)}+ @Test("A payload that never finished copying is replaced rather than kept")+ func partialCloneIsReplaced() throws {+ let runners = try makeRunners()+ defer { try? FileManager.default.removeItem(at: runners) }++ let (install, build) = try makeSupportedInstall(in: runners.appending(path: "src"))++ let stale = SupportPaths.clonedRoot(forBuild: build.id, runners: runners)+ try FileManager.default.createDirectory(at: stale, withIntermediateDirectories: true)+ try Data("junk".utf8).write(to: stale.appending(path: "leftover"))+ #expect(!RunnerInstaller.hasClone(forBuild: build.id, runners: runners))++ _ = try RunnerInstaller.clone(from: install, runners: runners)++ #expect(RunnerInstaller.hasClone(forBuild: build.id, runners: runners))+ #expect(!FileManager.default.fileExists(+ atPath: stale.appending(path: "leftover").path(percentEncoded: false)+ ))+ }+@Test("Cloning another build leaves the active link alone until setup finishes")func cloneDoesNotActivate() throws {let runners = try makeRunners()diff --git a/app/Tests/NotProtonAppTests/RunnerSwitchTests.swift b/app/Tests/NotProtonAppTests/RunnerSwitchTests.swiftindex 0503277..a63ac7a 100644--- a/app/Tests/NotProtonAppTests/RunnerSwitchTests.swift+++ b/app/Tests/NotProtonAppTests/RunnerSwitchTests.swift@@ -3,9 +3,6 @@ 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 {@@ -78,12 +75,10 @@ struct RunnerSwitchTests {#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])@@ -96,7 +91,6 @@ struct RunnerSwitchTests {#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])@@ -161,7 +155,6 @@ struct RunnerSwitchTests {#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])@@ -182,7 +175,6 @@ struct RunnerSwitchTests {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"),@@ -222,7 +214,6 @@ struct SetupSourceTests {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])@@ -246,4 +237,176 @@ struct SetupSourceTests {#expect(status.setupSource?.id == rosetta.id)#expect(status.usableCrossOvers.map(\.id) == [rosetta.id, fex.id])}++ @Test("An install matching the current build can repair it")+ func repairSourceMatchesCurrentBuild() {+ let rosetta = install("CrossOver", SupportedRunners.all[0])+ let status = status(+ runner: .cloned(build: SupportedRunners.all[0].id, supported: true),+ installs: [rosetta]+ )+ status.snapshot?.installedRunners = [SupportedRunners.all[0]]++ #expect(status.repairSource?.id == rosetta.id)+ #expect(status.availableBuilds.isEmpty)+ }++ @Test("An install offering another build cannot repair the current one")+ func repairSourceIsNilWhenBuildDiffers() {+ let rosetta = install("CrossOver", SupportedRunners.all[0])+ let status = status(+ runner: .cloned(build: SupportedRunners.all[1].id, supported: true),+ installs: [rosetta]+ )+ status.snapshot?.installedRunners = [SupportedRunners.all[1]]++ #expect(status.repairSource == nil)+ #expect(status.setupSource?.id == rosetta.id)+ #expect(status.availableBuilds.map(\.id) == [SupportedRunners.all[0].id])+ }++ @Test("A build already on disk is not offered as available")+ func deployedBuildIsNotOffered() {+ 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]+ )+ status.snapshot?.installedRunners = SupportedRunners.all++ #expect(status.repairSource?.id == fex.id)+ #expect(status.availableBuilds.isEmpty)+ }++ @Test("With nothing set up the runner row keeps the offer to itself")+ func nothingOfferedBeforeFirstSetUp() {+ let rosetta = install("CrossOver", SupportedRunners.all[0])+ let status = status(runner: .none, installs: [rosetta])++ #expect(status.repairSource == nil)+ #expect(status.setupSource?.id == rosetta.id)+ #expect(status.availableBuilds.isEmpty)+ }+}++@Suite("Removing an installed build")+struct RunnerRemovalTests {++ private static let rosetta = SupportedRunners.all.first { $0.flavor == nil }!+ private static let fex = SupportedRunners.all.first { $0.flavor == "fex" }!++ private func makeRunners(cloning builds: [String]) throws -> URL {+ let runners = FileManager.default.temporaryDirectory+ .appending(path: "np-remove-\(UUID().uuidString)")+ for build in builds {+ try FileManager.default.createDirectory(+ at: SupportPaths.clonedRoot(forBuild: build, runners: runners)+ .appending(path: "lib/wine"),+ withIntermediateDirectories: true+ )+ }+ return runners+ }++ @Test("A build that is not active is deleted from disk")+ func removesInactiveBuild() throws {+ let runners = try makeRunners(cloning: [Self.rosetta.id, Self.fex.id])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ try RunnerInstaller.removeClone(forBuild: Self.fex.id, runners: runners)++ #expect(!RunnerInstaller.hasClone(forBuild: Self.fex.id, runners: runners))+ #expect(RunnerInstaller.hasClone(forBuild: Self.rosetta.id, runners: runners))+ #expect(RunnerStore.currentBuild(runners: runners) == Self.rosetta.id)+ }++ @Test("The active build is refused so the tool keeps working")+ func refusesActiveBuild() throws {+ let runners = try makeRunners(cloning: [Self.rosetta.id, Self.fex.id])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ #expect(throws: StepFailure.self) {+ try RunnerInstaller.removeClone(forBuild: Self.rosetta.id, runners: runners)+ }+ #expect(RunnerInstaller.hasClone(forBuild: Self.rosetta.id, runners: runners))+ }++ @Test("A build with no clone reports rather than succeeding quietly")+ func refusesMissingBuild() throws {+ let runners = try makeRunners(cloning: [Self.rosetta.id])+ defer { try? FileManager.default.removeItem(at: runners) }++ #expect(throws: StepFailure.self) {+ try RunnerInstaller.removeClone(forBuild: Self.fex.id, runners: runners)+ }+ }++ @Test("A supported build whose payload never finished copying is listed as damaged")+ func damagedCloneIsListed() throws {+ let runners = try makeRunners(cloning: [Self.rosetta.id])+ defer { try? FileManager.default.removeItem(at: runners) }++ try FileManager.default.createDirectory(+ at: SupportPaths.clonedRoot(forBuild: Self.fex.id, runners: runners),+ withIntermediateDirectories: true+ )++ #expect(RunnerStore.damagedClones(in: runners) == [Self.fex.id])+ #expect(RunnerStore.orphanedClones(in: runners).isEmpty)+ #expect(RunnerStore.installedBuilds(in: runners).map(\.id) == [Self.rosetta.id])+ }++ @Test("Every clone on disk lands in exactly one of the three lists")+ func cloneListsPartition() throws {+ let runners = try makeRunners(cloning: [Self.rosetta.id, "1.2.3.4567"])+ defer { try? FileManager.default.removeItem(at: runners) }++ try FileManager.default.createDirectory(+ at: SupportPaths.clonedRoot(forBuild: Self.fex.id, runners: runners),+ withIntermediateDirectories: true+ )++ let installed = RunnerStore.installedBuilds(in: runners).map(\.id)+ let damaged = RunnerStore.damagedClones(in: runners)+ let orphaned = RunnerStore.orphanedClones(in: runners)+ let all = installed + damaged + orphaned++ #expect(Set(all) == Set(RunnerStore.clonedBuilds(in: runners)))+ #expect(all.count == Set(all).count)+ }++ @Test("Clones of unsupported versions are listed apart from installed builds")+ func orphanedClonesAreFound() throws {+ let runners = try makeRunners(cloning: [Self.rosetta.id, "1.2.3.4567"])+ defer { try? FileManager.default.removeItem(at: runners) }++ #expect(RunnerStore.orphanedClones(in: runners) == ["1.2.3.4567"])+ #expect(RunnerStore.installedBuilds(in: runners).map(\.id) == [Self.rosetta.id])+ }++ @Test("An orphaned clone can be removed")+ func removesOrphanedClone() throws {+ let runners = try makeRunners(cloning: [Self.rosetta.id, "1.2.3.4567"])+ defer { try? FileManager.default.removeItem(at: runners) }+ try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)++ try RunnerInstaller.removeClone(forBuild: "1.2.3.4567", runners: runners)++ #expect(RunnerStore.orphanedClones(in: runners).isEmpty)+ #expect(RunnerInstaller.hasClone(forBuild: Self.rosetta.id, runners: runners))+ }++ @Test("A clone's size counts the bytes it occupies")+ func measuresCloneSize() throws {+ let runners = try makeRunners(cloning: [Self.rosetta.id])+ defer { try? FileManager.default.removeItem(at: runners) }+ let file = SupportPaths.clonedRoot(forBuild: Self.rosetta.id, runners: runners)+ .appending(path: "lib/wine/blob")+ try Data(repeating: 0, count: 64 * 1024).write(to: file)++ #expect(RunnerStore.cloneSize(forBuild: Self.rosetta.id, runners: runners) >= 64 * 1024)+ }}