@@ -23,6 +23,18 @@ const HARMONY_DEVICE = {
2323} ;
2424const available = { available : true } as const ;
2525const unavailable = { available : false , reason : 'unsupported-platform-leaf' } as const ;
26+ const listAppsOperation : PlatformRuntimeOperations [ 'listApps' ] = vi . fn ( async ( { filter } ) =>
27+ filter === 'all'
28+ ? [
29+ { id : 'com.example.application' , name : 'application' } ,
30+ { id : 'com.ohos.settings' , name : 'settings' } ,
31+ ]
32+ : [ { id : 'com.example.application' , name : 'application' } ] ,
33+ ) ;
34+ const ensureReady = vi . fn ( async ( device : typeof HARMONY_DEVICE ) => ( {
35+ ...device ,
36+ booted : true ,
37+ } ) ) ;
2638
2739function runtimeFacts ( ) : RuntimeFacts < PlatformRuntimeOperations > {
2840 return {
@@ -33,7 +45,7 @@ function runtimeFacts(): RuntimeFacts<PlatformRuntimeOperations> {
3345 appLogStart : available ,
3446 appLogReattach : available ,
3547 appLogCleanup : available ,
36- listApps : unavailable ,
48+ listApps : { available : true } ,
3749 networkDump : unavailable ,
3850 screenRecordingStart : unavailable ,
3951 screenRecordingReattach : unavailable ,
@@ -54,7 +66,7 @@ const bindDevice: BindDeviceRuntime = async (device, use) => {
5466 device,
5567 owner : localRuntimeOwner ( 'harmonyos' ) ,
5668 facts : runtimeFacts ( ) ,
57- operations : { ensureReady : async ( ) => device } ,
69+ operations : { ensureReady, listApps : listAppsOperation } ,
5870 [ Symbol . asyncDispose ] : async ( ) => { } ,
5971 } ,
6072 use ,
@@ -63,10 +75,12 @@ const bindDevice: BindDeviceRuntime = async (device, use) => {
6375
6476beforeEach ( ( ) => {
6577 vi . mocked ( inspectFacts ) . mockClear ( ) ;
78+ vi . mocked ( listAppsOperation ) . mockClear ( ) ;
79+ vi . mocked ( ensureReady ) . mockClear ( ) ;
6680 bindCount = 0 ;
6781} ) ;
6882
69- async function listApps ( ) : Promise < DaemonResponse | null > {
83+ async function listApps ( appsFilter : 'all' | 'user-installed' ) : Promise < DaemonResponse | null > {
7084 const sessionName = 'harmony-apps' ;
7185 const sessionStore = makeSessionStore ( ) ;
7286 sessionStore . set ( sessionName , makeSession ( sessionName , HARMONY_DEVICE ) ) ;
@@ -75,7 +89,7 @@ async function listApps(): Promise<DaemonResponse | null> {
7589 session : sessionName ,
7690 command : 'apps' ,
7791 positionals : [ ] ,
78- flags : { appsFilter : 'all' } ,
92+ flags : { appsFilter } ,
7993 } ;
8094 return await handleSessionInventoryCommands ( {
8195 req,
@@ -86,11 +100,25 @@ async function listApps(): Promise<DaemonResponse | null> {
86100 } ) ;
87101}
88102
89- test ( 'HarmonyOS apps remains fail-closed when the legacy capability rejected the leaf' , async ( ) => {
90- await expect ( listApps ( ) ) . resolves . toMatchObject ( {
91- ok : false ,
92- error : { code : 'UNSUPPORTED_OPERATION' } ,
103+ test . each ( [
104+ {
105+ appsFilter : 'user-installed' as const ,
106+ expected : [ 'application (com.example.application)' ] ,
107+ } ,
108+ {
109+ appsFilter : 'all' as const ,
110+ expected : [ 'application (com.example.application)' , 'settings (com.ohos.settings)' ] ,
111+ } ,
112+ ] ) ( 'HarmonyOS apps preserves the $appsFilter response parity' , async ( { appsFilter, expected } ) => {
113+ await expect ( listApps ( appsFilter ) ) . resolves . toMatchObject ( {
114+ ok : true ,
115+ data : { apps : expected } ,
93116 } ) ;
94117 expect ( inspectFacts ) . toHaveBeenCalledOnce ( ) ;
95- expect ( bindCount ) . toBe ( 0 ) ;
118+ expect ( bindCount ) . toBe ( 1 ) ;
119+ expect ( ensureReady ) . toHaveBeenCalledOnce ( ) ;
120+ expect ( listAppsOperation ) . toHaveBeenCalledWith ( {
121+ device : expect . any ( Object ) ,
122+ filter : appsFilter ,
123+ } ) ;
96124} ) ;
0 commit comments