Skip to content

refactor(6/12): migrate simulator tools to event-based handlers#324

Open
cameroncooke wants to merge 1 commit intorefactor/runtime-handler-contractfrom
refactor/migrate-simulator-tools
Open

refactor(6/12): migrate simulator tools to event-based handlers#324
cameroncooke wants to merge 1 commit intorefactor/runtime-handler-contractfrom
refactor/migrate-simulator-tools

Conversation

@cameroncooke
Copy link
Copy Markdown
Collaborator

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 new ctx.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, screenshot

Simulator management tools: erase_sims, reset_sim_location, set_sim_appearance, set_sim_location, sim_statusbar

Pattern 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.emit to the xcodebuild pipeline so events stream in real-time during compilation. test_sim delegates to simulator-test-execution.ts and test-preflight.ts from PR 4.

Supporting changes

  • simulator-utils.ts: Updated to work with the new handler context
  • simulator-resolver.ts: Simplified resolver that integrates with the step modules from PR 4

Stack navigation

  • PR 1-5/12: Foundation, utilities, runtime contract
  • PR 6/12 (this PR): Simulator tool migrations
  • PR 7/12: Device + macOS tool migrations
  • PR 8/12: UI automation tool migrations
  • PR 9/12: Remaining tool migrations
  • PR 10-12/12: Boundaries, config, tests

Test plan

  • npx vitest run passes -- all simulator tool tests updated
  • Each tool handler emits the expected event sequence
  • Build/test tools stream progress events during xcodebuild execution

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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.

Create PR

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.

Comment on lines -127 to -134
sharedBuildParams,
{
platform: detectedPlatform,
simulatorId: params.simulatorId,
simulatorName: params.simulatorName,
useLatestOS: params.simulatorId ? false : params.useLatestOS,
logPrefix,
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The inferPlatform function is no longer passed the simulatorId, which will cause platform detection to fail for non-iOS simulators specified by UUID.
Severity: HIGH

Suggested Fix

Pass the simulatorId to the inferPlatform function call to ensure it can correctly infer the platform for simulators identified by their UUID.

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/build_run_sim.ts#L127-L134

Potential issue: The `inferPlatform` function is now called without the `simulatorId`.
When a simulator is identified by its UUID, this change prevents the correct platform
(like watchOS, tvOS, or visionOS) from being detected. As a result, the system will
default to iOS, leading to build or run failures because the wrong destination platform
is used.

Did we get this right? 👍 / 👎 to inform future reviews.

@cameroncooke cameroncooke force-pushed the refactor/runtime-handler-contract branch from 089f6a3 to fa1ece2 Compare April 8, 2026 21:29
@cameroncooke cameroncooke force-pushed the refactor/migrate-simulator-tools branch from daf00b3 to d9e9216 Compare April 8, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant