@@ -38,7 +38,7 @@ describe('launch_app_device plugin (device-shared)', () => {
3838 const schema = z . strictObject ( launchAppDevice . schema ) ;
3939 expect ( schema . safeParse ( { } ) . success ) . toBe ( true ) ;
4040 expect ( schema . safeParse ( { bundleId : 'com.example.app' } ) . success ) . toBe ( false ) ;
41- expect ( Object . keys ( launchAppDevice . schema ) ) . toEqual ( [ ] ) ;
41+ expect ( Object . keys ( launchAppDevice . schema ) . sort ( ) ) . toEqual ( [ 'env' ] ) ;
4242 } ) ;
4343
4444 it ( 'should validate schema with invalid inputs' , ( ) => {
@@ -142,6 +142,67 @@ describe('launch_app_device plugin (device-shared)', () => {
142142 'com.apple.mobilesafari' ,
143143 ] ) ;
144144 } ) ;
145+
146+ it ( 'should append --environment-variables flags before bundleId when env is provided' , async ( ) => {
147+ const calls : any [ ] = [ ] ;
148+ const mockExecutor = createMockExecutor ( {
149+ success : true ,
150+ output : 'App launched successfully' ,
151+ process : { pid : 12345 } ,
152+ } ) ;
153+
154+ const trackingExecutor = async ( command : string [ ] ) => {
155+ calls . push ( { command } ) ;
156+ return mockExecutor ( command ) ;
157+ } ;
158+
159+ await launch_app_deviceLogic (
160+ {
161+ deviceId : 'test-device-123' ,
162+ bundleId : 'com.example.app' ,
163+ env : { STAGING_ENABLED : '1' , DEBUG : 'true' } ,
164+ } ,
165+ trackingExecutor ,
166+ createMockFileSystemExecutor ( ) ,
167+ ) ;
168+
169+ expect ( calls ) . toHaveLength ( 1 ) ;
170+ const cmd = calls [ 0 ] . command ;
171+ // bundleId should be the last element
172+ expect ( cmd [ cmd . length - 1 ] ) . toBe ( 'com.example.app' ) ;
173+ // --environment-variables flags should appear before bundleId
174+ const envIdx1 = cmd . indexOf ( '--environment-variables' ) ;
175+ expect ( envIdx1 ) . toBeGreaterThan ( - 1 ) ;
176+ expect ( cmd [ envIdx1 + 1 ] ) . toBe ( 'STAGING_ENABLED=1' ) ;
177+ const envIdx2 = cmd . indexOf ( '--environment-variables' , envIdx1 + 1 ) ;
178+ expect ( envIdx2 ) . toBeGreaterThan ( - 1 ) ;
179+ expect ( cmd [ envIdx2 + 1 ] ) . toBe ( 'DEBUG=true' ) ;
180+ } ) ;
181+
182+ it ( 'should not include --environment-variables when env is not provided' , async ( ) => {
183+ const calls : any [ ] = [ ] ;
184+ const mockExecutor = createMockExecutor ( {
185+ success : true ,
186+ output : 'App launched successfully' ,
187+ process : { pid : 12345 } ,
188+ } ) ;
189+
190+ const trackingExecutor = async ( command : string [ ] ) => {
191+ calls . push ( { command } ) ;
192+ return mockExecutor ( command ) ;
193+ } ;
194+
195+ await launch_app_deviceLogic (
196+ {
197+ deviceId : 'test-device-123' ,
198+ bundleId : 'com.example.app' ,
199+ } ,
200+ trackingExecutor ,
201+ createMockFileSystemExecutor ( ) ,
202+ ) ;
203+
204+ expect ( calls [ 0 ] . command ) . not . toContain ( '--environment-variables' ) ;
205+ } ) ;
145206 } ) ;
146207
147208 describe ( 'Success Path Tests' , ( ) => {
0 commit comments