Repository navigation
Expand file tree
/
Copy pathe2e-mcp-sessions.test.ts
More file actions
314 lines (277 loc) · 9.82 KB
/
Copy pathe2e-mcp-sessions.test.ts
File metadata and controls
314 lines (277 loc) · 9.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
import { createMcpTestHarness, type McpTestHarness } from '../mcp-test-harness.ts';
import { extractText, expectContent } from '../test-helpers.ts';
let harness: McpTestHarness;
beforeAll(async () => {
harness = await createMcpTestHarness({
commandResponses: {
xcodebuild: { success: true, output: 'Build Succeeded' },
'simctl list devices': {
success: true,
output: JSON.stringify({
devices: {
'com.apple.CoreSimulator.SimRuntime.iOS-18-0': [
{
name: 'iPhone 17 Pro',
udid: 'AAAAAAAA-1111-2222-3333-444444444444',
state: 'Shutdown',
isAvailable: true,
},
],
},
}),
},
},
});
}, 30_000);
afterAll(async () => {
await harness.cleanup();
});
beforeEach(async () => {
// Clear defaults before each test
await harness.client.callTool({
name: 'session_clear_defaults',
arguments: { all: true },
});
});
describe('MCP Session Management (e2e)', () => {
it('session_set_defaults stores scheme', async () => {
const result = await harness.client.callTool({
name: 'session_set_defaults',
arguments: { scheme: 'MyApp' },
});
expect(result).toBeDefined();
const text = extractText(result);
expect(text).toContain('scheme');
});
it('session_show_defaults returns the set defaults', async () => {
// Set some defaults
await harness.client.callTool({
name: 'session_set_defaults',
arguments: { scheme: 'TestApp', projectPath: '/path/to/project' },
});
// Show defaults
const result = await harness.client.callTool({
name: 'session_show_defaults',
arguments: {},
});
const text = extractText(result);
expect(text).toContain('TestApp');
expect(text).toContain('/path/to/project');
});
it('session_clear_defaults clears all defaults', async () => {
// Set defaults
await harness.client.callTool({
name: 'session_set_defaults',
arguments: { scheme: 'ClearMeScheme', projectPath: '/clear-me-proj' },
});
// Clear all
await harness.client.callTool({
name: 'session_clear_defaults',
arguments: { all: true },
});
// Show should be empty
const result = await harness.client.callTool({
name: 'session_show_defaults',
arguments: {},
});
const text = extractText(result);
// Should not contain the previously set values
expect(text).not.toContain('ClearMeScheme');
expect(text).not.toContain('/clear-me-proj');
});
it('session_clear_defaults clears specific keys', async () => {
// Set multiple defaults
await harness.client.callTool({
name: 'session_set_defaults',
arguments: { scheme: 'KeepThis', projectPath: '/clear/this' },
});
// Clear only projectPath
await harness.client.callTool({
name: 'session_clear_defaults',
arguments: { keys: ['projectPath'] },
});
// Show defaults
const result = await harness.client.callTool({
name: 'session_show_defaults',
arguments: {},
});
const text = extractText(result);
expect(text).toContain('KeepThis');
expect(text).not.toContain('/clear/this');
});
it('session defaults flow into tool invocations', async () => {
// Set session defaults
await harness.client.callTool({
name: 'session_set_defaults',
arguments: {
scheme: 'SessionScheme',
projectPath: '/session/project.xcodeproj',
simulatorId: 'AAAAAAAA-1111-2222-3333-444444444444',
},
});
// Invoke build_sim without explicit scheme/project (should use session defaults)
harness.resetCapturedCommands();
const result = await harness.client.callTool({
name: 'build_sim',
arguments: {},
});
expectContent(result);
// The captured commands should include the session default scheme
const commandStrs = harness.capturedCommands.map((c) => c.command.join(' '));
const buildCommand = commandStrs.find((c) => c.includes('xcodebuild') && c.includes('-scheme'));
expect(buildCommand).toBeDefined();
expect(buildCommand).toContain('SessionScheme');
});
it('explicit simulator build arguments override session defaults', async () => {
await harness.client.callTool({
name: 'session_set_defaults',
arguments: {
scheme: 'DefaultScheme',
projectPath: '/default/project.xcodeproj',
simulatorId: 'AAAAAAAA-1111-2222-3333-444444444444',
configuration: 'Debug',
},
});
harness.resetCapturedCommands();
const result = await harness.client.callTool({
name: 'build_sim',
arguments: {
scheme: 'ExplicitScheme',
projectPath: '/explicit/project.xcodeproj',
simulatorName: 'iPhone 17 Pro',
configuration: 'Release',
},
});
expectContent(result);
const commandStrs = harness.capturedCommands.map((command) => command.command.join(' '));
const buildCommand = commandStrs.find(
(command) => command.includes('xcodebuild') && command.includes('-scheme'),
);
expect(buildCommand).toBeDefined();
expect(buildCommand).toContain('ExplicitScheme');
expect(buildCommand).toContain('/explicit/project.xcodeproj');
expect(buildCommand).toContain('iPhone 17 Pro');
expect(buildCommand).toContain('Release');
expect(buildCommand).not.toContain('DefaultScheme');
expect(buildCommand).not.toContain('/default/project.xcodeproj');
});
it('accepts typed simulator test selectors', async () => {
await harness.client.callTool({
name: 'session_set_defaults',
arguments: {
scheme: 'SessionScheme',
projectPath: '/session/project.xcodeproj',
simulatorId: 'AAAAAAAA-1111-2222-3333-444444444444',
},
});
harness.resetCapturedCommands();
const result = await harness.client.callTool({
name: 'test_sim',
arguments: {
onlyTesting: ['MyTests/LoginTests/testSuccess'],
skipTesting: ['MyTests/LoginTests/testFailure'],
},
});
expectContent(result);
const commandStrs = harness.capturedCommands.map((command) => command.command.join(' '));
const testCommand = commandStrs.find(
(command) => command.includes('xcodebuild') && command.includes(' test'),
);
expect(testCommand).toBeDefined();
expect(testCommand).toContain('-only-testing:MyTests/LoginTests/testSuccess');
expect(testCommand).toContain('-skip-testing:MyTests/LoginTests/testFailure');
});
it('updating session defaults changes subsequent tool behavior', async () => {
// Set initial defaults
await harness.client.callTool({
name: 'session_set_defaults',
arguments: {
scheme: 'FirstScheme',
projectPath: '/first/project.xcodeproj',
simulatorId: 'AAAAAAAA-1111-2222-3333-444444444444',
},
});
// Update scheme via session_set_defaults
await harness.client.callTool({
name: 'session_set_defaults',
arguments: {
scheme: 'UpdatedScheme',
},
});
// Invoke build_sim - should use the updated scheme
harness.resetCapturedCommands();
const result = await harness.client.callTool({
name: 'build_sim',
arguments: {},
});
expect(result).toBeDefined();
const commandStrs = harness.capturedCommands.map((c) => c.command.join(' '));
const buildCommand = commandStrs.find((c) => c.includes('xcodebuild') && c.includes('-scheme'));
expect(buildCommand).toBeDefined();
expect(buildCommand).toContain('UpdatedScheme');
});
it('supports namespaced defaults by switching active profile', async () => {
await harness.client.callTool({
name: 'session_set_defaults',
arguments: {
profile: 'ios',
createIfNotExists: true,
scheme: 'IOSScheme',
projectPath: '/ios/project.xcodeproj',
},
});
await harness.client.callTool({
name: 'session_set_defaults',
arguments: {
profile: 'watch',
createIfNotExists: true,
scheme: 'WatchScheme',
projectPath: '/watch/project.xcodeproj',
},
});
const watchResult = (await harness.client.callTool({
name: 'session_use_defaults_profile',
arguments: { profile: 'watch' },
})) as {
structuredContent?: { data?: { currentProfile?: string } };
};
expect(watchResult.structuredContent?.data?.currentProfile).toBe('watch');
const watchDefaults = (await harness.client.callTool({
name: 'session_show_defaults',
arguments: {},
})) as {
structuredContent?: {
data?: {
currentProfile?: string;
profiles?: Record<string, { scheme?: string | null; projectPath?: string | null }>;
};
};
};
expect(watchDefaults.structuredContent?.data?.currentProfile).toBe('watch');
expect(watchDefaults.structuredContent?.data?.profiles?.watch?.scheme).toBe('WatchScheme');
expect(watchDefaults.structuredContent?.data?.profiles?.ios?.scheme).toBe('IOSScheme');
const iosResult = (await harness.client.callTool({
name: 'session_use_defaults_profile',
arguments: { profile: 'ios' },
})) as {
structuredContent?: { data?: { currentProfile?: string } };
};
expect(iosResult.structuredContent?.data?.currentProfile).toBe('ios');
const iosDefaults = (await harness.client.callTool({
name: 'session_show_defaults',
arguments: {},
})) as {
structuredContent?: {
data?: {
currentProfile?: string;
profiles?: Record<string, { scheme?: string | null; projectPath?: string | null }>;
};
};
};
expect(iosDefaults.structuredContent?.data?.currentProfile).toBe('ios');
expect(iosDefaults.structuredContent?.data?.profiles?.ios?.projectPath).toBe(
'/ios/project.xcodeproj',
);
});
});