-
-
Notifications
You must be signed in to change notification settings - Fork 260
feat(simulator-management): add consolidated erase_sims tool (UDID or all) #111
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e0d82e7
feat(simulator-management): add consolidated erase_sims tool
cameroncooke e93cf4c
docs: update TOOLS.md and README workflow counts; document erase_sims…
cameroncooke 4a5ebd3
feat(simulator-management): add shutdownFirst option and tool hints f…
cameroncooke dc695f5
docs(TOOLS): reflect erase_sims shutdownFirst option (no default)
cameroncooke 90dc951
refactor(simulator-management): adopt UDID terminology (simulatorUdid…
cameroncooke 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
64 changes: 64 additions & 0 deletions
64
src/mcp/tools/simulator-management/__tests__/erase_sims.test.ts
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,64 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { z } from 'zod'; | ||
| import eraseSims, { erase_simsLogic } from '../erase_sims.ts'; | ||
| import { createMockExecutor } from '../../../../test-utils/mock-executors.ts'; | ||
|
|
||
| describe('erase_sims tool (UDID or ALL only)', () => { | ||
| describe('Export Field Validation (Literal)', () => { | ||
| it('should have correct name', () => { | ||
| expect(eraseSims.name).toBe('erase_sims'); | ||
| }); | ||
|
|
||
| it('should have correct description', () => { | ||
| expect(eraseSims.description).toContain('Provide exactly one of: simulatorUuid or all=true'); | ||
| }); | ||
|
|
||
| it('should have handler function', () => { | ||
| expect(typeof eraseSims.handler).toBe('function'); | ||
| }); | ||
|
|
||
| it('should validate schema fields (shape only)', () => { | ||
| const schema = z.object(eraseSims.schema); | ||
| // Valid | ||
| expect(schema.safeParse({ simulatorUuid: 'UDID-1' }).success).toBe(true); | ||
| expect(schema.safeParse({ all: true }).success).toBe(true); | ||
| // Shape-level schema does not enforce selection rules; handler validation covers that. | ||
| }); | ||
| }); | ||
|
|
||
| describe('Single mode', () => { | ||
| it('erases a simulator successfully', async () => { | ||
| const mock = createMockExecutor({ success: true, output: 'OK' }); | ||
| const res = await erase_simsLogic({ simulatorUuid: 'UD1' }, mock); | ||
| expect(res).toEqual({ | ||
| content: [{ type: 'text', text: 'Successfully erased simulator UD1' }], | ||
| }); | ||
| }); | ||
|
|
||
| it('returns failure when erase fails', async () => { | ||
| const mock = createMockExecutor({ success: false, error: 'Booted device' }); | ||
| const res = await erase_simsLogic({ simulatorUuid: 'UD1' }, mock); | ||
| expect(res).toEqual({ | ||
| content: [{ type: 'text', text: 'Failed to erase simulator: Booted device' }], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('All mode', () => { | ||
| it('erases all simulators successfully', async () => { | ||
| const exec = createMockExecutor({ success: true, output: 'OK' }); | ||
| const res = await erase_simsLogic({ all: true }, exec); | ||
| expect(res).toEqual({ | ||
| content: [{ type: 'text', text: 'Successfully erased all simulators' }], | ||
| }); | ||
| }); | ||
|
|
||
| it('returns failure when erase all fails', async () => { | ||
| const exec = createMockExecutor({ success: false, error: 'Denied' }); | ||
| const res = await erase_simsLogic({ all: true }, exec); | ||
| expect(res).toEqual({ | ||
| content: [{ type: 'text', text: 'Failed to erase all simulators: Denied' }], | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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,86 @@ | ||
| import { z } from 'zod'; | ||
| import { ToolResponse } from '../../../types/common.ts'; | ||
| import { log } from '../../../utils/logging/index.ts'; | ||
| import { CommandExecutor, getDefaultCommandExecutor } from '../../../utils/execution/index.ts'; | ||
| import { createTypedTool } from '../../../utils/typed-tool-factory.ts'; | ||
|
|
||
| const eraseSimsBaseSchema = z.object({ | ||
| simulatorUuid: z.string().optional().describe('UUID of the simulator to erase.'), | ||
| all: z.boolean().optional().describe('When true, erases all simulators.'), | ||
| }); | ||
|
|
||
| const eraseSimsSchema = eraseSimsBaseSchema.refine( | ||
| (v) => { | ||
| const selectors = (v.simulatorUuid ? 1 : 0) + (v.all === true ? 1 : 0); | ||
| return selectors === 1; | ||
| }, | ||
| { message: 'Provide exactly one of: simulatorUuid OR all=true.' }, | ||
| ); | ||
|
|
||
| type EraseSimsParams = z.infer<typeof eraseSimsSchema>; | ||
|
|
||
| async function eraseSingle(udid: string, executor: CommandExecutor): Promise<ToolResponse> { | ||
| const result = await executor( | ||
| ['xcrun', 'simctl', 'erase', udid], | ||
| 'Erase Simulator', | ||
| true, | ||
| undefined, | ||
| ); | ||
| if (result.success) { | ||
| return { content: [{ type: 'text', text: `Successfully erased simulator ${udid}` }] }; | ||
| } | ||
| return { | ||
| content: [ | ||
| { type: 'text', text: `Failed to erase simulator: ${result.error ?? 'Unknown error'}` }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| export async function erase_simsLogic( | ||
| params: EraseSimsParams, | ||
| executor: CommandExecutor, | ||
| ): Promise<ToolResponse> { | ||
| try { | ||
| if (params.simulatorUuid) { | ||
| log('info', `Erasing simulator ${params.simulatorUuid}`); | ||
| return await eraseSingle(params.simulatorUuid, executor); | ||
| } | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| if (params.all === true) { | ||
| log('info', 'Erasing ALL simulators'); | ||
| const result = await executor( | ||
| ['xcrun', 'simctl', 'erase', 'all'], | ||
| 'Erase All Simulators', | ||
| true, | ||
| undefined, | ||
| ); | ||
| if (!result.success) { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: `Failed to erase all simulators: ${result.error ?? 'Unknown error'}`, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| return { content: [{ type: 'text', text: 'Successfully erased all simulators' }] }; | ||
| } | ||
|
|
||
| return { | ||
| content: [{ type: 'text', text: 'Invalid parameters: provide simulatorUuid or all=true.' }], | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } catch (error: unknown) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| log('error', `Error erasing simulators: ${message}`); | ||
| return { content: [{ type: 'text', text: `Failed to erase simulators: ${message}` }] }; | ||
| } | ||
| } | ||
|
|
||
| export default { | ||
| name: 'erase_sims', | ||
| description: | ||
| 'Erases simulator content and settings. Provide exactly one of: simulatorUuid or all=true.', | ||
| schema: eraseSimsBaseSchema.shape, | ||
| handler: createTypedTool(eraseSimsSchema, erase_simsLogic, getDefaultCommandExecutor), | ||
| }; | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.