From 36c7b6ea3b30814c26783eabfba673963c418089 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 29 Sep 2026 11:23:12 +0000 Subject: [PATCH 1/3] Harden routing heuristics, add dot_clean timeout, expand tests, add CI - Match aliases as whole words after normalizing separators; drop padded aliases - Require a same-stem (or multi-track) CUE to route a BIN to PlayStation - Time out hung dot_clean and drain its output concurrently - Add tests for ImportExecutor, MetadataCleaner symlinks, m3u/CUE resolution - Add macOS GitHub Actions workflow running swift build/test Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Apys6XL8BAS3tGcbfB2hYu --- .github/workflows/ci.yml | 16 ++++ README.md | 2 +- Sources/BrickDrop/DotCleanRunner.swift | 38 +++++++- Sources/BrickDrop/RoutingEngine.swift | 50 ++++++---- .../BrickDropTests/DotCleanRunnerTests.swift | 18 ++++ .../BrickDropTests/ImportExecutorTests.swift | 93 +++++++++++++++++++ Tests/BrickDropTests/ImportPlannerTests.swift | 33 +++++++ .../BrickDropTests/MetadataCleanerTests.swift | 44 +++++++++ Tests/BrickDropTests/RoutingEngineTests.swift | 34 +++++++ 9 files changed, 304 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 Tests/BrickDropTests/ImportExecutorTests.swift diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..aa47b39 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,16 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + test: + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build + - name: Test + run: swift test diff --git a/README.md b/README.md index 526722e..4206027 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ The cleaner does not follow symbolic links and does not delete files merely beca ## Development -The routing, disc-set planning, and metadata safety behavior are covered by XCTest tests in `Tests/BrickDropTests`. +The routing, disc-set planning, copy semantics (skip/overwrite), and metadata safety (including symlinks) are covered by XCTest tests in `Tests/BrickDropTests`. ```sh swift build diff --git a/Sources/BrickDrop/DotCleanRunner.swift b/Sources/BrickDrop/DotCleanRunner.swift index 408f6cf..1bf45a3 100644 --- a/Sources/BrickDrop/DotCleanRunner.swift +++ b/Sources/BrickDrop/DotCleanRunner.swift @@ -2,6 +2,7 @@ import Foundation enum DotCleanError: LocalizedError { case failed(exitCode: Int32, message: String) + case timedOut(seconds: TimeInterval) var errorDescription: String? { switch self { @@ -10,15 +11,23 @@ enum DotCleanError: LocalizedError { return detail.isEmpty ? "dot_clean failed with exit code \(exitCode)." : "dot_clean failed: \(detail)" + case .timedOut(let seconds): + return "dot_clean did not finish within \(Int(seconds)) seconds and was stopped." } } } +private final class OutputBox: @unchecked Sendable { + var data = Data() +} + struct DotCleanRunner: Sendable { let executableURL: URL + let timeout: TimeInterval - init(executableURL: URL = URL(fileURLWithPath: "/usr/sbin/dot_clean")) { + init(executableURL: URL = URL(fileURLWithPath: "/usr/sbin/dot_clean"), timeout: TimeInterval = 120) { self.executableURL = executableURL + self.timeout = timeout } @discardableResult @@ -30,10 +39,31 @@ struct DotCleanRunner: Sendable { process.standardOutput = output process.standardError = output + let finished = DispatchSemaphore(value: 0) + process.terminationHandler = { _ in finished.signal() } try process.run() - process.waitUntilExit() - let data = output.fileHandleForReading.readDataToEndOfFile() - let message = String(data: data, encoding: .utf8) ?? "" + + // Drain the pipe concurrently so a chatty child can't block on a full buffer. + let box = OutputBox() + let drained = DispatchGroup() + drained.enter() + DispatchQueue.global().async { + box.data = output.fileHandleForReading.readDataToEndOfFile() + drained.leave() + } + + if finished.wait(timeout: .now() + timeout) == .timedOut { + process.terminate() + if finished.wait(timeout: .now() + 2) == .timedOut { + kill(process.processIdentifier, SIGKILL) + finished.wait() + } + _ = drained.wait(timeout: .now() + 2) + throw DotCleanError.timedOut(seconds: timeout) + } + drained.wait() + + let message = String(data: box.data, encoding: .utf8) ?? "" guard process.terminationStatus == 0 else { throw DotCleanError.failed(exitCode: process.terminationStatus, message: message) } diff --git a/Sources/BrickDrop/RoutingEngine.swift b/Sources/BrickDrop/RoutingEngine.swift index 90d09de..90823ea 100644 --- a/Sources/BrickDrop/RoutingEngine.swift +++ b/Sources/BrickDrop/RoutingEngine.swift @@ -22,7 +22,7 @@ struct RoutingEngine: Sendable { private let aliases: [ROMSystem: [String]] = [ .fc: ["fc", "nes", "famicom"], .sfc: ["sfc", "snes", "superfamicom", "super nintendo"], - .gb: ["gameboy", "game boy", " dmg "], + .gb: ["gameboy", "game boy", "dmg"], .gbc: ["gbc", "gameboycolor", "game boy color"], .gba: ["gba", "gameboyadvance", "game boy advance"], .n64: ["n64", "nintendo64", "nintendo 64"], @@ -32,7 +32,7 @@ struct RoutingEngine: Sendable { .ms: ["mastersystem", "master system"], .pce: ["pcengine", "pc engine", "turbografx", "tg16"], .ps: ["ps1", "psx", "playstation", "psone"], - .dc: ["dreamcast", " dc "], + .dc: ["dreamcast", "dc"], .psp: ["psp"], .arcade: ["arcade", "mame", "fbneo", "fba"], .neogeo: ["neogeo", "neo geo"] @@ -54,9 +54,11 @@ struct RoutingEngine: Sendable { let stem = fileURL.deletingPathExtension().lastPathComponent.lowercased() let hasCue = siblingNames.contains { name in let sibling = URL(fileURLWithPath: name) - return sibling.pathExtension.lowercased() == "cue" && - sibling.deletingPathExtension().lastPathComponent.lowercased() == stem - } || siblingNames.contains { URL(fileURLWithPath: $0).pathExtension.lowercased() == "cue" } + guard sibling.pathExtension.lowercased() == "cue" else { return false } + let cueStem = sibling.deletingPathExtension().lastPathComponent.lowercased() + // Multi-track dumps name their files "Game (Track 1).bin" next to "Game.cue". + return stem == cueStem || stem.hasPrefix(cueStem + " (track") + } if hasCue { return .resolved(.ps, reason: "BIN is part of a CUE disc set") } if let heuristic = systemFromContext(context) { return .resolved(heuristic, reason: "Detected \(heuristic.displayName) from its name or source folder") @@ -127,25 +129,35 @@ struct RoutingEngine: Sendable { .compactMap { $0 }.joined(separator: " ")) } + /// Lowercases and turns every non-alphanumeric run into a single space, padded on both ends, + /// so aliases can be matched as whole words with a plain substring search. private func normalized(_ value: String) -> String { - " " + value.lowercased() - .replacingOccurrences(of: "_", with: " ") - .replacingOccurrences(of: "-", with: " ") - .replacingOccurrences(of: "/", with: " ") + " " + var result = " " + var lastWasSpace = true + for scalar in value.lowercased().unicodeScalars { + if CharacterSet.alphanumerics.contains(scalar) { + result.unicodeScalars.append(scalar) + lastWasSpace = false + } else if !lastWasSpace { + result.append(" ") + lastWasSpace = true + } + } + return lastWasSpace ? result : result + " " } private func systemFromContext(_ context: String, allowed: Set? = nil) -> ROMSystem? { - // More specific aliases win before shorter terms such as GB. - let ordered = ROMSystem.allCases.sorted { - let left = aliases[$0, default: []].map(\.count).max() ?? 0 - let right = aliases[$1, default: []].map(\.count).max() ?? 0 - return left > right - } - for system in ordered where allowed?.contains(system) ?? true { - for alias in aliases[system, default: []] where context.contains(alias) { - return system - } + // Longest alias first so "game boy color" beats "game boy"; whole-word matching keeps + // short aliases like "nes" or "dc" from firing inside longer words. + for entry in orderedAliases where allowed?.contains(entry.system) ?? true { + if context.contains(" \(entry.alias) ") { return entry.system } } return nil } + + private var orderedAliases: [(alias: String, system: ROMSystem)] { + ROMSystem.allCases + .flatMap { system in aliases[system, default: []].map { (alias: $0, system: system) } } + .sorted { $0.alias.count > $1.alias.count } + } } diff --git a/Tests/BrickDropTests/DotCleanRunnerTests.swift b/Tests/BrickDropTests/DotCleanRunnerTests.swift index 0a2ebe5..a870da1 100644 --- a/Tests/BrickDropTests/DotCleanRunnerTests.swift +++ b/Tests/BrickDropTests/DotCleanRunnerTests.swift @@ -19,4 +19,22 @@ final class DotCleanRunnerTests: XCTestCase { XCTAssertNotEqual(exitCode, 0) } } + + func testTimesOutHungProcess() { + let started = Date() + + // A script that ignores its arguments and never finishes on its own. + let script = FileManager.default.temporaryDirectory.appending(path: "hang-\(UUID().uuidString).sh") + defer { try? FileManager.default.removeItem(at: script) } + XCTAssertNoThrow(try "#!/bin/sh\nexec sleep 30\n".write(to: script, atomically: true, encoding: .utf8)) + XCTAssertNoThrow(try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: script.path)) + + let hanging = DotCleanRunner(executableURL: script, timeout: 0.5) + XCTAssertThrowsError(try hanging.clean(volumeURL: URL(fileURLWithPath: "/Volumes/Card"))) { error in + guard case DotCleanError.timedOut = error else { + return XCTFail("Unexpected error: \(error)") + } + } + XCTAssertLessThan(Date().timeIntervalSince(started), 10) + } } diff --git a/Tests/BrickDropTests/ImportExecutorTests.swift b/Tests/BrickDropTests/ImportExecutorTests.swift new file mode 100644 index 0000000..46ed917 --- /dev/null +++ b/Tests/BrickDropTests/ImportExecutorTests.swift @@ -0,0 +1,93 @@ +import XCTest +@testable import BrickDrop + +final class ImportExecutorTests: XCTestCase { + private var directory: URL! + + override func setUpWithError() throws { + directory = FileManager.default.temporaryDirectory.appending(path: "BrickDropExecutor-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: directory.appending(path: "SD"), withIntermediateDirectories: true) + } + + override func tearDownWithError() throws { + if let directory { try? FileManager.default.removeItem(at: directory) } + } + + private func makeItem(contents: UInt8, status: ImportStatus = .ready, withDestination: Bool = true) throws -> ImportItem { + let source = directory.appending(path: "Tetris-\(UUID().uuidString).gb") + try Data([contents]).write(to: source) + return ImportItem( + sourceURL: source, + system: .gb, + candidateSystems: [.gb], + destinationURL: withDestination ? directory.appending(path: "SD/Roms/GB/Tetris.gb") : nil, + status: status, + detail: "" + ) + } + + func testCopiesIntoNewDestinationDirectories() throws { + let item = try makeItem(contents: 1) + let report = ImportExecutor().execute(items: [item], sdRoot: directory.appending(path: "SD"), overwriteExisting: false) + + XCTAssertEqual(report.copied, [item.id]) + XCTAssertEqual(try Data(contentsOf: item.destinationURL!), Data([1])) + } + + func testSkipsExistingFileWhenNotOverwriting() throws { + let existing = try makeItem(contents: 1) + _ = ImportExecutor().execute(items: [existing], sdRoot: directory.appending(path: "SD"), overwriteExisting: false) + let replacement = try makeItem(contents: 2) + + let report = ImportExecutor().execute(items: [replacement], sdRoot: directory.appending(path: "SD"), overwriteExisting: false) + + XCTAssertEqual(report.skipped, [replacement.id]) + XCTAssertTrue(report.copied.isEmpty) + XCTAssertEqual(try Data(contentsOf: replacement.destinationURL!), Data([1])) + } + + func testReplacesExistingFileWhenOverwriting() throws { + let existing = try makeItem(contents: 1) + _ = ImportExecutor().execute(items: [existing], sdRoot: directory.appending(path: "SD"), overwriteExisting: false) + let replacement = try makeItem(contents: 2) + + let report = ImportExecutor().execute(items: [replacement], sdRoot: directory.appending(path: "SD"), overwriteExisting: true) + + XCTAssertEqual(report.copied, [replacement.id]) + XCTAssertEqual(try Data(contentsOf: replacement.destinationURL!), Data([2])) + } + + func testIgnoresItemsThatAreNotReady() throws { + let item = try makeItem(contents: 1, status: .needsChoice) + let report = ImportExecutor().execute(items: [item], sdRoot: directory.appending(path: "SD"), overwriteExisting: true) + + XCTAssertTrue(report.copied.isEmpty) + XCTAssertFalse(FileManager.default.fileExists(atPath: item.destinationURL!.path)) + } + + func testReportsFailureForMissingDestinationOrSource() throws { + let noDestination = try makeItem(contents: 1, withDestination: false) + var missingSource = try makeItem(contents: 1) + try FileManager.default.removeItem(at: missingSource.sourceURL) + missingSource.destinationURL = directory.appending(path: "SD/Roms/GB/Other.gb") + + let report = ImportExecutor().execute( + items: [noDestination, missingSource], sdRoot: directory.appending(path: "SD"), overwriteExisting: false + ) + + XCTAssertNotNil(report.failures[noDestination.id]) + XCTAssertNotNil(report.failures[missingSource.id]) + XCTAssertTrue(report.copied.isEmpty) + } + + func testCleansMetadataAfterCopy() throws { + let sd = directory.appending(path: "SD") + try Data([9]).write(to: sd.appending(path: ".DS_Store")) + let item = try makeItem(contents: 1) + + let report = ImportExecutor().execute(items: [item], sdRoot: sd, overwriteExisting: false) + + XCTAssertEqual(report.cleanup.removedCount, 1) + XCTAssertFalse(FileManager.default.fileExists(atPath: sd.appending(path: ".DS_Store").path)) + } +} diff --git a/Tests/BrickDropTests/ImportPlannerTests.swift b/Tests/BrickDropTests/ImportPlannerTests.swift index 8ac4808..3df980a 100644 --- a/Tests/BrickDropTests/ImportPlannerTests.swift +++ b/Tests/BrickDropTests/ImportPlannerTests.swift @@ -64,3 +64,36 @@ final class ImportPlannerTests: XCTestCase { XCTAssertTrue(items.allSatisfy { $0.destinationURL?.path.contains("Roms/PS/Game/") == true }) } } + +extension ImportPlannerTests { + func testM3UIncludesExistingReferencedDiscsAndSkipsMissingOnes() throws { + let source = temporaryDirectory.appending(path: "Source") + let sd = temporaryDirectory.appending(path: "SD") + try FileManager.default.createDirectory(at: source, withIntermediateDirectories: true) + try FileManager.default.createDirectory(at: sd, withIntermediateDirectories: true) + let playlist = source.appending(path: "Final Fantasy VII PS1.m3u") + try "# comment\nDisc 1.chd\n\nDisc 2.chd\nMissing.chd\n".write(to: playlist, atomically: true, encoding: .utf8) + try Data([1]).write(to: source.appending(path: "Disc 1.chd")) + try Data([2]).write(to: source.appending(path: "Disc 2.chd")) + + let items = ImportPlanner().plan(urls: [playlist], sdRoot: sd) + + XCTAssertEqual(items.count, 3) + XCTAssertTrue(items.allSatisfy { $0.system == .ps }) + XCTAssertTrue(items.contains { $0.destinationURL?.path.hasSuffix("Roms/PS/Final Fantasy VII PS1/Disc 2.chd") == true }) + } + + func testCueIgnoresMissingAndUnquotedReferences() throws { + let source = temporaryDirectory.appending(path: "Source") + let sd = temporaryDirectory.appending(path: "SD") + try FileManager.default.createDirectory(at: source, withIntermediateDirectories: true) + try FileManager.default.createDirectory(at: sd, withIntermediateDirectories: true) + let cue = source.appending(path: "Game.cue") + try "FILE Track01.bin BINARY\nFILE \"Missing.bin\" BINARY\n".write(to: cue, atomically: true, encoding: .utf8) + try Data([1]).write(to: source.appending(path: "Track01.bin")) + + let items = ImportPlanner().plan(urls: [cue], sdRoot: sd) + + XCTAssertEqual(items.map { $0.sourceURL.lastPathComponent }.sorted(), ["Game.cue", "Track01.bin"]) + } +} diff --git a/Tests/BrickDropTests/MetadataCleanerTests.swift b/Tests/BrickDropTests/MetadataCleanerTests.swift index 40eec95..85ac692 100644 --- a/Tests/BrickDropTests/MetadataCleanerTests.swift +++ b/Tests/BrickDropTests/MetadataCleanerTests.swift @@ -24,4 +24,48 @@ final class MetadataCleanerTests: XCTestCase { XCTAssertFalse(FileManager.default.fileExists(atPath: appleDouble.path)) XCTAssertFalse(FileManager.default.fileExists(atPath: dsStore.path)) } + + func testCleanerNeverFollowsOrRemovesSymlinks() throws { + let base = FileManager.default.temporaryDirectory.appending(path: "BrickDropSymlink-\(UUID().uuidString)") + defer { try? FileManager.default.removeItem(at: base) } + let root = base.appending(path: "SD") + let outside = base.appending(path: "Outside") + try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true) + try FileManager.default.createDirectory(at: outside.appending(path: ".Trashes"), withIntermediateDirectories: true) + let outsideMetadata = outside.appending(path: "._precious") + let outsideDSStore = outside.appending(path: ".DS_Store") + try Data([1]).write(to: outsideMetadata) + try Data([2]).write(to: outsideDSStore) + + // A symlinked directory pointing outside the card, one named like metadata, and a file symlink. + let linkedDirectory = root.appending(path: "Linked") + let linkedTrashes = root.appending(path: ".Trashes") + let linkedAppleDouble = root.appending(path: "._link") + try FileManager.default.createSymbolicLink(at: linkedDirectory, withDestinationURL: outside) + try FileManager.default.createSymbolicLink(at: linkedTrashes, withDestinationURL: outside.appending(path: ".Trashes")) + try FileManager.default.createSymbolicLink(at: linkedAppleDouble, withDestinationURL: outsideMetadata) + + let report = MetadataCleaner().clean(root: root) + + XCTAssertEqual(report.removedCount, 0) + XCTAssertTrue(FileManager.default.fileExists(atPath: outsideMetadata.path)) + XCTAssertTrue(FileManager.default.fileExists(atPath: outsideDSStore.path)) + XCTAssertTrue(FileManager.default.fileExists(atPath: outside.appending(path: ".Trashes").path)) + for link in [linkedDirectory, linkedTrashes, linkedAppleDouble] { + XCTAssertNotNil(try? FileManager.default.destinationOfSymbolicLink(atPath: link.path), link.lastPathComponent) + } + } + + func testCleanerRemovesMetadataDirectoriesRecursively() throws { + let root = FileManager.default.temporaryDirectory.appending(path: "BrickDropDirs-\(UUID().uuidString)") + defer { try? FileManager.default.removeItem(at: root) } + let trashes = root.appending(path: ".Trashes/501") + try FileManager.default.createDirectory(at: trashes, withIntermediateDirectories: true) + try Data([1]).write(to: trashes.appending(path: "old.gb")) + + let report = MetadataCleaner().clean(root: root) + + XCTAssertEqual(report.removedCount, 1) + XCTAssertFalse(FileManager.default.fileExists(atPath: root.appending(path: ".Trashes").path)) + } } diff --git a/Tests/BrickDropTests/RoutingEngineTests.swift b/Tests/BrickDropTests/RoutingEngineTests.swift index 04c6f4f..2503857 100644 --- a/Tests/BrickDropTests/RoutingEngineTests.swift +++ b/Tests/BrickDropTests/RoutingEngineTests.swift @@ -51,4 +51,38 @@ final class RoutingEngineTests: XCTestCase { let decision = router.route(fileURL: URL(fileURLWithPath: "/ROMs/Arcade/galaga.zip")) XCTAssertEqual(decision.system, .arcade) } + + func testAliasesMatchWholeWordsOnly() { + // "nes" must not fire inside "business", nor "dc" inside "DCollection". + XCTAssertNil(router.route(fileURL: URL(fileURLWithPath: "/Incoming/business.iso")).system) + XCTAssertNil(router.route(fileURL: URL(fileURLWithPath: "/Incoming/DCollection.iso")).system) + XCTAssertNil(router.route(fileURL: URL(fileURLWithPath: "/Incoming/Genesis2.zip")).system) + } + + func testAliasesMatchAcrossSeparators() { + XCTAssertEqual(router.route(fileURL: URL(fileURLWithPath: "/Incoming/dmg-game.zip")).system, .gb) + XCTAssertEqual(router.route(fileURL: URL(fileURLWithPath: "/Incoming/DC_Sonic.chd")).system, .dc) + XCTAssertEqual(router.route(fileURL: URL(fileURLWithPath: "/Incoming/Sonic (NES).zip")).system, .fc) + } + + func testLongestAliasWins() { + let decision = router.route(fileURL: URL(fileURLWithPath: "/Incoming/Game Boy Color/Pokemon.zip")) + XCTAssertEqual(decision.system, .gbc) + } + + func testBinIgnoresUnrelatedCueInSameFolder() { + let decision = router.route( + fileURL: URL(fileURLWithPath: "/Incoming/Genesis/sonic.bin"), + siblingNames: ["ridge.cue", "sonic.bin"] + ) + XCTAssertEqual(decision.system, .md) + } + + func testMultiTrackBinMatchesCue() { + let decision = router.route( + fileURL: URL(fileURLWithPath: "/Incoming/Ridge Racer (Track 1).bin"), + siblingNames: ["Ridge Racer.cue", "Ridge Racer (Track 1).bin"] + ) + XCTAssertEqual(decision.system, .ps) + } } From e2ba58e3e2a665975dc7da85993694b26174a7f8 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 29 Sep 2026 11:30:57 +0000 Subject: [PATCH 2/3] Match (Disc N) BINs to a single CUE; bound post-SIGKILL wait Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Apys6XL8BAS3tGcbfB2hYu --- Sources/BrickDrop/DotCleanRunner.swift | 2 +- Sources/BrickDrop/RoutingEngine.swift | 5 +++-- Tests/BrickDropTests/RoutingEngineTests.swift | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/BrickDrop/DotCleanRunner.swift b/Sources/BrickDrop/DotCleanRunner.swift index 1bf45a3..0ed4b15 100644 --- a/Sources/BrickDrop/DotCleanRunner.swift +++ b/Sources/BrickDrop/DotCleanRunner.swift @@ -56,7 +56,7 @@ struct DotCleanRunner: Sendable { process.terminate() if finished.wait(timeout: .now() + 2) == .timedOut { kill(process.processIdentifier, SIGKILL) - finished.wait() + _ = finished.wait(timeout: .now() + 2) } _ = drained.wait(timeout: .now() + 2) throw DotCleanError.timedOut(seconds: timeout) diff --git a/Sources/BrickDrop/RoutingEngine.swift b/Sources/BrickDrop/RoutingEngine.swift index 90823ea..9415e66 100644 --- a/Sources/BrickDrop/RoutingEngine.swift +++ b/Sources/BrickDrop/RoutingEngine.swift @@ -56,8 +56,9 @@ struct RoutingEngine: Sendable { let sibling = URL(fileURLWithPath: name) guard sibling.pathExtension.lowercased() == "cue" else { return false } let cueStem = sibling.deletingPathExtension().lastPathComponent.lowercased() - // Multi-track dumps name their files "Game (Track 1).bin" next to "Game.cue". - return stem == cueStem || stem.hasPrefix(cueStem + " (track") + // Multi-track/disc dumps name their files "Game (Track 1).bin" or "Game (Disc 1).bin" + // next to a single "Game.cue". + return stem == cueStem || stem.hasPrefix(cueStem + " (track") || stem.hasPrefix(cueStem + " (disc") } if hasCue { return .resolved(.ps, reason: "BIN is part of a CUE disc set") } if let heuristic = systemFromContext(context) { diff --git a/Tests/BrickDropTests/RoutingEngineTests.swift b/Tests/BrickDropTests/RoutingEngineTests.swift index 2503857..291dafe 100644 --- a/Tests/BrickDropTests/RoutingEngineTests.swift +++ b/Tests/BrickDropTests/RoutingEngineTests.swift @@ -85,4 +85,12 @@ final class RoutingEngineTests: XCTestCase { ) XCTAssertEqual(decision.system, .ps) } + + func testMultiDiscBinMatchesSingleCue() { + let decision = router.route( + fileURL: URL(fileURLWithPath: "/Incoming/Game (Disc 1).bin"), + siblingNames: ["Game.cue", "Game (Disc 1).bin"] + ) + XCTAssertEqual(decision.system, .ps) + } } From e7b9dbc31797681765815fffb6539c95e7982549 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 29 Sep 2026 11:33:38 +0000 Subject: [PATCH 3/3] CI: use macos-15 runner for Swift 6 tools version Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Apys6XL8BAS3tGcbfB2hYu --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa47b39..93c6c2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,9 +7,11 @@ on: jobs: test: - runs-on: macos-14 + runs-on: macos-15 steps: - uses: actions/checkout@v4 + - name: Swift version + run: swift --version - name: Build run: swift build - name: Test