11import { describe , it , expect } from 'vitest' ;
2- import { schema , clone_simsLogic } from '../clone_sims.ts' ;
2+ import { schema , clone_simsLogic , createCloneSimsExecutor } from '../clone_sims.ts' ;
33import { createMockExecutor } from '../../../../test-utils/mock-executors.ts' ;
44import { allText , runLogic } from '../../../../test-utils/test-helpers.ts' ;
55
@@ -14,16 +14,6 @@ describe('clone_sims tool', () => {
1414 it ( 'clones a simulator and captures the new UDID' , async ( ) => {
1515 const newUdid = '00000000-0000-0000-0000-000000000001' ;
1616 const mock = createMockExecutor ( { success : true , output : `${ newUdid } \n` } ) ;
17- const res = await runLogic ( ( ) =>
18- clone_simsLogic ( { sourceSimulatorId : '00000000-0000-0000-0000-000000000000' } , mock ) ,
19- ) ;
20- expect ( res . isError ) . toBeFalsy ( ) ;
21- const text = allText ( res ) ;
22- expect ( text ) . toContain ( 'Simulator cloned successfully' ) ;
23- } ) ;
24-
25- it ( 'clones with a custom name' , async ( ) => {
26- const mock = createMockExecutor ( { success : true , output : 'UUID1\n' } ) ;
2717 const res = await runLogic ( ( ) =>
2818 clone_simsLogic (
2919 {
@@ -34,19 +24,60 @@ describe('clone_sims tool', () => {
3424 ) ,
3525 ) ;
3626 expect ( res . isError ) . toBeFalsy ( ) ;
27+ const text = allText ( res ) ;
28+ expect ( text ) . toContain ( 'Simulator cloned successfully' ) ;
29+ } ) ;
30+
31+ it ( 'passes the required custom name to simctl clone' , async ( ) => {
32+ const calls : string [ ] [ ] = [ ] ;
33+ const mock = createMockExecutor ( {
34+ success : true ,
35+ output : 'UUID1\n' ,
36+ onExecute : ( command ) => calls . push ( command ) ,
37+ } ) ;
38+
39+ const executeCloneSims = createCloneSimsExecutor ( mock ) ;
40+ const result = await executeCloneSims ( {
41+ sourceSimulatorId : '00000000-0000-0000-0000-000000000000' ,
42+ newName : 'My Clone' ,
43+ } ) ;
44+
45+ expect ( result . didError ) . toBe ( false ) ;
46+ expect ( calls ) . toEqual ( [
47+ [ 'xcrun' , 'simctl' , 'clone' , '00000000-0000-0000-0000-000000000000' , 'My Clone' ] ,
48+ ] ) ;
3749 } ) ;
3850 } ) ;
3951
4052 describe ( 'Failure path' , ( ) => {
4153 it ( 'returns failure when clone fails' , async ( ) => {
4254 const mock = createMockExecutor ( { success : false , error : 'No such device' } ) ;
4355 const res = await runLogic ( ( ) =>
44- clone_simsLogic ( { sourceSimulatorId : '00000000-0000-0000-0000-000000000000' } , mock ) ,
56+ clone_simsLogic (
57+ {
58+ sourceSimulatorId : '00000000-0000-0000-0000-000000000000' ,
59+ newName : 'My Clone' ,
60+ } ,
61+ mock ,
62+ ) ,
4563 ) ;
4664 expect ( res . isError ) . toBe ( true ) ;
4765 const text = allText ( res ) ;
4866 expect ( text ) . toContain ( 'Clone simulator failed' ) ;
4967 expect ( text ) . toContain ( 'No such device' ) ;
5068 } ) ;
69+
70+ it ( 'omits artifacts when clone fails before producing a cloned simulator ID' , async ( ) => {
71+ const mock = createMockExecutor ( { success : false , error : 'No such device' } ) ;
72+ const executeCloneSims = createCloneSimsExecutor ( mock ) ;
73+
74+ const result = await executeCloneSims ( {
75+ sourceSimulatorId : '00000000-0000-0000-0000-000000000000' ,
76+ newName : 'My Clone' ,
77+ } ) ;
78+
79+ expect ( result . didError ) . toBe ( true ) ;
80+ expect ( result . artifacts ) . toBeUndefined ( ) ;
81+ } ) ;
5182 } ) ;
5283} ) ;
0 commit comments