Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

feat: per-program settings (launch arguments, environment, renderer) + test suite

Gauthier Piarrette1a69bcd0be90
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 1cd138c..4010dba 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -240,6 +240,15 @@ final class AppState {
update(copy)
}
+ /// Replace a pin wholesale (program settings sheet: arguments, environment, renderer).
+ func updatePin(_ pin: Pin, in bottle: Bottle) {
+ var copy = bottle
+ if let i = copy.settings.pins.firstIndex(where: { $0.id == pin.id }) {
+ copy.settings.pins[i] = pin
+ update(copy)
+ }
+ }
+
func setPinRenderer(_ renderer: Renderer?, pin: Pin, in bottle: Bottle) {
var copy = bottle
if let i = copy.settings.pins.firstIndex(where: { $0.id == pin.id }) {
diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swift
index 0faf4ee..36c1e96 100644
--- a/Sources/HighballApp/BottleView.swift
+++ b/Sources/HighballApp/BottleView.swift
@@ -35,6 +35,7 @@ struct BottleView: View {
]
@State private var showSettings = false
+ @State private var editingPin: Pin?
private var engine: InstalledEngine? { state.engine(for: bottle) }
private var games: [SteamGame] {
@@ -96,6 +97,7 @@ struct BottleView: View {
}
}
.sheet(isPresented: $showSettings) { BottleSettingsSheet(bottle: bottle) }
+ .sheet(item: $editingPin) { p in PinSettingsSheet(pin: p, bottle: bottle) }
.onDrop(of: [.fileURL], isTargeted: nil) { providers in
guard let provider = providers.first else { return false }
_ = provider.loadObject(ofClass: URL.self) { url, _ in
@@ -227,6 +229,7 @@ struct BottleView: View {
.contextMenu {
if installed, let pin {
Button(L("Open")) { state.launch(pin: pin, in: bottle) }
+ Button(L("Program settings…")) { editingPin = pin }
Button(L("Remove from list"), role: .destructive) { state.removePin(pin, from: bottle) }
}
}
@@ -259,6 +262,7 @@ struct BottleView: View {
.background(HB.card)
.help(pin.path)
.contextMenu {
+ Button(L("Program settings…")) { editingPin = pin }
Menu(L("Renderer override")) {
Button(L("Bottle default")) { state.setPinRenderer(nil, pin: pin, in: bottle) }
ForEach(Renderer.allCases, id: \.self) { r in
@@ -739,6 +743,74 @@ struct EpicSignInSheet: View {
}
+/// Per-program settings: launch arguments, environment, renderer override in one place.
+struct PinSettingsSheet: View {
+ @Environment(AppState.self) private var state
+ @Environment(\.dismiss) private var dismiss
+ let bottle: Bottle
+ @State private var pin: Pin
+ @State private var argsText: String
+ @State private var envText: String
+
+ init(pin: Pin, bottle: Bottle) {
+ self.bottle = bottle
+ _pin = State(initialValue: pin)
+ _argsText = State(initialValue: ArgumentLine.join(pin.arguments))
+ _envText = State(initialValue: pin.environment.sorted { $0.key < $1.key }
+ .map { "\($0.key)=\($0.value)" }.joined(separator: "\n"))
+ }
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 14) {
+ Text(pin.name).font(.title2.bold())
+ Text(pin.path).font(.caption.monospaced()).foregroundStyle(.secondary)
+ .lineLimit(1).truncationMode(.middle)
+ VStack(alignment: .leading, spacing: 6) {
+ Text(L("Launch arguments")).font(.callout.weight(.medium))
+ TextField(L("-dx11 -skiplauncher \"an argument with spaces\""), text: $argsText)
+ .textFieldStyle(.roundedBorder).font(.body.monospaced())
+ Text(L("Passed to the program on every launch. Quote arguments that contain spaces."))
+ .font(.caption).foregroundStyle(.secondary)
+ }
+ VStack(alignment: .leading, spacing: 6) {
+ Text(L("Environment")).font(.callout.weight(.medium))
+ TextEditor(text: $envText)
+ .font(.body.monospaced()).frame(height: 64)
+ .overlay(RoundedRectangle(cornerRadius: 6).stroke(.quaternary))
+ Text(L("One KEY=VALUE per line, applied only to this program."))
+ .font(.caption).foregroundStyle(.secondary)
+ }
+ Picker(L("Renderer"), selection: $pin.renderer) {
+ Text(L("Bottle default")).tag(Renderer?.none)
+ ForEach(Renderer.allCases, id: \.self) { r in
+ Text(r.rawValue.uppercased()).tag(Renderer?.some(r))
+ }
+ }
+ .pickerStyle(.menu)
+ HStack {
+ Spacer()
+ Button(L("Cancel")) { dismiss() }
+ Button(L("Save")) {
+ pin.arguments = ArgumentLine.split(argsText)
+ var env: [String: String] = [:]
+ for line in envText.split(separator: "\n") {
+ let parts = line.split(separator: "=", maxSplits: 1).map(String.init)
+ if parts.count == 2, !parts[0].trimmingCharacters(in: .whitespaces).isEmpty {
+ env[parts[0].trimmingCharacters(in: .whitespaces)] = parts[1]
+ }
+ }
+ pin.environment = env
+ state.updatePin(pin, in: bottle)
+ dismiss()
+ }
+ .keyboardShortcut(.defaultAction)
+ }
+ }
+ .padding(24)
+ .frame(width: 460)
+ }
+}
+
/// Bottle environment editor: one KEY=VALUE per line, saved on every keystroke batch.
struct EnvEditor: View {
@Environment(AppState.self) private var state
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swift
index 0a7fa29..9cf0369 100644
--- a/Sources/HighballKit/Bottle.swift
+++ b/Sources/HighballKit/Bottle.swift
@@ -57,6 +57,61 @@ public struct Pin: Codable, Sendable, Identifiable, Hashable {
public init(name: String, path: String, arguments: [String] = [], environment: [String: String] = [:], renderer: Renderer? = nil) {
self.name = name; self.path = path; self.arguments = arguments; self.environment = environment; self.renderer = renderer
}
+
+ enum CodingKeys: String, CodingKey { case id, name, path, arguments, environment, renderer }
+
+ /// Lenient decode: hand-written recipe pins may omit id/arguments/environment.
+ /// (The synthesized decoder treats defaulted non-optionals as required keys.)
+ public init(from decoder: Decoder) throws {
+ let c = try decoder.container(keyedBy: CodingKeys.self)
+ id = try c.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
+ name = try c.decode(String.self, forKey: .name)
+ path = try c.decode(String.self, forKey: .path)
+ arguments = try c.decodeIfPresent([String].self, forKey: .arguments) ?? []
+ environment = try c.decodeIfPresent([String: String].self, forKey: .environment) ?? [:]
+ renderer = try c.decodeIfPresent(Renderer.self, forKey: .renderer)
+ }
+}
+
+/// One-line editing of a pin's argument list. Double quotes group words; backslash
+/// escapes only a following quote (so Windows paths like C:\Games pass through
+/// untouched); everything else is literal.
+public enum ArgumentLine {
+ public static func split(_ line: String) -> [String] {
+ var args: [String] = []
+ var cur = ""
+ var inQuotes = false
+ var started = false
+ var i = line.startIndex
+ while i < line.endIndex {
+ let ch = line[i]
+ let next = line.index(after: i)
+ if ch == "\\", next < line.endIndex, line[next] == "\"" {
+ cur.append("\""); started = true
+ i = line.index(after: next)
+ continue
+ }
+ if ch == "\"" {
+ inQuotes.toggle(); started = true
+ } else if (ch == " " || ch == "\t") && !inQuotes {
+ if started { args.append(cur); cur = ""; started = false }
+ } else {
+ cur.append(ch); started = true
+ }
+ i = next
+ }
+ if started { args.append(cur) }
+ return args
+ }
+
+ public static func join(_ args: [String]) -> String {
+ args.map { a in
+ if a.isEmpty { return "\"\"" }
+ let escaped = a.replacingOccurrences(of: "\"", with: "\\\"")
+ let needsQuotes = a.contains(" ") || a.contains("\t")
+ return needsQuotes ? "\"\(escaped)\"" : escaped
+ }.joined(separator: " ")
+ }
}
/// Persisted as `<bottle>/gin.json`.
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index 8f29502..9778cc4 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -148,9 +148,13 @@ public struct WineRunner: Sendable {
/// identity instead. The pair MUST exist in Wine's GPU table or the override is silently
/// discarded ("Invalid GPU override" in winediag): 0x1002:0x73bf is Radeon RX 6800/6900 XT,
/// present in Wine 10's table. Applied at bottle creation and by Repair.
+ /// AMD RX 6800/6900 XT. Regression-tested: changing this to a pair absent from Wine's
+ /// GPU table silently reverts bottles to the fake-NVIDIA identity (the 0.7.1 bug).
+ public static let gpuIdentity: (vendor: Int, device: Int) = (0x1002, 0x73bf)
+
public func setGpuIdentity() async throws {
- try await regAdd(key: #"HKCU\Software\Wine\Direct3D"#, name: "VideoPciVendorID", type: "REG_DWORD", data: String(0x1002))
- try await regAdd(key: #"HKCU\Software\Wine\Direct3D"#, name: "VideoPciDeviceID", type: "REG_DWORD", data: String(0x73bf))
+ try await regAdd(key: #"HKCU\Software\Wine\Direct3D"#, name: "VideoPciVendorID", type: "REG_DWORD", data: String(Self.gpuIdentity.vendor))
+ try await regAdd(key: #"HKCU\Software\Wine\Direct3D"#, name: "VideoPciDeviceID", type: "REG_DWORD", data: String(Self.gpuIdentity.device))
}
public func setWindowsVersion(_ v: WindowsVersion) async throws {
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index c5dd023..0f065c4 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -7,7 +7,7 @@ struct Highball: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "highball",
abstract: "Highball — run Windows games on Apple Silicon. Free, open, engine-agnostic.",
- subcommands: [Engine.self, Bottle.self, Run.self, Recipe.self, Tricks.self, Env.self, Epic.self, Report.self, BugReportCommand.self, Verify.self],
+ subcommands: [Engine.self, Bottle.self, Run.self, PinCommand.self, Recipe.self, Tricks.self, Env.self, Epic.self, Report.self, BugReportCommand.self, Verify.self],
defaultSubcommand: nil
)
}
@@ -188,6 +188,65 @@ struct Bottle: AsyncParsableCommand {
// MARK: - gin run
+// MARK: - gin pin
+
+struct PinCommand: AsyncParsableCommand {
+ static let configuration = CommandConfiguration(
+ commandName: "pin",
+ abstract: "Per-program settings: persistent launch arguments, environment, renderer.",
+ subcommands: [List.self, Set.self])
+
+ struct List: AsyncParsableCommand {
+ @Argument var bottle: String
+ func run() async throws {
+ let b = try BottleStore().get(bottle)
+ if b.settings.pins.isEmpty { print("no pins in \(b.name)"); return }
+ for p in b.settings.pins {
+ var extras: [String] = []
+ if !p.arguments.isEmpty { extras.append("args=\(ArgumentLine.join(p.arguments))") }
+ if !p.environment.isEmpty { extras.append("env=" + p.environment.sorted { $0.key < $1.key }.map { "\($0.key)=\($0.value)" }.joined(separator: ";")) }
+ if let r = p.renderer { extras.append("renderer=\(r.rawValue)") }
+ print("\(p.name)\t\(p.path)" + (extras.isEmpty ? "" : "\t" + extras.joined(separator: "\t")))
+ }
+ }
+ }
+
+ struct Set: AsyncParsableCommand {
+ static let configuration = CommandConfiguration(abstract: "Change a pin setting: args (rest of line), renderer (name or default), env KEY=VALUE (VALUE empty removes).")
+ @Argument var bottle: String
+ @Argument var pin: String
+ @Argument var setting: String
+ @Argument(parsing: .remaining) var value: [String] = []
+
+ func run() async throws {
+ let bs = BottleStore()
+ var b = try bs.get(bottle)
+ guard let i = b.settings.pins.firstIndex(where: { $0.name.lowercased() == pin.lowercased() }) else {
+ fail("no pin '\(pin)' in \(b.name) (pins: \(b.settings.pins.map(\.name).joined(separator: ", ")))")
+ }
+ switch setting {
+ case "args":
+ b.settings.pins[i].arguments = value.count == 1 ? ArgumentLine.split(value[0]) : value
+ case "renderer":
+ guard let v = value.first else { fail("renderer expects a value or 'default'") }
+ if v == "default" || v == "none" { b.settings.pins[i].renderer = nil }
+ else if let r = HighballKit.Renderer(rawValue: v) { b.settings.pins[i].renderer = r }
+ else { fail("bad renderer \(v)") }
+ case "env":
+ guard let v = value.first else { fail("env expects KEY=VALUE") }
+ let parts = v.split(separator: "=", maxSplits: 1).map(String.init)
+ guard parts.count == 2 else { fail("env expects KEY=VALUE") }
+ if parts[1].isEmpty { b.settings.pins[i].environment.removeValue(forKey: parts[0]) }
+ else { b.settings.pins[i].environment[parts[0]] = parts[1] }
+ default: fail("unknown setting \(setting) (args, renderer, env)")
+ }
+ try bs.update(b)
+ let p = b.settings.pins[i]
+ print("ok — \(p.name): args=[\(ArgumentLine.join(p.arguments))] renderer=\(p.renderer?.rawValue ?? "default") env=\(p.environment.count) vars")
+ }
+ }
+}
+
struct Run: AsyncParsableCommand {
static let configuration = CommandConfiguration(abstract: "Run a program in a bottle: a pin name, a Windows path, or a Unix path.")
@Argument var bottle: String
diff --git a/Tests/GinKitTests/ArgumentLineTests.swift b/Tests/GinKitTests/ArgumentLineTests.swift
new file mode 100644
index 0000000..10d8a36
--- /dev/null
+++ b/Tests/GinKitTests/ArgumentLineTests.swift
@@ -0,0 +1,51 @@
+import XCTest
+@testable import HighballKit
+
+/// The one-line argument editor behind the per-program settings sheet and
+/// `highball pin set <bottle> <pin> args`. Windows paths are full of backslashes,
+/// so the split rules must never eat them.
+final class ArgumentLineTests: XCTestCase {
+ func testBasicSplit() {
+ XCTAssertEqual(ArgumentLine.split("-dx11 -skiplauncher"), ["-dx11", "-skiplauncher"])
+ XCTAssertEqual(ArgumentLine.split(""), [])
+ XCTAssertEqual(ArgumentLine.split(" "), [])
+ XCTAssertEqual(ArgumentLine.split("one"), ["one"])
+ XCTAssertEqual(ArgumentLine.split("a\tb c"), ["a", "b", "c"])
+ }
+
+ func testQuotedArguments() {
+ XCTAssertEqual(ArgumentLine.split(#"-config "C:\my folder\cfg.ini""#),
+ ["-config", #"C:\my folder\cfg.ini"#])
+ XCTAssertEqual(ArgumentLine.split(#""two words" plain"#), ["two words", "plain"])
+ XCTAssertEqual(ArgumentLine.split(#""""#), [""]) // explicit empty argument
+ }
+
+ func testWindowsBackslashesSurvive() {
+ // Backslash is only an escape before a quote; bare path separators pass through.
+ XCTAssertEqual(ArgumentLine.split(#"C:\Games\thing.exe"#), [#"C:\Games\thing.exe"#])
+ XCTAssertEqual(ArgumentLine.split(#"-path C:\a\b\c"#), ["-path", #"C:\a\b\c"#])
+ }
+
+ func testEscapedQuote() {
+ XCTAssertEqual(ArgumentLine.split(#"say \"hi\""#), ["say", "\"hi\""])
+ }
+
+ func testJoinQuotesWhatNeedsIt() {
+ XCTAssertEqual(ArgumentLine.join(["-dx11", "two words"]), #"-dx11 "two words""#)
+ XCTAssertEqual(ArgumentLine.join([]), "")
+ XCTAssertEqual(ArgumentLine.join([""]), #""""#)
+ }
+
+ func testRoundTrips() {
+ let cases: [[String]] = [
+ ["-dx11", "-skiplauncher"],
+ ["-config", #"C:\my folder\cfg.ini"#],
+ [#"C:\Games\a b\x.exe"#, "--flag"],
+ ["quote\"inside", "plain"],
+ [],
+ ]
+ for args in cases {
+ XCTAssertEqual(ArgumentLine.split(ArgumentLine.join(args)), args, "round trip failed for \(args)")
+ }
+ }
+}
diff --git a/Tests/GinKitTests/EnvironmentTests.swift b/Tests/GinKitTests/EnvironmentTests.swift
new file mode 100644
index 0000000..c174559
--- /dev/null
+++ b/Tests/GinKitTests/EnvironmentTests.swift
@@ -0,0 +1,97 @@
+import XCTest
+@testable import HighballKit
+
+/// The launch environment is where most field bugs lived (Steam's CEF hang, DLL
+/// overrides, renderer overlays). These tests pin its composition rules.
+final class EnvironmentTests: XCTestCase {
+
+ private func fixtures() throws -> (engine: InstalledEngine, bottle: Bottle) {
+ let manifestURL = URL(fileURLWithPath: #filePath)
+ .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
+ .appending(path: "spike/engine-manifest.json")
+ let manifest = try EngineManifest.load(from: manifestURL)
+ let root = FileManager.default.temporaryDirectory.appending(path: "hb-test-engine-\(UUID().uuidString)")
+ let engine = InstalledEngine(manifest: manifest, root: root)
+ let bottle = Bottle(url: URL(fileURLWithPath: "/tmp/hb-test-bottle"),
+ settings: BottleSettings(name: "t", engineID: manifest.id))
+ return (engine, bottle)
+ }
+
+ // Steam's CEF webhelper hangs under msync/esync on Wine 10. sync=none must write
+ // explicit zeros, not merely omit the variables.
+ func testSyncNoneWritesExplicitZeros() throws {
+ var (engine, bottle) = try fixtures()
+ bottle.settings.sync = .none
+ let env = try bottle.environment(engine: engine, renderer: .wined3d)
+ XCTAssertEqual(env["WINEMSYNC"], "0")
+ XCTAssertEqual(env["WINEESYNC"], "0")
+ }
+
+ func testSyncModes() throws {
+ var (engine, bottle) = try fixtures()
+ bottle.settings.sync = .msync
+ var env = try bottle.environment(engine: engine, renderer: .wined3d)
+ XCTAssertEqual(env["WINEMSYNC"], "1")
+ XCTAssertEqual(env["WINEESYNC"], "0")
+ bottle.settings.sync = .esync
+ env = try bottle.environment(engine: engine, renderer: .wined3d)
+ XCTAssertEqual(env["WINEESYNC"], "1")
+ XCTAssertEqual(env["WINEMSYNC"], "0")
+ }
+
+ func testPrefixAndDebugAlwaysSet() throws {
+ let (engine, bottle) = try fixtures()
+ let env = try bottle.environment(engine: engine, renderer: .wined3d)
+ XCTAssertEqual(env["WINEPREFIX"], "/tmp/hb-test-bottle")
+ XCTAssertEqual(env["WINEDEBUG"], "fixme-all")
+ }
+
+ // Bottle-level DLL overrides (the #17 feature) reach WINEDLLOVERRIDES, and compose
+ // with an override the user also set via the env editor, joined by ";".
+ func testDllOverridesCompose() throws {
+ var (engine, bottle) = try fixtures()
+ bottle.settings.dllOverrides = "version=n,b"
+ var env = try bottle.environment(engine: engine, renderer: .wined3d)
+ XCTAssertEqual(env["WINEDLLOVERRIDES"], "version=n,b")
+
+ bottle.settings.environment["WINEDLLOVERRIDES+"] = "libglesv2=d"
+ env = try bottle.environment(engine: engine, renderer: .wined3d)
+ let v = env["WINEDLLOVERRIDES"] ?? ""
+ XCTAssertTrue(v.contains("version=n,b") && v.contains("libglesv2=d"), "got \(v)")
+ XCTAssertTrue(v.contains(";"), "WINEDLLOVERRIDES parts must be ';'-joined, got \(v)")
+ }
+
+ // extra (per-pin environment from the program settings sheet) wins over bottle env.
+ func testExtraEnvironmentWins() throws {
+ var (engine, bottle) = try fixtures()
+ bottle.settings.environment["MY_FLAG"] = "bottle"
+ let env = try bottle.environment(engine: engine, renderer: .wined3d, extra: ["MY_FLAG": "pin"])
+ XCTAssertEqual(env["MY_FLAG"], "pin")
+ }
+
+ func testTogglesAndFpsCap() throws {
+ var (engine, bottle) = try fixtures()
+ bottle.settings.metalHUD = true
+ bottle.settings.advertiseAVX = true
+ bottle.settings.fpsCap = 60
+ var env = try bottle.environment(engine: engine, renderer: .wined3d)
+ XCTAssertEqual(env["MTL_HUD_ENABLED"], "1")
+ XCTAssertEqual(env["ROSETTA_ADVERTISE_AVX"], "1")
+ XCTAssertNil(env["DXVK_FRAME_RATE"], "wined3d has no fps cap channel")
+
+ // DXVK renderer needs its overlay dir on disk for environment() to succeed.
+ let dxvkWine = engine.renderersDir.appending(path: "dxvk/wine")
+ try FileManager.default.createDirectory(at: dxvkWine, withIntermediateDirectories: true)
+ defer { try? FileManager.default.removeItem(at: engine.root) }
+ env = try bottle.environment(engine: engine, renderer: .dxvk)
+ XCTAssertEqual(env["DXVK_FRAME_RATE"], "60")
+ XCTAssertEqual(env["DXVK_ASYNC"], "1", "dxvkAsync defaults on")
+ XCTAssertEqual(env["WINEDLLPATH_PREPEND"], dxvkWine.path)
+ }
+
+ // A renderer whose overlay is missing must throw, not silently fall back.
+ func testMissingRendererThrows() throws {
+ let (engine, bottle) = try fixtures()
+ XCTAssertThrowsError(try bottle.environment(engine: engine, renderer: .dxmt))
+ }
+}
diff --git a/Tests/GinKitTests/RecipeDBTests.swift b/Tests/GinKitTests/RecipeDBTests.swift
new file mode 100644
index 0000000..676ffe5
--- /dev/null
+++ b/Tests/GinKitTests/RecipeDBTests.swift
@@ -0,0 +1,76 @@
+import XCTest
+@testable import HighballKit
+
+/// Every recipe and db entry shipped from highball-db must decode with the current
+/// Recipe/GameDBEntry types — this is the drift tripwire between the two repos.
+/// Skips cleanly when the sibling checkout isn't present (e.g. bare CI).
+final class RecipeDBTests: XCTestCase {
+
+ private var dbRoot: URL {
+ URL(fileURLWithPath: #filePath)
+ .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
+ .deletingLastPathComponent().appending(path: "highball-db")
+ }
+
+ func testAllShippedRecipesDecode() throws {
+ let recipes = dbRoot.appending(path: "recipes")
+ guard FileManager.default.fileExists(atPath: recipes.path) else {
+ throw XCTSkip("highball-db checkout not found next to the repo")
+ }
+ var checked = 0
+ for sub in ["launchers", "games", "tweaks"] {
+ let dir = recipes.appending(path: sub)
+ guard let files = try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil) else { continue }
+ for f in files where f.pathExtension == "json" {
+ let r: Recipe
+ do { r = try JSONDecoder.gin.decode(Recipe.self, from: Data(contentsOf: f)) }
+ catch { XCTFail("\(f.lastPathComponent) failed to decode: \(error)"); continue }
+ XCTAssertFalse(r.id.isEmpty, f.lastPathComponent)
+ XCTAssertFalse(r.title.isEmpty, f.lastPathComponent)
+ for step in r.steps {
+ if case let .installer(url, _, _, _) = step {
+ XCTAssertEqual(url.scheme, "https", "\(f.lastPathComponent): installer URLs must be https")
+ }
+ }
+ checked += 1
+ }
+ }
+ XCTAssertGreaterThan(checked, 5, "expected to find shipped recipes; wrong path?")
+ }
+
+ func testAllShippedGameDBEntriesDecode() throws {
+ let dir = dbRoot.appending(path: "db/games")
+ guard FileManager.default.fileExists(atPath: dir.path) else {
+ throw XCTSkip("highball-db checkout not found next to the repo")
+ }
+ var checked = 0
+ for f in try FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil)
+ where f.pathExtension == "json" {
+ do {
+ let e = try JSONDecoder.gin.decode(GameDBEntry.self, from: Data(contentsOf: f))
+ XCTAssertFalse(e.id.isEmpty, f.lastPathComponent)
+ XCTAssertTrue(["verified-local", "reported-upstream", "community", "blocked-anticheat"].contains(e.status),
+ "\(f.lastPathComponent): unknown status '\(e.status)'")
+ } catch {
+ XCTFail("\(f.lastPathComponent) failed to decode: \(error)")
+ }
+ checked += 1
+ }
+ XCTAssertGreaterThan(checked, 0)
+ }
+
+ // The GOG recipe regression: the web installer trips its service-pack check under
+ // Wine's win10 profile. The recipe must keep pointing at the offline installer.
+ func testGogRecipeUsesOfflineInstaller() throws {
+ let f = dbRoot.appending(path: "recipes/launchers/gog-galaxy.json")
+ guard FileManager.default.fileExists(atPath: f.path) else {
+ throw XCTSkip("highball-db checkout not found next to the repo")
+ }
+ let r = try JSONDecoder.gin.decode(Recipe.self, from: Data(contentsOf: f))
+ let installers = r.steps.compactMap { step -> URL? in
+ if case let .installer(url, _, _, _) = step { return url } else { return nil }
+ }
+ XCTAssertFalse(installers.contains { $0.absoluteString.contains("webinstallers") },
+ "web installer fails its Windows 7 SP1 check under wine win10 — use the offline setup exe")
+ }
+}
diff --git a/Tests/GinKitTests/RegressionTests.swift b/Tests/GinKitTests/RegressionTests.swift
new file mode 100644
index 0000000..3dd0871
--- /dev/null
+++ b/Tests/GinKitTests/RegressionTests.swift
@@ -0,0 +1,91 @@
+import XCTest
+@testable import HighballKit
+
+/// Tripwires for bugs that shipped once and must not ship twice.
+final class RegressionTests: XCTestCase {
+
+ // Issue #12: Windows-invalid characters in a bottle name break wineboot (exit 53).
+ func testBottleNameValidation() {
+ XCTAssertNil(BottleStore.nameProblem("games"))
+ XCTAssertNil(BottleStore.nameProblem("My Bottle 2"))
+ for bad in ["a:b", "a/b", #"a\b"#, "a?b", "a*b", "a<b", "a>b", "a|b", "a\"b"] {
+ XCTAssertNotNil(BottleStore.nameProblem(bad), "'\(bad)' must be rejected")
+ }
+ XCTAssertNotNil(BottleStore.nameProblem(""))
+ XCTAssertNotNil(BottleStore.nameProblem(" "))
+ XCTAssertNotNil(BottleStore.nameProblem(".hidden"))
+ XCTAssertNotNil(BottleStore.nameProblem("dot."))
+ XCTAssertNotNil(BottleStore.nameProblem(String(repeating: "x", count: 65)))
+ }
+
+ // 0.7.1 shipped a GPU identity absent from Wine's table; Wine silently ignored it
+ // ("Invalid GPU override") and bottles stayed on the fake-NVIDIA identity that
+ // makes CS:GO-class games demand NVAPI and die. 0x1002:0x73bf is in Wine 10's table.
+ func testGpuIdentityStaysTableValid() {
+ let id = WineRunner.gpuIdentity
+ XCTAssertEqual(id.vendor, 0x1002, "AMD vendor id — do not change without checking Wine's GPU table")
+ XCTAssertEqual(id.device, 0x73bf, "must exist in Wine's wined3d GPU table (0x73df does NOT)")
+ XCTAssertNotEqual(id.device, 0x73df, "0x73df is the known-bad pair Wine rejects")
+ XCTAssertLessThanOrEqual(id.vendor, 0xffff, "registry override values above 0xffff are rejected")
+ XCTAssertLessThanOrEqual(id.device, 0xffff)
+ }
+
+ // Legendary's list-installed JSON uses `title`, not `app_title` (which the owned-games
+ // endpoint uses). Decoding with the wrong type broke the Epic library view in 0.7.0 dev.
+ func testEpicInstalledGameDecode() throws {
+ let json = #"[{"app_name":"Duck","title":"Cardpocalypse","version":"1.0"}]"#
+ let games = try JSONDecoder().decode([EpicStore.InstalledGame].self, from: Data(json.utf8))
+ XCTAssertEqual(games.first?.app_name, "Duck")
+ }
+
+ // Old bottles carry gin.json written by earlier versions without newer fields.
+ // Decoding must fill defaults, never throw (an early 0.5.x crashed on this class).
+ func testSettingsDecodeFromOldVersion() throws {
+ let old = #"{"formatVersion":1,"name":"aged","engineID":"x64-test","renderer":"dxmt","windowsVersion":"win10","sync":"msync","metalHUD":false,"advertiseAVX":false,"pins":[{"id":"6B1F0D2A-0000-4000-8000-000000000001","name":"Steam","path":"Program Files (x86)/Steam/steam.exe"}],"environment":{},"recipes":[]}"#
+ let s = try JSONDecoder.gin.decode(BottleSettings.self, from: Data(old.utf8))
+ XCTAssertEqual(s.name, "aged")
+ XCTAssertEqual(s.retinaMode, false, "field added in 0.7.x must default off")
+ XCTAssertEqual(s.dllOverrides, "", "field added in 0.7.2 must default empty")
+ XCTAssertEqual(s.fpsCap, 0)
+ XCTAssertEqual(s.dxvkAsync, true)
+ XCTAssertEqual(s.pins.first?.arguments, [], "pin arguments default to empty")
+ XCTAssertEqual(s.pins.first?.environment, [:])
+ XCTAssertNil(s.pins.first?.renderer)
+ }
+
+ // Steam writes StateFlags 1026 while downloading; the game card must not offer Play.
+ func testACFDownloadingNotReady() throws {
+ let acf = """
+ "AppState"
+ {
+ \t"appid"\t\t"730"
+ \t"name"\t\t"Counter-Strike 2"
+ \t"StateFlags"\t\t"1026"
+ \t"installdir"\t\t"Counter-Strike Global Offensive"
+ }
+ """
+ let tmp = FileManager.default.temporaryDirectory.appending(path: "appmanifest_730.acf")
+ try acf.write(to: tmp, atomically: true, encoding: .utf8)
+ defer { try? FileManager.default.removeItem(at: tmp) }
+ let game = SteamLibrary.parseManifest(tmp)
+ XCTAssertEqual(game?.appid, 730)
+ XCTAssertEqual(game?.isReady, false)
+ }
+
+ // resolve() must accept both drive-letter cases (CLI users type c:\ freely).
+ func testWindowsPathLowercaseDrive() {
+ let b = Bottle(url: URL(fileURLWithPath: "/tmp/b"), settings: BottleSettings(name: "b", engineID: "e"))
+ XCTAssertEqual(b.resolve(windowsPath: #"c:\windows\system32\cmd.exe"#).path,
+ "/tmp/b/drive_c/windows/system32/cmd.exe")
+ }
+
+ // Pins round trip with everything the program settings sheet can write.
+ func testPinFullRoundTrip() throws {
+ var p = Pin(name: "Launcher", path: "Games/l.exe")
+ p.arguments = ["-dx11", #"C:\a b\cfg"#]
+ p.environment = ["WINE_SIMULATE_WRITECOPY": "1"]
+ p.renderer = .dxvk
+ let back = try JSONDecoder.gin.decode(Pin.self, from: JSONEncoder.gin.encode(p))
+ XCTAssertEqual(back, p)
+ }
+}