Repository navigation
Harden routing heuristics, add dot_clean timeout, expand tests, add CI #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: macos-15 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Swift version | ||
| run: swift --version | ||
| - name: Build | ||
| run: swift build | ||
| - name: Test | ||
| run: swift test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the executable exits after spawning a subprocess that inherits stdout or stderr,
finishedis signaled before the pipe reaches EOF, so this unconditional wait can block indefinitely and bypass the configured timeout. For example, a script containingsleep 30 &; exit 0makescleanwait about 30 seconds even with a sub-second timeout, leaving the eject UI stuck; apply a deadline to the drain phase as well and close or otherwise release the pipe on expiry.Useful? React with 👍 / 👎.