11import { describe , it , expect , beforeAll , afterAll } from 'vitest' ;
22import { createMcpTestHarness , type McpTestHarness } from '../mcp-test-harness.ts' ;
3+ import { isErrorResponse } from '../test-helpers.ts' ;
34
45let harness : McpTestHarness ;
56
@@ -34,7 +35,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
3435 } ,
3536 } ) ;
3637
37- harness . capturedCommands . length = 0 ;
38+ harness . resetCapturedCommands ( ) ;
3839 const result = await harness . client . callTool ( {
3940 name : 'build_device' ,
4041 arguments : { } ,
@@ -59,7 +60,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
5960 } ,
6061 } ) ;
6162
62- harness . capturedCommands . length = 0 ;
63+ harness . resetCapturedCommands ( ) ;
6364 const result = await harness . client . callTool ( {
6465 name : 'test_device' ,
6566 arguments : { } ,
@@ -83,7 +84,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
8384 } ,
8485 } ) ;
8586
86- harness . capturedCommands . length = 0 ;
87+ harness . resetCapturedCommands ( ) ;
8788 const result = await harness . client . callTool ( {
8889 name : 'launch_app_device' ,
8990 arguments : { } ,
@@ -106,7 +107,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
106107 } ,
107108 } ) ;
108109
109- harness . capturedCommands . length = 0 ;
110+ harness . resetCapturedCommands ( ) ;
110111 const result = await harness . client . callTool ( {
111112 name : 'stop_app_device' ,
112113 arguments : { processId : 12345 } ,
@@ -131,7 +132,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
131132 } ,
132133 } ) ;
133134
134- harness . capturedCommands . length = 0 ;
135+ harness . resetCapturedCommands ( ) ;
135136 const result = await harness . client . callTool ( {
136137 name : 'install_app_device' ,
137138 arguments : { appPath : '/path/to/MyApp.app' } ,
@@ -155,7 +156,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
155156 } ,
156157 } ) ;
157158
158- harness . capturedCommands . length = 0 ;
159+ harness . resetCapturedCommands ( ) ;
159160 const result = await harness . client . callTool ( {
160161 name : 'get_device_app_path' ,
161162 arguments : { } ,
@@ -173,7 +174,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
173174 } ) ;
174175
175176 it ( 'list_devices captures devicectl or xctrace command' , async ( ) => {
176- harness . capturedCommands . length = 0 ;
177+ harness . resetCapturedCommands ( ) ;
177178 const result = await harness . client . callTool ( {
178179 name : 'list_devices' ,
179180 arguments : { } ,
@@ -190,7 +191,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
190191
191192 describe ( 'project discovery tools' , ( ) => {
192193 it ( 'discover_projs responds with content' , async ( ) => {
193- harness . capturedCommands . length = 0 ;
194+ harness . resetCapturedCommands ( ) ;
194195 const result = await harness . client . callTool ( {
195196 name : 'discover_projs' ,
196197 arguments : { workspaceRoot : '/path/to/workspace' } ,
@@ -203,7 +204,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
203204 } ) ;
204205
205206 it ( 'get_app_bundle_id responds with content' , async ( ) => {
206- harness . capturedCommands . length = 0 ;
207+ harness . resetCapturedCommands ( ) ;
207208 const result = await harness . client . callTool ( {
208209 name : 'get_app_bundle_id' ,
209210 arguments : { appPath : '/path/to/MyApp.app' } ,
@@ -216,7 +217,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
216217 } ) ;
217218
218219 it ( 'get_mac_bundle_id responds with content' , async ( ) => {
219- harness . capturedCommands . length = 0 ;
220+ harness . resetCapturedCommands ( ) ;
220221 const result = await harness . client . callTool ( {
221222 name : 'get_mac_bundle_id' ,
222223 arguments : { appPath : '/path/to/MyApp.app' } ,
@@ -239,7 +240,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
239240 } ,
240241 } ) ;
241242
242- harness . capturedCommands . length = 0 ;
243+ harness . resetCapturedCommands ( ) ;
243244 const result = await harness . client . callTool ( {
244245 name : 'build_macos' ,
245246 arguments : { } ,
@@ -265,7 +266,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
265266 } ,
266267 } ) ;
267268
268- harness . capturedCommands . length = 0 ;
269+ harness . resetCapturedCommands ( ) ;
269270 const result = await harness . client . callTool ( {
270271 name : 'build_run_macos' ,
271272 arguments : { } ,
@@ -289,7 +290,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
289290 } ,
290291 } ) ;
291292
292- harness . capturedCommands . length = 0 ;
293+ harness . resetCapturedCommands ( ) ;
293294 const result = await harness . client . callTool ( {
294295 name : 'test_macos' ,
295296 arguments : { } ,
@@ -305,7 +306,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
305306 } ) ;
306307
307308 it ( 'launch_mac_app responds with content' , async ( ) => {
308- harness . capturedCommands . length = 0 ;
309+ harness . resetCapturedCommands ( ) ;
309310 const result = await harness . client . callTool ( {
310311 name : 'launch_mac_app' ,
311312 arguments : { appPath : '/path/to/MyMacApp.app' } ,
@@ -318,7 +319,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
318319 } ) ;
319320
320321 it ( 'stop_mac_app captures kill command with processId' , async ( ) => {
321- harness . capturedCommands . length = 0 ;
322+ harness . resetCapturedCommands ( ) ;
322323 const result = await harness . client . callTool ( {
323324 name : 'stop_mac_app' ,
324325 arguments : { processId : 54321 } ,
@@ -334,7 +335,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
334335 } ) ;
335336
336337 it ( 'stop_mac_app captures pkill command with appName' , async ( ) => {
337- harness . capturedCommands . length = 0 ;
338+ harness . resetCapturedCommands ( ) ;
338339 const result = await harness . client . callTool ( {
339340 name : 'stop_mac_app' ,
340341 arguments : { appName : 'MyMacApp' } ,
@@ -358,7 +359,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
358359 } ,
359360 } ) ;
360361
361- harness . capturedCommands . length = 0 ;
362+ harness . resetCapturedCommands ( ) ;
362363 const result = await harness . client . callTool ( {
363364 name : 'get_mac_app_path' ,
364365 arguments : { } ,
@@ -388,20 +389,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
388389 arguments : { } ,
389390 } ) ;
390391
391- const content = 'content' in result ? result . content : [ ] ;
392- const isError = 'isError' in result ? result . isError : false ;
393- const hasErrorText =
394- Array . isArray ( content ) &&
395- content . some (
396- ( c ) =>
397- 'text' in c &&
398- typeof c . text === 'string' &&
399- ( c . text . toLowerCase ( ) . includes ( 'error' ) ||
400- c . text . toLowerCase ( ) . includes ( 'required' ) ||
401- c . text . toLowerCase ( ) . includes ( 'must provide' ) ||
402- c . text . toLowerCase ( ) . includes ( 'provide' ) ) ,
403- ) ;
404- expect ( isError || hasErrorText ) . toBe ( true ) ;
392+ expect ( isErrorResponse ( result ) ) . toBe ( true ) ;
405393 } ) ;
406394
407395 it ( 'build_macos returns error when session defaults missing' , async ( ) => {
@@ -415,20 +403,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
415403 arguments : { } ,
416404 } ) ;
417405
418- const content = 'content' in result ? result . content : [ ] ;
419- const isError = 'isError' in result ? result . isError : false ;
420- const hasErrorText =
421- Array . isArray ( content ) &&
422- content . some (
423- ( c ) =>
424- 'text' in c &&
425- typeof c . text === 'string' &&
426- ( c . text . toLowerCase ( ) . includes ( 'error' ) ||
427- c . text . toLowerCase ( ) . includes ( 'required' ) ||
428- c . text . toLowerCase ( ) . includes ( 'must provide' ) ||
429- c . text . toLowerCase ( ) . includes ( 'provide' ) ) ,
430- ) ;
431- expect ( isError || hasErrorText ) . toBe ( true ) ;
406+ expect ( isErrorResponse ( result ) ) . toBe ( true ) ;
432407 } ) ;
433408
434409 it ( 'stop_mac_app returns error when no appName or processId provided' , async ( ) => {
@@ -437,19 +412,7 @@ describe('MCP Device and macOS Tool Invocation (e2e)', () => {
437412 arguments : { } ,
438413 } ) ;
439414
440- const content = 'content' in result ? result . content : [ ] ;
441- const isError = 'isError' in result ? result . isError : false ;
442- const hasErrorText =
443- Array . isArray ( content ) &&
444- content . some (
445- ( c ) =>
446- 'text' in c &&
447- typeof c . text === 'string' &&
448- ( c . text . toLowerCase ( ) . includes ( 'either' ) ||
449- c . text . toLowerCase ( ) . includes ( 'error' ) ||
450- c . text . toLowerCase ( ) . includes ( 'must be provided' ) ) ,
451- ) ;
452- expect ( isError || hasErrorText ) . toBe ( true ) ;
415+ expect ( isErrorResponse ( result ) ) . toBe ( true ) ;
453416 } ) ;
454417 } ) ;
455418} ) ;
0 commit comments