@@ -237,15 +237,17 @@ test("downloadDependencyCaches - does not restore caches with feature keys if no
237237 . resolves ( CSHARP_BASE_PATTERNS ) ;
238238 makePatternCheckStub . withArgs ( CSHARP_EXTRA_PATTERNS ) . resolves ( undefined ) ;
239239
240- const results = await downloadDependencyCaches (
240+ const result = await downloadDependencyCaches (
241241 codeql ,
242242 createFeatures ( [ ] ) ,
243243 [ KnownLanguage . csharp ] ,
244244 logger ,
245245 ) ;
246- t . is ( results . length , 1 ) ;
247- t . is ( results [ 0 ] . language , KnownLanguage . csharp ) ;
248- t . is ( results [ 0 ] . hit_kind , CacheHitKind . Miss ) ;
246+ const statusReport = result . statusReport ;
247+ t . is ( statusReport . length , 1 ) ;
248+ t . is ( statusReport [ 0 ] . language , KnownLanguage . csharp ) ;
249+ t . is ( statusReport [ 0 ] . hit_kind , CacheHitKind . Miss ) ;
250+ t . deepEqual ( result . restoredKeys , [ ] ) ;
249251 t . assert ( restoreCacheStub . calledOnce ) ;
250252} ) ;
251253
@@ -257,7 +259,8 @@ test("downloadDependencyCaches - restores caches with feature keys if features a
257259 const logger = getRecordingLogger ( messages ) ;
258260 const features = createFeatures ( [ Feature . CsharpNewCacheKey ] ) ;
259261
260- sinon . stub ( glob , "hashFiles" ) . resolves ( "abcdef" ) ;
262+ const mockHash = "abcdef" ;
263+ sinon . stub ( glob , "hashFiles" ) . resolves ( mockHash ) ;
261264
262265 const keyWithFeature = await cacheKey (
263266 codeql ,
@@ -277,15 +280,28 @@ test("downloadDependencyCaches - restores caches with feature keys if features a
277280 . resolves ( CSHARP_BASE_PATTERNS ) ;
278281 makePatternCheckStub . withArgs ( CSHARP_EXTRA_PATTERNS ) . resolves ( undefined ) ;
279282
280- const results = await downloadDependencyCaches (
283+ const result = await downloadDependencyCaches (
281284 codeql ,
282285 features ,
283286 [ KnownLanguage . csharp ] ,
284287 logger ,
285288 ) ;
286- t . is ( results . length , 1 ) ;
287- t . is ( results [ 0 ] . language , KnownLanguage . csharp ) ;
288- t . is ( results [ 0 ] . hit_kind , CacheHitKind . Exact ) ;
289+
290+ // Check that the status report for telemetry indicates that one cache was restored with an exact match.
291+ const statusReport = result . statusReport ;
292+ t . is ( statusReport . length , 1 ) ;
293+ t . is ( statusReport [ 0 ] . language , KnownLanguage . csharp ) ;
294+ t . is ( statusReport [ 0 ] . hit_kind , CacheHitKind . Exact ) ;
295+
296+ // Check that the restored key has been returned.
297+ const restoredKeys = result . restoredKeys ;
298+ t . is ( restoredKeys . length , 1 ) ;
299+ t . assert (
300+ restoredKeys [ 0 ] . endsWith ( mockHash ) ,
301+ "Expected restored key to end with hash returned by `hashFiles`" ,
302+ ) ;
303+
304+ // `restoreCache` should have been called exactly once.
289305 t . assert ( restoreCacheStub . calledOnce ) ;
290306} ) ;
291307
@@ -297,8 +313,14 @@ test("downloadDependencyCaches - restores caches with feature keys if features a
297313 const logger = getRecordingLogger ( messages ) ;
298314 const features = createFeatures ( [ Feature . CsharpNewCacheKey ] ) ;
299315
316+ // We expect two calls to `hashFiles`: the first by the call to `cacheKey` below,
317+ // and the second by `downloadDependencyCaches`. We use the result of the first
318+ // call as part of the cache key that identifies a mock, existing cache. The result
319+ // of the second call is for the primary restore key, which we don't want to match
320+ // the first key so that we can test the restore keys logic.
321+ const restoredHash = "abcdef" ;
300322 const hashFilesStub = sinon . stub ( glob , "hashFiles" ) ;
301- hashFilesStub . onFirstCall ( ) . resolves ( "abcdef" ) ;
323+ hashFilesStub . onFirstCall ( ) . resolves ( restoredHash ) ;
302324 hashFilesStub . onSecondCall ( ) . resolves ( "123456" ) ;
303325
304326 const keyWithFeature = await cacheKey (
@@ -319,15 +341,27 @@ test("downloadDependencyCaches - restores caches with feature keys if features a
319341 . resolves ( CSHARP_BASE_PATTERNS ) ;
320342 makePatternCheckStub . withArgs ( CSHARP_EXTRA_PATTERNS ) . resolves ( undefined ) ;
321343
322- const results = await downloadDependencyCaches (
344+ const result = await downloadDependencyCaches (
323345 codeql ,
324346 features ,
325347 [ KnownLanguage . csharp ] ,
326348 logger ,
327349 ) ;
328- t . is ( results . length , 1 ) ;
329- t . is ( results [ 0 ] . language , KnownLanguage . csharp ) ;
330- t . is ( results [ 0 ] . hit_kind , CacheHitKind . Partial ) ;
350+
351+ // Check that the status report for telemetry indicates that one cache was restored with a partial match.
352+ const statusReport = result . statusReport ;
353+ t . is ( statusReport . length , 1 ) ;
354+ t . is ( statusReport [ 0 ] . language , KnownLanguage . csharp ) ;
355+ t . is ( statusReport [ 0 ] . hit_kind , CacheHitKind . Partial ) ;
356+
357+ // Check that the restored key has been returned.
358+ const restoredKeys = result . restoredKeys ;
359+ t . is ( restoredKeys . length , 1 ) ;
360+ t . assert (
361+ restoredKeys [ 0 ] . endsWith ( restoredHash ) ,
362+ "Expected restored key to end with hash returned by `hashFiles`" ,
363+ ) ;
364+
331365 t . assert ( restoreCacheStub . calledOnce ) ;
332366} ) ;
333367
0 commit comments