11import { expect , test , vi } from 'vitest' ;
2- import type { AppDeploymentRuntimeHost } from '@agent-device/contracts/platform' ;
2+ import type { AndroidAppDeploymentExecutor } from '@agent-device/contracts/platform' ;
33import type { DeviceInfo } from '@agent-device/kernel/device' ;
44import { androidAppDeploymentFacts , createAndroidAppDeploymentOperations } from './runtime.ts' ;
55
@@ -46,21 +46,20 @@ test('exposes all Android deployment operations only for admitted kinds', async
4646 const uninstall = vi . fn ( async ( ) => ( { packageName : 'com.example.replaced' } ) ) ;
4747 const appName = vi . fn ( async ( ) => 'Example' ) ;
4848 const push = vi . fn ( async ( ) => ( { action : 'com.example.app.TEST_PUSH' , extrasCount : 0 } ) ) ;
49- const host = {
50- android : {
51- ensureBooted,
52- withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
53- prepareArtifact,
54- install,
55- uninstall,
56- appName,
57- push,
58- } ,
59- } as unknown as AppDeploymentRuntimeHost ;
49+ const executor = {
50+ ensureBooted,
51+ withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
52+ prepareArtifact,
53+ install,
54+ uninstall,
55+ appName,
56+ push,
57+ } as AndroidAppDeploymentExecutor ;
58+ const signal = new AbortController ( ) . signal ;
6059 const operations = createAndroidAppDeploymentOperations ( {
61- host ,
60+ executor ,
6261 device,
63- signal : new AbortController ( ) . signal ,
62+ signal,
6463 } ) ;
6564
6665 await operations . deployApp ?.( { app : '' , appPath : '/tmp/app.apk' , replaceExisting : false } ) ;
@@ -81,6 +80,12 @@ test('exposes all Android deployment operations only for admitted kinds', async
8180 expect ( appName ) . toHaveBeenCalledTimes ( 2 ) ;
8281 expect ( push ) . toHaveBeenCalledOnce ( ) ;
8382 expect ( cleanup ) . toHaveBeenCalledTimes ( 2 ) ;
83+ expect ( uninstall ) . toHaveBeenCalledWith ( device , 'com.example.replaced' , signal ) ;
84+ expect ( install ) . toHaveBeenCalledWith ( device , '/tmp/app.apk' , {
85+ packageNameHint : 'com.example.app' ,
86+ signal,
87+ } ) ;
88+ expect ( push ) . toHaveBeenCalledWith ( device , { appId : 'com.example.app' , payload : { } } , signal ) ;
8489 expect ( prepareArtifact ) . toHaveBeenNthCalledWith (
8590 1 ,
8691 { source : { kind : 'path' , path : '/tmp/app.apk' } } ,
@@ -93,7 +98,7 @@ test('exposes all Android deployment operations only for admitted kinds', async
9398 ) ;
9499 expect (
95100 createAndroidAppDeploymentOperations ( {
96- host ,
101+ executor ,
97102 device : { ...device , kind : 'simulator' } ,
98103 signal : new AbortController ( ) . signal ,
99104 } ) ,
@@ -113,20 +118,18 @@ test('preserves the pre-install Android boot wait before artifact identity inspe
113118 cleanup : async ( ) => { } ,
114119 } ;
115120 } ) ;
116- const host = {
117- android : {
118- ensureBooted,
119- withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
120- prepareArtifact,
121- install : async ( ) => 'com.example.app' ,
122- uninstall : async ( ) => ( { packageName : 'com.example.app' } ) ,
123- appName : async ( ) => 'Example' ,
124- push : async ( ) => ( { } ) ,
125- } ,
126- } as unknown as AppDeploymentRuntimeHost ;
121+ const executor = {
122+ ensureBooted,
123+ withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
124+ prepareArtifact,
125+ install : async ( ) => 'com.example.app' ,
126+ uninstall : async ( ) => ( { packageName : 'com.example.app' } ) ,
127+ appName : async ( ) => 'Example' ,
128+ push : async ( ) => ( { } ) ,
129+ } as AndroidAppDeploymentExecutor ;
127130 const signal = new AbortController ( ) . signal ;
128131 const operations = createAndroidAppDeploymentOperations ( {
129- host ,
132+ executor ,
130133 device : { ...device , booted : false } ,
131134 signal,
132135 } ) ;
@@ -151,19 +154,17 @@ test('preserves Android reinstall partial-failure ordering', async () => {
151154 order . push ( 'install' ) ;
152155 return 'com.example.replaced' ;
153156 } ) ;
154- const host = {
155- android : {
156- ensureBooted : async ( ) => { } ,
157- withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
158- prepareArtifact,
159- install,
160- uninstall,
161- appName : async ( ) => 'Example' ,
162- push : async ( ) => ( { } ) ,
163- } ,
164- } as unknown as AppDeploymentRuntimeHost ;
157+ const executor = {
158+ ensureBooted : async ( ) => { } ,
159+ withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
160+ prepareArtifact,
161+ install,
162+ uninstall,
163+ appName : async ( ) => 'Example' ,
164+ push : async ( ) => ( { } ) ,
165+ } as AndroidAppDeploymentExecutor ;
165166 const operations = createAndroidAppDeploymentOperations ( {
166- host ,
167+ executor ,
167168 device,
168169 signal : new AbortController ( ) . signal ,
169170 } ) ;
@@ -208,22 +209,20 @@ test('clears cached fuzzy Android resolution before and after the whole reinstal
208209 cachedResolutions . set ( 'Maps' , 'com.example.replacement' ) ;
209210 return 'com.example.current' ;
210211 } ) ;
211- const host = {
212- android : {
213- ensureBooted : async ( ) => { } ,
214- prepareArtifact : async ( ) => ( {
215- installablePath : '/tmp/replacement.apk' ,
216- cleanup : async ( ) => { } ,
217- } ) ,
218- install,
219- uninstall,
220- appName : async ( ) => 'Example' ,
221- push : async ( ) => ( { } ) ,
222- withInvalidatedAppResolutionCache,
223- } ,
224- } as unknown as AppDeploymentRuntimeHost ;
212+ const executor = {
213+ ensureBooted : async ( ) => { } ,
214+ prepareArtifact : async ( ) => ( {
215+ installablePath : '/tmp/replacement.apk' ,
216+ cleanup : async ( ) => { } ,
217+ } ) ,
218+ install,
219+ uninstall,
220+ appName : async ( ) => 'Example' ,
221+ push : async ( ) => ( { } ) ,
222+ withInvalidatedAppResolutionCache,
223+ } as AndroidAppDeploymentExecutor ;
225224 const operations = createAndroidAppDeploymentOperations ( {
226- host ,
225+ executor ,
227226 device,
228227 signal : new AbortController ( ) . signal ,
229228 } ) ;
@@ -243,22 +242,20 @@ test('clears cached fuzzy Android resolution before and after the whole reinstal
243242
244243test ( 'keeps ordinary Android install successful when identity is unavailable' , async ( ) => {
245244 const appName = vi . fn ( async ( ) => 'should not be called' ) ;
246- const host = {
247- android : {
248- ensureBooted : async ( ) => { } ,
249- withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
250- prepareArtifact : async ( ) => ( {
251- installablePath : '/tmp/app.apk' ,
252- cleanup : async ( ) => { } ,
253- } ) ,
254- install : async ( ) => undefined ,
255- uninstall : async ( ) => ( { packageName : 'com.example.app' } ) ,
256- appName,
257- push : async ( ) => ( { } ) ,
258- } ,
259- } as unknown as AppDeploymentRuntimeHost ;
245+ const executor = {
246+ ensureBooted : async ( ) => { } ,
247+ withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
248+ prepareArtifact : async ( ) => ( {
249+ installablePath : '/tmp/app.apk' ,
250+ cleanup : async ( ) => { } ,
251+ } ) ,
252+ install : async ( ) => undefined ,
253+ uninstall : async ( ) => ( { packageName : 'com.example.app' } ) ,
254+ appName,
255+ push : async ( ) => ( { } ) ,
256+ } as AndroidAppDeploymentExecutor ;
260257 const operations = createAndroidAppDeploymentOperations ( {
261- host ,
258+ executor ,
262259 device,
263260 signal : new AbortController ( ) . signal ,
264261 } ) ;
0 commit comments