@@ -30,8 +30,8 @@ export type LimrunConnectionVerificationOptions = {
3030export async function verifyLimrunConnection (
3131 options : LimrunConnectionVerificationOptions ,
3232) : Promise < LimrunConnectionVerification > {
33- const connectAttached = attachedInstanceConnector ( options ) ;
34- if ( connectAttached ) return await verifyAttachedInstance ( options . platform , connectAttached ) ;
33+ const attached = await verifyAttachedInstance ( options ) ;
34+ if ( attached ) return attached ;
3535 if ( ! options . apiKey ) {
3636 throw new AppError (
3737 'INVALID_ARGS' ,
@@ -89,47 +89,44 @@ function readStatus(error: unknown): number | undefined {
8989 return typeof status === 'number' ? status : undefined ;
9090}
9191
92- type InstanceConnector = ( ) => Promise < { disconnect ( ) : void } > ;
93-
94- function attachedInstanceConnector (
92+ function connectAttachedInstance (
9593 options : LimrunConnectionVerificationOptions ,
96- ) : InstanceConnector | undefined {
94+ ) : Promise < { disconnect ( ) : void } > | undefined {
9795 const clientOptions = { logLevel : 'none' , maxReconnectAttempts : 0 } as const ;
98- const ios = options . instances ?. ios ;
99- if ( options . platform === 'ios' && ios ) {
100- return async ( ) =>
101- await (
102- await import ( '@limrun/api/ios-client' )
103- ) . createInstanceClient ( { ...clientOptions , ...ios } ) ;
104- }
105- const android = options . instances ?. android ;
106- if ( options . platform === 'android' && android ) {
107- return async ( ) =>
108- await (
109- await import ( '@limrun/api/instance-client' )
110- ) . createInstanceClient ( { ...clientOptions , ...android } ) ;
96+ const { ios, android } = options . instances ?? { } ;
97+ if ( options . platform === 'android' ) {
98+ return (
99+ android &&
100+ import ( '@limrun/api/instance-client' ) . then ( ( { createInstanceClient } ) =>
101+ createInstanceClient ( { ...clientOptions , ...android } ) ,
102+ )
103+ ) ;
111104 }
112- return undefined ;
105+ return (
106+ ios &&
107+ import ( '@limrun/api/ios-client' ) . then ( ( { createInstanceClient } ) =>
108+ createInstanceClient ( { ...clientOptions , ...ios } ) ,
109+ )
110+ ) ;
113111}
114112
115113async function verifyAttachedInstance (
116- platform : 'android' | 'ios' ,
117- connect : InstanceConnector ,
118- ) : Promise < LimrunConnectionVerification > {
119- const platformName = platform === 'android' ? 'Android' : 'iOS' ;
120- const instanceVars =
121- platform === 'android'
122- ? 'LIM_ANDROID_INSTANCE_URL, LIM_ANDROID_INSTANCE_TOKEN, and LIM_ANDROID_INSTANCE_ADB_URL'
123- : 'LIM_IOS_INSTANCE_URL and LIM_IOS_INSTANCE_TOKEN' ;
114+ options : LimrunConnectionVerificationOptions ,
115+ ) : Promise < LimrunConnectionVerification | undefined > {
116+ const connecting = connectAttachedInstance ( options ) ;
117+ if ( ! connecting ) return undefined ;
118+ const android = options . platform === 'android' ;
119+ const platformName = android ? 'Android' : 'iOS' ;
124120 try {
125- const client = await connect ( ) ;
126- client . disconnect ( ) ;
121+ ( await connecting ) . disconnect ( ) ;
127122 } catch ( error ) {
128123 throw new AppError (
129124 'COMMAND_FAILED' ,
130125 `Limrun ${ platformName } instance access failed.` ,
131126 {
132- hint : `Check ${ instanceVars } , and that the instance is still running.` ,
127+ hint : android
128+ ? 'Check LIM_ANDROID_INSTANCE_URL, LIM_ANDROID_INSTANCE_TOKEN, and LIM_ANDROID_INSTANCE_ADB_URL, and that the instance is still running.'
129+ : 'Check LIM_IOS_INSTANCE_URL and LIM_IOS_INSTANCE_TOKEN, and that the instance is still running.' ,
133130 } ,
134131 error ,
135132 ) ;
@@ -140,8 +137,8 @@ async function verifyAttachedInstance(
140137 verificationMessage : `Existing ${ platformName } instance access verified. agent-device will not create or delete it.` ,
141138 device : {
142139 status : 'verified' ,
143- name : `Existing ${ platformName } ${ platform === ' android' ? 'emulator' : 'simulator' } ` ,
144- platform,
140+ name : `Existing ${ platformName } ${ android ? 'emulator' : 'simulator' } ` ,
141+ platform : options . platform ,
145142 } ,
146143 app : {
147144 status : 'missing' ,
0 commit comments