Extract shared helpers and async-friendly process execution#25
Merged
Conversation
Replace all blocking `process.waitUntilExit()` calls with `withCheckedThrowingContinuation` + `terminationHandler` via a shared `runAsync` utility, matching the pattern already used in `SimulatorManager.screenshot()`. This avoids blocking actor cooperative threads during long-running subprocesses. Extract duplicated build-detection and device-resolution logic from RunCommand, SnapshotCommand, and MCPServer into shared `detectAndBuild` and `resolveDeviceUDID` helpers in BuildHelpers.swift. Closes #4, closes #6 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…Error Read pipe data eagerly via readabilityHandler instead of inside terminationHandler to prevent deadlock when child output exceeds the ~64KB pipe buffer. Keep using ArgumentParser's ValidationError for CLI device resolution errors to preserve usage hint formatting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace inline Process/terminationHandler in SimulatorManager.screenshot() with runAsync() to avoid pipe buffer deadlock when simctl produces large stderr output. Add hot-reload logging with session IDs for diagnostics. Update integration test skill with toggle tap guidance, sleep timing, and log sanity check instructions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Format files added/modified by this branch to match the swift-format config merged on main. Also replace readabilityHandler-based pipe reading with DispatchGroup + background readDataToEndOfFile() to eliminate a race where terminationHandler could read stdoutData before the readabilityHandler had appended its chunk, causing empty output for short-lived processes like `xcrun --show-sdk-path`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Async process execution (Use async-friendly Process execution in SPMBuildSystem #6): Replace all blocking
process.waitUntilExit()calls inSPMBuildSystem,Compiler,IOSHostBuilder, andIOSPreviewSessionwith a sharedrunAsyncutility that useswithCheckedThrowingContinuation+terminationHandler. This avoids blocking actor cooperative threads during long-running subprocesses (e.g.,swift build).Shared helpers (Extract shared helpers for build-detection and device-resolution #4): Extract duplicated build-detection (5 instances) and device-resolution (3 instances) logic from
RunCommand,SnapshotCommand, andMCPServerintodetectAndBuildandresolveDeviceUDIDhelpers. Net result: -194 lines, +199 lines (including new tests and the two new files).Closes #4, closes #6
Test plan
swift test)AsyncProcessunit tests added and passingswift build && .build/debug/previewsmcp serve— verify MCP tools work with correct stderr logging🤖 Generated with Claude Code