-
-
Notifications
You must be signed in to change notification settings - Fork 219
fix(runtime): Preserve daemon next-step params in CLI hints #259
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
Open
cameroncooke
wants to merge
3
commits into
main
Choose a base branch
from
XcodeBuildMCP-build-run-device
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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,18 @@ | ||
| id: build_run_device | ||
| module: mcp/tools/device/build_run_device | ||
| names: | ||
| mcp: build_run_device | ||
| cli: build-and-run | ||
| description: Build, install, and launch on physical device. Preferred single-step run tool when defaults are set. | ||
| predicates: | ||
| - hideWhenXcodeAgentMode | ||
| annotations: | ||
| title: Build Run Device | ||
| destructiveHint: false | ||
| nextSteps: | ||
| - label: Capture device logs | ||
| toolId: start_device_log_cap | ||
| priority: 1 | ||
| - label: Stop app on device | ||
| toolId: stop_app_device | ||
| priority: 2 |
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
254 changes: 254 additions & 0 deletions
254
src/mcp/tools/device/__tests__/build_run_device.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,254 @@ | ||
| import { describe, it, expect, beforeEach } from 'vitest'; | ||
| import * as z from 'zod'; | ||
| import { | ||
| createMockCommandResponse, | ||
| createMockFileSystemExecutor, | ||
| } from '../../../../test-utils/mock-executors.ts'; | ||
| import type { CommandExecutor } from '../../../../utils/execution/index.ts'; | ||
| import { sessionStore } from '../../../../utils/session-store.ts'; | ||
| import { schema, handler, build_run_deviceLogic } from '../build_run_device.ts'; | ||
|
|
||
| describe('build_run_device tool', () => { | ||
| beforeEach(() => { | ||
| sessionStore.clear(); | ||
| }); | ||
|
|
||
| it('exposes only non-session fields in public schema', () => { | ||
| const schemaObj = z.strictObject(schema); | ||
|
|
||
| expect(schemaObj.safeParse({}).success).toBe(true); | ||
| expect(schemaObj.safeParse({ extraArgs: ['-quiet'] }).success).toBe(true); | ||
| expect(schemaObj.safeParse({ env: { FOO: 'bar' } }).success).toBe(true); | ||
|
|
||
| expect(schemaObj.safeParse({ scheme: 'App' }).success).toBe(false); | ||
| expect(schemaObj.safeParse({ deviceId: 'device-id' }).success).toBe(false); | ||
|
|
||
| const schemaKeys = Object.keys(schema).sort(); | ||
| expect(schemaKeys).toEqual(['env', 'extraArgs']); | ||
| }); | ||
|
|
||
| it('requires scheme + deviceId and project/workspace via handler', async () => { | ||
| const missingAll = await handler({}); | ||
| expect(missingAll.isError).toBe(true); | ||
| expect(missingAll.content[0].text).toContain('Provide scheme and deviceId'); | ||
|
|
||
| const missingSource = await handler({ scheme: 'MyApp', deviceId: 'DEVICE-UDID' }); | ||
| expect(missingSource.isError).toBe(true); | ||
| expect(missingSource.content[0].text).toContain('Provide a project or workspace'); | ||
| }); | ||
|
|
||
| it('builds, installs, and launches successfully', async () => { | ||
| const commands: string[] = []; | ||
| const mockExecutor: CommandExecutor = async (command) => { | ||
| commands.push(command.join(' ')); | ||
|
|
||
| if (command.includes('-showBuildSettings')) { | ||
| return createMockCommandResponse({ | ||
| success: true, | ||
| output: 'BUILT_PRODUCTS_DIR = /tmp/build\nFULL_PRODUCT_NAME = MyApp.app\n', | ||
| }); | ||
| } | ||
|
|
||
| if (command[0] === '/bin/sh') { | ||
| return createMockCommandResponse({ success: true, output: 'io.sentry.MyApp' }); | ||
| } | ||
|
|
||
| return createMockCommandResponse({ success: true, output: 'OK' }); | ||
| }; | ||
|
|
||
| const result = await build_run_deviceLogic( | ||
| { | ||
| projectPath: '/tmp/MyApp.xcodeproj', | ||
| scheme: 'MyApp', | ||
| deviceId: 'DEVICE-UDID', | ||
| }, | ||
| mockExecutor, | ||
| createMockFileSystemExecutor({ | ||
| existsSync: () => true, | ||
| readFile: async () => JSON.stringify({ result: { process: { processIdentifier: 1234 } } }), | ||
| }), | ||
| ); | ||
|
|
||
| expect(result.isError).toBe(false); | ||
| expect(result.content[0].text).toContain('device build and run succeeded'); | ||
| expect(result.nextStepParams).toMatchObject({ | ||
| start_device_log_cap: { deviceId: 'DEVICE-UDID', bundleId: 'io.sentry.MyApp' }, | ||
| stop_app_device: { deviceId: 'DEVICE-UDID', processId: 1234 }, | ||
| }); | ||
|
|
||
| expect(commands.some((c) => c.includes('xcodebuild') && c.includes('build'))).toBe(true); | ||
| expect(commands.some((c) => c.includes('xcodebuild') && c.includes('-showBuildSettings'))).toBe( | ||
| true, | ||
| ); | ||
| expect(commands.some((c) => c.includes('devicectl') && c.includes('install'))).toBe(true); | ||
| expect(commands.some((c) => c.includes('devicectl') && c.includes('launch'))).toBe(true); | ||
| }); | ||
|
|
||
| it('uses generic destination for build-settings lookup', async () => { | ||
| const commandCalls: string[][] = []; | ||
| const mockExecutor: CommandExecutor = async (command) => { | ||
| commandCalls.push(command); | ||
|
|
||
| if (command.includes('-showBuildSettings')) { | ||
| return createMockCommandResponse({ | ||
| success: true, | ||
| output: 'BUILT_PRODUCTS_DIR = /tmp/build\nFULL_PRODUCT_NAME = MyWatchApp.app\n', | ||
| }); | ||
| } | ||
|
|
||
| if (command[0] === '/bin/sh') { | ||
| return createMockCommandResponse({ success: true, output: 'io.sentry.MyWatchApp' }); | ||
| } | ||
|
|
||
| if (command.includes('launch')) { | ||
| return createMockCommandResponse({ | ||
| success: true, | ||
| output: JSON.stringify({ result: { process: { processIdentifier: 9876 } } }), | ||
| }); | ||
| } | ||
|
|
||
| return createMockCommandResponse({ success: true, output: 'OK' }); | ||
| }; | ||
|
|
||
| const result = await build_run_deviceLogic( | ||
| { | ||
| projectPath: '/tmp/MyWatchApp.xcodeproj', | ||
| scheme: 'MyWatchApp', | ||
| platform: 'watchOS', | ||
| deviceId: 'DEVICE-UDID', | ||
| }, | ||
| mockExecutor, | ||
| createMockFileSystemExecutor({ existsSync: () => true }), | ||
| ); | ||
|
|
||
| expect(result.isError).toBe(false); | ||
|
|
||
| const showBuildSettingsCommand = commandCalls.find((command) => | ||
| command.includes('-showBuildSettings'), | ||
| ); | ||
| expect(showBuildSettingsCommand).toBeDefined(); | ||
| expect(showBuildSettingsCommand).toContain('-destination'); | ||
|
|
||
| const destinationIndex = showBuildSettingsCommand!.indexOf('-destination'); | ||
| expect(showBuildSettingsCommand![destinationIndex + 1]).toBe('generic/platform=watchOS'); | ||
| }); | ||
|
|
||
| it('includes fallback stop guidance when process id is unavailable', async () => { | ||
| const mockExecutor: CommandExecutor = async (command) => { | ||
| if (command.includes('-showBuildSettings')) { | ||
| return createMockCommandResponse({ | ||
| success: true, | ||
| output: 'BUILT_PRODUCTS_DIR = /tmp/build\nFULL_PRODUCT_NAME = MyApp.app\n', | ||
| }); | ||
| } | ||
|
|
||
| if (command[0] === '/bin/sh') { | ||
| return createMockCommandResponse({ success: true, output: 'io.sentry.MyApp' }); | ||
| } | ||
|
|
||
| return createMockCommandResponse({ success: true, output: 'OK' }); | ||
| }; | ||
|
|
||
| const result = await build_run_deviceLogic( | ||
| { | ||
| projectPath: '/tmp/MyApp.xcodeproj', | ||
| scheme: 'MyApp', | ||
| deviceId: 'DEVICE-UDID', | ||
| }, | ||
| mockExecutor, | ||
| createMockFileSystemExecutor({ | ||
| existsSync: () => true, | ||
| readFile: async () => 'not-json', | ||
| }), | ||
| ); | ||
|
|
||
| expect(result.isError).toBe(false); | ||
| expect(result.content[0].text).toContain('Process ID was unavailable'); | ||
| expect(result.nextStepParams).toMatchObject({ | ||
| start_device_log_cap: { deviceId: 'DEVICE-UDID', bundleId: 'io.sentry.MyApp' }, | ||
| }); | ||
| expect(result.nextStepParams?.stop_app_device).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns an error when app-path lookup fails after successful build', async () => { | ||
| const mockExecutor: CommandExecutor = async (command) => { | ||
| if (command.includes('-showBuildSettings')) { | ||
| return createMockCommandResponse({ success: false, error: 'no build settings' }); | ||
| } | ||
| return createMockCommandResponse({ success: true, output: 'OK' }); | ||
| }; | ||
|
|
||
| const result = await build_run_deviceLogic( | ||
| { | ||
| projectPath: '/tmp/MyApp.xcodeproj', | ||
| scheme: 'MyApp', | ||
| deviceId: 'DEVICE-UDID', | ||
| }, | ||
| mockExecutor, | ||
| createMockFileSystemExecutor({ existsSync: () => true }), | ||
| ); | ||
|
|
||
| expect(result.isError).toBe(true); | ||
| expect(result.content[0].text).toContain('failed to get app path'); | ||
| }); | ||
|
|
||
| it('returns an error when install fails', async () => { | ||
| const mockExecutor: CommandExecutor = async (command) => { | ||
| if (command.includes('-showBuildSettings')) { | ||
| return createMockCommandResponse({ | ||
| success: true, | ||
| output: 'BUILT_PRODUCTS_DIR = /tmp/build\nFULL_PRODUCT_NAME = MyApp.app\n', | ||
| }); | ||
| } | ||
|
|
||
| if (command.includes('install')) { | ||
| return createMockCommandResponse({ success: false, error: 'install failed' }); | ||
| } | ||
|
|
||
| return createMockCommandResponse({ success: true, output: 'io.sentry.MyApp' }); | ||
| }; | ||
|
|
||
| const result = await build_run_deviceLogic( | ||
| { | ||
| projectPath: '/tmp/MyApp.xcodeproj', | ||
| scheme: 'MyApp', | ||
| deviceId: 'DEVICE-UDID', | ||
| }, | ||
| mockExecutor, | ||
| createMockFileSystemExecutor({ existsSync: () => true }), | ||
| ); | ||
|
|
||
| expect(result.isError).toBe(true); | ||
| expect(result.content[0].text).toContain('error installing app on device'); | ||
| }); | ||
|
|
||
| it('returns an error when launch fails', async () => { | ||
| const mockExecutor: CommandExecutor = async (command) => { | ||
| if (command.includes('-showBuildSettings')) { | ||
| return createMockCommandResponse({ | ||
| success: true, | ||
| output: 'BUILT_PRODUCTS_DIR = /tmp/build\nFULL_PRODUCT_NAME = MyApp.app\n', | ||
| }); | ||
| } | ||
|
|
||
| if (command.includes('launch')) { | ||
| return createMockCommandResponse({ success: false, error: 'launch failed' }); | ||
| } | ||
|
|
||
| return createMockCommandResponse({ success: true, output: 'io.sentry.MyApp' }); | ||
| }; | ||
|
|
||
| const result = await build_run_deviceLogic( | ||
| { | ||
| projectPath: '/tmp/MyApp.xcodeproj', | ||
| scheme: 'MyApp', | ||
| deviceId: 'DEVICE-UDID', | ||
| }, | ||
| mockExecutor, | ||
| createMockFileSystemExecutor({ existsSync: () => true }), | ||
| ); | ||
|
|
||
| expect(result.isError).toBe(true); | ||
| expect(result.content[0].text).toContain('error launching app on device'); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.