@@ -12,6 +12,13 @@ const device: DeviceInfo = {
1212 booted : true ,
1313} ;
1414
15+ async function withoutInvalidatingAppResolutionCache < Result > (
16+ _device : DeviceInfo ,
17+ operation : ( ) => Promise < Result > ,
18+ ) : Promise < Result > {
19+ return await operation ( ) ;
20+ }
21+
1522test . each ( [
1623 [ 'emulator' , device , true ] ,
1724 [ 'physical device' , { ...device , kind : 'device' as const } , true ] ,
@@ -40,7 +47,15 @@ test('exposes all Android deployment operations only for admitted kinds', async
4047 const appName = vi . fn ( async ( ) => 'Example' ) ;
4148 const push = vi . fn ( async ( ) => ( { action : 'com.example.app.TEST_PUSH' , extrasCount : 0 } ) ) ;
4249 const host = {
43- android : { ensureBooted, prepareArtifact, install, uninstall, appName, push } ,
50+ android : {
51+ ensureBooted,
52+ withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
53+ prepareArtifact,
54+ install,
55+ uninstall,
56+ appName,
57+ push,
58+ } ,
4459 } as unknown as AppDeploymentRuntimeHost ;
4560 const operations = createAndroidAppDeploymentOperations ( {
4661 host,
@@ -101,6 +116,7 @@ test('preserves the pre-install Android boot wait before artifact identity inspe
101116 const host = {
102117 android : {
103118 ensureBooted,
119+ withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
104120 prepareArtifact,
105121 install : async ( ) => 'com.example.app' ,
106122 uninstall : async ( ) => ( { packageName : 'com.example.app' } ) ,
@@ -138,6 +154,7 @@ test('preserves Android reinstall partial-failure ordering', async () => {
138154 const host = {
139155 android : {
140156 ensureBooted : async ( ) => { } ,
157+ withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
141158 prepareArtifact,
142159 install,
143160 uninstall,
@@ -163,11 +180,73 @@ test('preserves Android reinstall partial-failure ordering', async () => {
163180 expect ( install ) . not . toHaveBeenCalled ( ) ;
164181} ) ;
165182
183+ test ( 'clears cached fuzzy Android resolution before and after the whole reinstall' , async ( ) => {
184+ const cachedResolutions = new Map ( [ [ 'Maps' , 'com.example.stale' ] ] ) ;
185+ const withInvalidatedAppResolutionCache = vi . fn (
186+ async < Result > ( _device : DeviceInfo , operation : ( ) => Promise < Result > ) : Promise < Result > => {
187+ cachedResolutions . clear ( ) ;
188+ try {
189+ return await operation ( ) ;
190+ } finally {
191+ cachedResolutions . clear ( ) ;
192+ }
193+ } ,
194+ ) ;
195+ const resolveFuzzyTarget = vi . fn ( async ( target : string ) => {
196+ const resolved = cachedResolutions . get ( target ) ?? 'com.example.current' ;
197+ cachedResolutions . set ( target , resolved ) ;
198+ return resolved ;
199+ } ) ;
200+ const uninstall = vi . fn ( async ( _device : DeviceInfo , app : string ) => {
201+ const packageName = await resolveFuzzyTarget ( app ) ;
202+ if ( packageName !== 'com.example.current' ) {
203+ throw new Error ( `stale fuzzy target: ${ packageName } ` ) ;
204+ }
205+ return { packageName } ;
206+ } ) ;
207+ const install = vi . fn ( async ( ) => {
208+ cachedResolutions . set ( 'Maps' , 'com.example.replacement' ) ;
209+ return 'com.example.current' ;
210+ } ) ;
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 ;
225+ const operations = createAndroidAppDeploymentOperations ( {
226+ host,
227+ device,
228+ signal : new AbortController ( ) . signal ,
229+ } ) ;
230+
231+ await expect (
232+ operations . deployApp ?.( {
233+ app : 'Maps' ,
234+ appPath : '/tmp/replacement.apk' ,
235+ replaceExisting : true ,
236+ } ) ,
237+ ) . resolves . toEqual ( { packageName : 'com.example.current' , launchTarget : 'com.example.current' } ) ;
238+
239+ expect ( withInvalidatedAppResolutionCache ) . toHaveBeenCalledOnce ( ) ;
240+ expect ( resolveFuzzyTarget ) . toHaveBeenCalledWith ( 'Maps' ) ;
241+ expect ( cachedResolutions ) . toEqual ( new Map ( ) ) ;
242+ } ) ;
243+
166244test ( 'keeps ordinary Android install successful when identity is unavailable' , async ( ) => {
167245 const appName = vi . fn ( async ( ) => 'should not be called' ) ;
168246 const host = {
169247 android : {
170248 ensureBooted : async ( ) => { } ,
249+ withInvalidatedAppResolutionCache : withoutInvalidatingAppResolutionCache ,
171250 prepareArtifact : async ( ) => ( {
172251 installablePath : '/tmp/app.apk' ,
173252 cleanup : async ( ) => { } ,
0 commit comments