Commit 6e51e5b
authored
refactor(6/12): migrate simulator tools to event-based handlers (#324)
## 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 execution1 parent bc56fa7 commit 6e51e5b
37 files changed
Lines changed: 2537 additions & 3081 deletions
File tree
- src
- mcp/tools
- simulator-management
- __tests__
- simulator
- __tests__
- utils
- __tests__
- axe
Lines changed: 17 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 17 | + | |
| 18 | + | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 23 | + | |
| 24 | + | |
30 | 25 | | |
31 | 26 | | |
32 | 27 | | |
33 | 28 | | |
34 | 29 | | |
35 | 30 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
39 | 35 | | |
40 | 36 | | |
41 | 37 | | |
| |||
44 | 40 | | |
45 | 41 | | |
46 | 42 | | |
47 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 50 | + | |
55 | 51 | | |
56 | 52 | | |
57 | 53 | | |
Lines changed: 33 additions & 45 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 28 | + | |
| 29 | + | |
35 | 30 | | |
36 | | - | |
37 | | - | |
| 31 | + | |
38 | 32 | | |
39 | | - | |
40 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
41 | 38 | | |
42 | 39 | | |
43 | 40 | | |
| |||
46 | 43 | | |
47 | 44 | | |
48 | 45 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 46 | + | |
| 47 | + | |
58 | 48 | | |
59 | | - | |
60 | | - | |
| 49 | + | |
61 | 50 | | |
62 | | - | |
63 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
64 | 56 | | |
65 | 57 | | |
66 | 58 | | |
67 | 59 | | |
68 | 60 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 61 | + | |
| 62 | + | |
78 | 63 | | |
79 | | - | |
80 | | - | |
| 64 | + | |
81 | 65 | | |
82 | | - | |
83 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
84 | 71 | | |
85 | 72 | | |
86 | 73 | | |
| |||
92 | 79 | | |
93 | 80 | | |
94 | 81 | | |
95 | | - | |
96 | 82 | | |
97 | 83 | | |
98 | 84 | | |
99 | 85 | | |
100 | 86 | | |
101 | 87 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
107 | 95 | | |
108 | 96 | | |
109 | 97 | | |
| |||
Lines changed: 39 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
| |||
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 39 | + | |
| 40 | + | |
46 | 41 | | |
47 | | - | |
48 | | - | |
| 42 | + | |
| 43 | + | |
49 | 44 | | |
50 | | - | |
51 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
52 | 50 | | |
53 | 51 | | |
54 | 52 | | |
| |||
57 | 55 | | |
58 | 56 | | |
59 | 57 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 58 | + | |
| 59 | + | |
70 | 60 | | |
71 | | - | |
72 | | - | |
| 61 | + | |
| 62 | + | |
73 | 63 | | |
74 | | - | |
75 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
76 | 69 | | |
77 | 70 | | |
78 | 71 | | |
79 | 72 | | |
80 | 73 | | |
81 | 74 | | |
82 | | - | |
| 75 | + | |
83 | 76 | | |
84 | 77 | | |
85 | 78 | | |
86 | 79 | | |
87 | 80 | | |
88 | 81 | | |
89 | 82 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 83 | + | |
| 84 | + | |
100 | 85 | | |
101 | | - | |
102 | | - | |
| 86 | + | |
| 87 | + | |
103 | 88 | | |
104 | | - | |
105 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
106 | 94 | | |
107 | 95 | | |
108 | 96 | | |
| |||
118 | 106 | | |
119 | 107 | | |
120 | 108 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
127 | 117 | | |
128 | 118 | | |
129 | 119 | | |
130 | 120 | | |
131 | 121 | | |
132 | 122 | | |
133 | 123 | | |
134 | | - | |
135 | 124 | | |
136 | 125 | | |
137 | 126 | | |
| |||
0 commit comments