Skip to content

Commit 8ca5b79

Browse files
committed
fix: align simulator app path platform typing
1 parent 45f242e commit 8ca5b79

2 files changed

Lines changed: 31 additions & 22 deletions

File tree

src/mcp/tools/simulator/__tests__/get_sim_app_path.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createMockExecutor } from '../../../../test-utils/mock-executors.ts';
1010
import { sessionStore } from '../../../../utils/session-store.ts';
1111
import { schema, handler, get_sim_app_pathLogic } from '../get_sim_app_path.ts';
1212
import type { CommandExecutor } from '../../../../utils/CommandExecutor.ts';
13+
import { XcodePlatform } from '../../../../types/common.ts';
1314

1415
describe('get_sim_app_path tool', () => {
1516
beforeEach(() => {
@@ -24,7 +25,7 @@ describe('get_sim_app_path tool', () => {
2425
it('should expose only platform in public schema', () => {
2526
const schemaObj = z.object(schema);
2627

27-
expect(schemaObj.safeParse({ platform: 'iOS Simulator' }).success).toBe(true);
28+
expect(schemaObj.safeParse({ platform: XcodePlatform.iOSSimulator }).success).toBe(true);
2829
expect(schemaObj.safeParse({}).success).toBe(false);
2930
expect(schemaObj.safeParse({ platform: 'iOS' }).success).toBe(false);
3031

@@ -36,7 +37,7 @@ describe('get_sim_app_path tool', () => {
3637
describe('Handler Requirements', () => {
3738
it('should require scheme when not provided', async () => {
3839
const result = await handler({
39-
platform: 'iOS Simulator',
40+
platform: XcodePlatform.iOSSimulator,
4041
});
4142

4243
expect(result.isError).toBe(true);
@@ -47,7 +48,7 @@ describe('get_sim_app_path tool', () => {
4748
sessionStore.setDefaults({ scheme: 'MyScheme' });
4849

4950
const result = await handler({
50-
platform: 'iOS Simulator',
51+
platform: XcodePlatform.iOSSimulator,
5152
});
5253

5354
expect(result.isError).toBe(true);
@@ -61,7 +62,7 @@ describe('get_sim_app_path tool', () => {
6162
});
6263

6364
const result = await handler({
64-
platform: 'iOS Simulator',
65+
platform: XcodePlatform.iOSSimulator,
6566
});
6667

6768
expect(result.isError).toBe(true);
@@ -72,7 +73,7 @@ describe('get_sim_app_path tool', () => {
7273
sessionStore.setDefaults({ scheme: 'MyScheme' });
7374

7475
const result = await handler({
75-
platform: 'iOS Simulator',
76+
platform: XcodePlatform.iOSSimulator,
7677
projectPath: '/path/project.xcodeproj',
7778
workspacePath: '/path/workspace.xcworkspace',
7879
});
@@ -90,7 +91,7 @@ describe('get_sim_app_path tool', () => {
9091
});
9192

9293
const result = await handler({
93-
platform: 'iOS Simulator',
94+
platform: XcodePlatform.iOSSimulator,
9495
simulatorId: 'SIM-UUID',
9596
simulatorName: 'iPhone 16',
9697
});
@@ -134,7 +135,7 @@ describe('get_sim_app_path tool', () => {
134135
{
135136
workspacePath: '/path/to/workspace.xcworkspace',
136137
scheme: 'MyScheme',
137-
platform: 'iOS Simulator',
138+
platform: XcodePlatform.iOSSimulator,
138139
simulatorName: 'iPhone 16',
139140
useLatestOS: true,
140141
},
@@ -173,7 +174,7 @@ describe('get_sim_app_path tool', () => {
173174
{
174175
projectPath: '/path/to/project.xcodeproj',
175176
scheme: 'MyScheme',
176-
platform: 'iOS Simulator',
177+
platform: XcodePlatform.iOSSimulator,
177178
simulatorId: 'SIM-UUID',
178179
},
179180
mockExecutor,

src/mcp/tools/simulator/get_sim_app_path.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@ import {
1919
} from '../../../utils/typed-tool-factory.ts';
2020
import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts';
2121

22+
const SIMULATOR_PLATFORMS = [
23+
XcodePlatform.iOSSimulator,
24+
XcodePlatform.watchOSSimulator,
25+
XcodePlatform.tvOSSimulator,
26+
XcodePlatform.visionOSSimulator,
27+
] as const;
28+
2229
function constructDestinationString(
23-
platform: string,
30+
platform: XcodePlatform,
2431
simulatorName: string,
2532
simulatorId: string,
2633
useLatest: boolean = true,
2734
arch?: string,
2835
): string {
29-
const isSimulatorPlatform = [
30-
XcodePlatform.iOSSimulator,
31-
XcodePlatform.watchOSSimulator,
32-
XcodePlatform.tvOSSimulator,
33-
XcodePlatform.visionOSSimulator,
34-
].includes(platform);
36+
const isSimulatorPlatform = SIMULATOR_PLATFORMS.includes(
37+
platform as (typeof SIMULATOR_PLATFORMS)[number],
38+
);
3539

3640
// If ID is provided for a simulator, it takes precedence and uniquely identifies it.
3741
if (isSimulatorPlatform && simulatorId) {
@@ -76,7 +80,14 @@ const baseGetSimulatorAppPathSchema = z.object({
7680
.optional()
7781
.describe('Path to .xcworkspace file. Provide EITHER this OR projectPath, not both'),
7882
scheme: z.string().describe('The scheme to use (Required)'),
79-
platform: z.enum(['iOS Simulator', 'watchOS Simulator', 'tvOS Simulator', 'visionOS Simulator']),
83+
platform: z
84+
.nativeEnum(XcodePlatform)
85+
.refine(
86+
(platform) => SIMULATOR_PLATFORMS.includes(platform as (typeof SIMULATOR_PLATFORMS)[number]),
87+
{
88+
message: 'platform must be a simulator platform',
89+
},
90+
),
8091
simulatorId: z
8192
.string()
8293
.optional()
@@ -162,12 +173,9 @@ export async function get_sim_app_pathLogic(
162173
command.push('-configuration', configuration);
163174

164175
// Handle destination based on platform
165-
const isSimulatorPlatform = [
166-
XcodePlatform.iOSSimulator,
167-
XcodePlatform.watchOSSimulator,
168-
XcodePlatform.tvOSSimulator,
169-
XcodePlatform.visionOSSimulator,
170-
].includes(platform);
176+
const isSimulatorPlatform = SIMULATOR_PLATFORMS.includes(
177+
platform as (typeof SIMULATOR_PLATFORMS)[number],
178+
);
171179

172180
let destinationString = '';
173181

0 commit comments

Comments
 (0)