refactor(6/12): migrate simulator tools to event-based handlers#324
refactor(6/12): migrate simulator tools to event-based handlers#324cameroncooke wants to merge 4 commits intorefactor/runtime-handler-contractfrom
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Malformed JSON mock embeds command args in device array
- Removed the incorrectly placed '-derivedDataPath' and DERIVED_DATA_DIR strings from the devices array in both test cases, restoring valid simctl JSON structure.
Or push these changes by commenting:
@cursor push 4dad9e6f53
Preview (4dad9e6f53)
diff --git a/src/mcp/tools/simulator/__tests__/build_run_sim.test.ts b/src/mcp/tools/simulator/__tests__/build_run_sim.test.ts
--- a/src/mcp/tools/simulator/__tests__/build_run_sim.test.ts
+++ b/src/mcp/tools/simulator/__tests__/build_run_sim.test.ts
@@ -194,8 +194,6 @@
state: 'Booted',
isAvailable: true,
},
- '-derivedDataPath',
- DERIVED_DATA_DIR,
],
},
}),
@@ -277,8 +275,6 @@
state: 'Booted',
isAvailable: true,
},
- '-derivedDataPath',
- DERIVED_DATA_DIR,
],
},
}),This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Reviewed by Cursor Bugbot for commit daf00b3. Configure here.
089f6a3 to
fa1ece2
Compare
daf00b3 to
d9e9216
Compare
fa1ece2 to
e6e44bb
Compare
d9e9216 to
90f6699
Compare
| `Inferred simulator platform for tests: ${inferred.platform} (source: ${inferred.source})`, | ||
| ); | ||
|
|
||
| return handleTestLogic( | ||
| const ctx = getHandlerContext(); | ||
|
|
||
| const simulatorResolution = await resolveSimulatorIdOrName( | ||
| executor, | ||
| params.simulatorId, | ||
| params.simulatorName, | ||
| ); |
There was a problem hiding this comment.
Bug: The new simulator resolution logic uses a strict, case-sensitive match, a regression from xcodebuild's more flexible matching, which may cause existing test setups to fail.
Severity: MEDIUM
Suggested Fix
To restore the previous, more flexible behavior, consider passing the simulator name directly to xcodebuild instead of pre-resolving it with resolveSimulatorIdOrName. Alternatively, update resolveSimulatorIdOrName to perform a case-insensitive match to better align with user expectations and xcodebuild's functionality.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/mcp/tools/simulator/test_sim.ts#L113-L122
Potential issue: The new pre-flight simulator resolution in `test_sim.ts` uses
`resolveSimulatorIdOrName`, which performs a strict, case-sensitive name match against
available simulators. This is a regression from the previous behavior where the name was
passed directly to `xcodebuild`, which has more flexible resolution logic (e.g.,
case-insensitivity). This change can cause tests to fail for users who relied on
`xcodebuild`'s more permissive matching, as their simulator names may no longer resolve
correctly if they don't match the `simctl` output exactly.
There was a problem hiding this comment.
Not a regression. The pre-existing determineSimulatorUuid in simulator-utils.ts:94 uses identical strict equality (d.name === params.simulatorName). Both old and new code paths match the same way. xcodebuild itself expects exact simulator names as returned by simctl list devices, so case-insensitive matching would be non-standard.
e6e44bb to
8208efa
Compare
6ad5269 to
c6bb094
Compare
8208efa to
3d0b705
Compare
c6bb094 to
ea1dcfb
Compare
3d0b705 to
a798b24
Compare
ea1dcfb to
c4d9441
Compare
a798b24 to
84180f1
Compare
c4d9441 to
cfb41d8
Compare
1a1c722 to
9396aff
Compare
5e38f0a to
c802970
Compare
9396aff to
fef58c3
Compare
c802970 to
f5b95e6
Compare
fef58c3 to
03324df
Compare
f5b95e6 to
3a2b3da
Compare
589573e to
886a46f
Compare
3a2b3da to
9f921b2
Compare
886a46f to
a42228b
Compare
25b8d8d to
8d84711
Compare
a42228b to
696acb9
Compare
696acb9 to
0384076
Compare
…ased handler contract
The simulatorId parameter was not being passed to inferPlatform, causing platform detection to fall back to scheme-based inference even when a specific simulator UUID was provided. This broke non-iOS simulator detection (e.g. watchOS, tvOS) when specified by UUID.
Replace 12 identical local runLogic definitions with the shared import from test-helpers.ts.
8d84711 to
a7d936d
Compare



Summary
This is PR 6 of 12 in a stacked PR series that decouples the rendering pipeline from MCP transport. Depends on PR 5 (handler contract change).
Migrates all simulator and simulator-management tool handlers from the old
return toolResponse([...])pattern to the newctx.emit(event)pattern introduced in PR 5. This is the largest tool migration PR because simulators are the primary development target.Tools migrated (36 files)
Simulator tools:
boot_sim,build_sim,build_run_sim,get_sim_app_path,install_app_sim,launch_app_sim,list_sims,open_sim,record_sim_video,stop_app_sim,test_sim,screenshotSimulator management tools:
erase_sims,reset_sim_location,set_sim_appearance,set_sim_location,sim_statusbarPattern of change
Each handler follows the same mechanical transformation:
```typescript
// Before
async function handler(params) {
const result = await buildForSimulator(params);
return toolResponse([header('Build', [...]), statusLine('success', '...')]);
}
// After
async function handler(params, ctx) {
const result = await buildForSimulator(params, ctx);
ctx.emit(header('Build', [...]));
ctx.emit(statusLine('success', '...'));
}
```
Build/test tools additionally pass
ctx.emitto the xcodebuild pipeline so events stream in real-time during compilation.test_simdelegates tosimulator-test-execution.tsandtest-preflight.tsfrom PR 4.Supporting changes
simulator-utils.ts: Updated to work with the new handler contextsimulator-resolver.ts: Simplified resolver that integrates with the step modules from PR 4Stack navigation
Test plan
npx vitest runpasses -- all simulator tool tests updated