@@ -23,8 +23,10 @@ test.beforeEach(async (t) => {
2323 t . context . Configuration = Configuration ;
2424 sinon . stub ( Configuration , "fromFile" ) . resolves ( new Configuration ( { } ) ) ;
2525
26- t . context . cleanCacheStub = sinon . stub ( ) ;
27- t . context . getCacheInfoStub = sinon . stub ( ) ;
26+ t . context . frameworkCacheGetCacheInfo = sinon . stub ( ) ;
27+ t . context . frameworkCacheCleanCache = sinon . stub ( ) ;
28+ t . context . buildCacheGetCacheInfo = sinon . stub ( ) ;
29+ t . context . buildCacheCleanCache = sinon . stub ( ) ;
2830
2931 // Mock readline to simulate user confirmation
3032 const mockRLInterface = {
@@ -36,9 +38,15 @@ test.beforeEach(async (t) => {
3638
3739 t . context . cache = await esmock . p ( "../../../../lib/cli/commands/cache.js" , {
3840 "@ui5/project/config/Configuration" : t . context . Configuration ,
39- "@ui5/project/cache/CacheCleanup" : {
40- cleanCache : t . context . cleanCacheStub ,
41- getCacheInfo : t . context . getCacheInfoStub ,
41+ "@ui5/project/ui5Framework/cache" : {
42+ getCacheInfo : t . context . frameworkCacheGetCacheInfo ,
43+ cleanCache : t . context . frameworkCacheCleanCache
44+ } ,
45+ "@ui5/project/build/cache/CacheManager" : {
46+ default : class {
47+ static getCacheInfo = t . context . buildCacheGetCacheInfo ;
48+ static cleanCache = t . context . buildCacheCleanCache ;
49+ }
4250 } ,
4351 "node:readline" : {
4452 createInterface : t . context . readlineCreateInterfaceStub ,
@@ -67,41 +75,38 @@ test("Command builder", async (t) => {
6775} ) ;
6876
6977test . serial ( "ui5 cache clean: nothing to clean" , async ( t ) => {
70- const { cache, argv, stderrWriteStub, cleanCacheStub, getCacheInfoStub} = t . context ;
78+ const { cache, argv, stderrWriteStub, frameworkCacheCleanCache, frameworkCacheGetCacheInfo,
79+ buildCacheCleanCache, buildCacheGetCacheInfo} = t . context ;
7180
7281 // Simulate no cache items
73- getCacheInfoStub . resolves ( [ ] ) ;
82+ frameworkCacheGetCacheInfo . resolves ( null ) ;
83+ buildCacheGetCacheInfo . resolves ( null ) ;
7484
7585 argv [ "_" ] = [ "cache" , "clean" ] ;
7686 await cache . handler ( argv ) ;
7787
7888 t . is ( stderrWriteStub . firstCall . firstArg , "Nothing to clean\n" ) ;
79- t . is ( cleanCacheStub . callCount , 0 , "cleanCache should not be called" ) ;
89+ t . is ( frameworkCacheCleanCache . callCount , 0 , "frameworkCache.cleanCache should not be called" ) ;
90+ t . is ( buildCacheCleanCache . callCount , 0 , "buildCache.cleanCache should not be called" ) ;
8091} ) ;
8192
8293test . serial ( "ui5 cache clean: removes entries and reports" , async ( t ) => {
83- const { cache, argv, stderrWriteStub, cleanCacheStub , getCacheInfoStub ,
84- mockRLInterface} = t . context ;
94+ const { cache, argv, stderrWriteStub, frameworkCacheCleanCache , frameworkCacheGetCacheInfo ,
95+ buildCacheCleanCache , buildCacheGetCacheInfo , mockRLInterface} = t . context ;
8596
8697 // Simulate existing cache items
87- getCacheInfoStub . resolves ( [
88- { path : "framework/" , size : 15 * 1024 * 1024 , type : "directory" } ,
89- { path : "buildCache/ (database records)" , size : 8 * 1024 * 1024 , type : "database" } ,
90- ] ) ;
98+ frameworkCacheGetCacheInfo . resolves ( { path : "framework/" , size : 15 * 1024 * 1024 , type : "directory" } ) ;
99+ buildCacheGetCacheInfo . resolves ( {
100+ path : "buildCache/v0_7 (database records)" , size : 8 * 1024 * 1024 , type : "database"
101+ } ) ;
91102
92103 // Mock user confirmation
93104 mockRLInterface . question . callsFake ( ( question , callback ) => {
94105 callback ( "y" ) ;
95106 } ) ;
96107
97- cleanCacheStub . resolves ( {
98- entries : [
99- { path : "framework" , type : "framework" , size : 15 * 1024 * 1024 } ,
100- { path : "buildCache" , type : "buildCache" , size : 8 * 1024 * 1024 } ,
101- ] ,
102- totalSize : 23 * 1024 * 1024 ,
103- totalCount : 2 ,
104- } ) ;
108+ frameworkCacheCleanCache . resolves ( { path : "framework" , type : "framework" , size : 15 * 1024 * 1024 } ) ;
109+ buildCacheCleanCache . resolves ( { path : "buildCache/v0_7" , type : "buildCache" , size : 8 * 1024 * 1024 } ) ;
105110
106111 argv [ "_" ] = [ "cache" , "clean" ] ;
107112 await cache . handler ( argv ) ;
@@ -112,7 +117,8 @@ test.serial("ui5 cache clean: removes entries and reports", async (t) => {
112117 "Confirmation question should ask to continue" ) ;
113118
114119 // Check that cleanCache was called
115- t . is ( cleanCacheStub . callCount , 1 , "cleanCache should be called once" ) ;
120+ t . is ( frameworkCacheCleanCache . callCount , 1 , "frameworkCache.cleanCache should be called once" ) ;
121+ t . is ( buildCacheCleanCache . callCount , 1 , "buildCache.cleanCache should be called once" ) ;
116122
117123 // Check output
118124 const allOutput = stderrWriteStub . args . map ( ( a ) => a [ 0 ] ) . join ( "" ) ;
@@ -122,13 +128,12 @@ test.serial("ui5 cache clean: removes entries and reports", async (t) => {
122128} ) ;
123129
124130test . serial ( "ui5 cache clean: user cancels" , async ( t ) => {
125- const { cache, argv, stderrWriteStub, cleanCacheStub , getCacheInfoStub ,
126- mockRLInterface} = t . context ;
131+ const { cache, argv, stderrWriteStub, frameworkCacheCleanCache , frameworkCacheGetCacheInfo ,
132+ buildCacheCleanCache , buildCacheGetCacheInfo , mockRLInterface} = t . context ;
127133
128134 // Simulate existing cache items
129- getCacheInfoStub . resolves ( [
130- { path : "framework/" , size : 5 * 1024 * 1024 , type : "directory" }
131- ] ) ;
135+ frameworkCacheGetCacheInfo . resolves ( { path : "framework/" , size : 5 * 1024 * 1024 , type : "directory" } ) ;
136+ buildCacheGetCacheInfo . resolves ( null ) ;
132137
133138 // Mock user cancellation
134139 mockRLInterface . question . callsFake ( ( question , callback ) => {
@@ -141,8 +146,9 @@ test.serial("ui5 cache clean: user cancels", async (t) => {
141146 // Check that confirmation was asked
142147 t . is ( mockRLInterface . question . callCount , 1 , "Should ask for confirmation" ) ;
143148
144- // Check that cleanCache was NOT called
145- t . is ( cleanCacheStub . callCount , 0 , "cleanCache should not be called when user cancels" ) ;
149+ // Check that cleanup was NOT called
150+ t . is ( frameworkCacheCleanCache . callCount , 0 , "frameworkCache.cleanCache should not be called when user cancels" ) ;
151+ t . is ( buildCacheCleanCache . callCount , 0 , "buildCache.cleanCache should not be called when user cancels" ) ;
146152
147153 // Check output
148154 const allOutput = stderrWriteStub . args . map ( ( a ) => a [ 0 ] ) . join ( "" ) ;
@@ -160,75 +166,62 @@ test.serial("Command definition is correct", (t) => {
160166} ) ;
161167
162168test . serial ( "ui5 cache clean: accepts 'yes' as confirmation" , async ( t ) => {
163- const { cache, argv, cleanCacheStub, getCacheInfoStub, mockRLInterface} = t . context ;
169+ const { cache, argv, frameworkCacheCleanCache, frameworkCacheGetCacheInfo,
170+ buildCacheGetCacheInfo, mockRLInterface} = t . context ;
164171
165- getCacheInfoStub . resolves ( [
166- { path : "framework/" , size : 1024 , type : "directory" }
167- ] ) ;
172+ frameworkCacheGetCacheInfo . resolves ( { path : "framework/" , size : 1024 , type : "directory" } ) ;
173+ buildCacheGetCacheInfo . resolves ( null ) ;
168174
169175 mockRLInterface . question . callsFake ( ( question , callback ) => {
170176 callback ( "yes" ) ;
171177 } ) ;
172178
173- cleanCacheStub . resolves ( {
174- entries : [ { path : "framework" , type : "framework" , size : 1024 } ] ,
175- totalSize : 1024 ,
176- totalCount : 1 ,
177- } ) ;
179+ frameworkCacheCleanCache . resolves ( { path : "framework" , type : "framework" , size : 1024 } ) ;
178180
179181 argv [ "_" ] = [ "cache" , "clean" ] ;
180182 await cache . handler ( argv ) ;
181183
182- t . is ( cleanCacheStub . callCount , 1 , "cleanCache should be called with 'yes' confirmation" ) ;
184+ t . is ( frameworkCacheCleanCache . callCount , 1 , "frameworkCache. cleanCache should be called with 'yes' confirmation" ) ;
183185} ) ;
184186
185187test . serial ( "ui5 cache clean: formats byte sizes correctly" , async ( t ) => {
186- const { cache, argv, stderrWriteStub, cleanCacheStub, getCacheInfoStub, mockRLInterface} = t . context ;
188+ const { cache, argv, stderrWriteStub, frameworkCacheCleanCache, frameworkCacheGetCacheInfo,
189+ buildCacheCleanCache, buildCacheGetCacheInfo, mockRLInterface} = t . context ;
187190
188191 // Test with small bytes (B), KB, and GB sizes
189- getCacheInfoStub . resolves ( [
190- { path : "small" , size : 512 , type : "directory" } , // < 1024 = B
191- { path : "medium" , size : 50 * 1024 , type : "directory" } , // KB
192- { path : "large" , size : 2 * 1024 * 1024 * 1024 , type : "directory" } , // GB
193- ] ) ;
192+ frameworkCacheGetCacheInfo . resolves ( { path : "small" , size : 512 , type : "directory" } ) ; // < 1024 = B
193+ buildCacheGetCacheInfo . resolves ( { path : "medium" , size : 50 * 1024 , type : "database" } ) ; // KB
194194
195195 mockRLInterface . question . callsFake ( ( question , callback ) => {
196196 callback ( "y" ) ;
197197 } ) ;
198198
199- cleanCacheStub . resolves ( {
200- entries : [
201- { path : "small" , type : "directory" , size : 512 } ,
202- { path : "medium" , type : "directory" , size : 50 * 1024 } ,
203- { path : "large" , type : "directory" , size : 2 * 1024 * 1024 * 1024 } ,
204- ] ,
205- totalSize : 2 * 1024 * 1024 * 1024 + 50 * 1024 + 512 ,
206- totalCount : 3 ,
207- } ) ;
199+ frameworkCacheCleanCache . resolves ( { path : "small" , type : "directory" , size : 512 } ) ;
200+ buildCacheCleanCache . resolves ( { path : "medium" , type : "database" , size : 50 * 1024 } ) ;
208201
209202 argv [ "_" ] = [ "cache" , "clean" ] ;
210203 await cache . handler ( argv ) ;
211204
212205 const allOutput = stderrWriteStub . args . map ( ( a ) => a [ 0 ] ) . join ( "" ) ;
213206 t . true ( allOutput . includes ( "512 B" ) , "Shows bytes format" ) ;
214207 t . true ( allOutput . includes ( "50.0 KB" ) , "Shows KB format" ) ;
215- t . true ( allOutput . includes ( "2.0 GB" ) , "Shows GB format" ) ;
216208} ) ;
217209
218210test . serial ( "ui5 cache clean: uses UI5_DATA_DIR from environment" , async ( t ) => {
219- const { cache, argv, getCacheInfoStub } = t . context ;
211+ const { cache, argv, frameworkCacheGetCacheInfo , buildCacheGetCacheInfo } = t . context ;
220212 const originalEnv = process . env . UI5_DATA_DIR ;
221213
222214 try {
223215 process . env . UI5_DATA_DIR = "/custom/ui5/path" ;
224216
225- getCacheInfoStub . resolves ( [ ] ) ;
217+ frameworkCacheGetCacheInfo . resolves ( null ) ;
218+ buildCacheGetCacheInfo . resolves ( null ) ;
226219
227220 argv [ "_" ] = [ "cache" , "clean" ] ;
228221 await cache . handler ( argv ) ;
229222
230- t . is ( getCacheInfoStub . callCount , 1 , "getCacheInfo called" ) ;
231- t . true ( getCacheInfoStub . firstCall . args [ 0 ] . ui5DataDir . includes ( "custom/ui5/path" ) ,
223+ t . is ( frameworkCacheGetCacheInfo . callCount , 1 , "frameworkCache. getCacheInfo called" ) ;
224+ t . true ( frameworkCacheGetCacheInfo . firstCall . args [ 0 ] . includes ( "custom/ui5/path" ) ,
232225 "Uses environment variable path" ) ;
233226 } finally {
234227 if ( originalEnv ) {
@@ -240,19 +233,20 @@ test.serial("ui5 cache clean: uses UI5_DATA_DIR from environment", async (t) =>
240233} ) ;
241234
242235test . serial ( "ui5 cache clean: uses config.getUi5DataDir when no env var" , async ( t ) => {
243- const { cache, argv, getCacheInfoStub , Configuration} = t . context ;
236+ const { cache, argv, frameworkCacheGetCacheInfo , buildCacheGetCacheInfo , Configuration} = t . context ;
244237 const originalEnv = process . env . UI5_DATA_DIR ;
245238
246239 try {
247240 delete process . env . UI5_DATA_DIR ;
248241
249242 Configuration . fromFile . resolves ( new Configuration ( { ui5DataDir : "/config/path" } ) ) ;
250- getCacheInfoStub . resolves ( [ ] ) ;
243+ frameworkCacheGetCacheInfo . resolves ( null ) ;
244+ buildCacheGetCacheInfo . resolves ( null ) ;
251245
252246 argv [ "_" ] = [ "cache" , "clean" ] ;
253247 await cache . handler ( argv ) ;
254248
255- t . is ( getCacheInfoStub . callCount , 1 , "getCacheInfo called" ) ;
249+ t . is ( frameworkCacheGetCacheInfo . callCount , 1 , "frameworkCache. getCacheInfo called" ) ;
256250 } finally {
257251 if ( originalEnv ) {
258252 process . env . UI5_DATA_DIR = originalEnv ;
0 commit comments