@@ -14,6 +14,8 @@ import {
1414 OverlayDatabaseMode ,
1515 writeBaseDatabaseOidsFile ,
1616 writeOverlayChangesFile ,
17+ getCacheRestoreKeyPrefix ,
18+ getCacheSaveKey ,
1719} from "./overlay-database-utils" ;
1820import {
1921 createTestConfig ,
@@ -261,3 +263,37 @@ test(
261263 } ,
262264 false ,
263265) ;
266+
267+ test ( "overlay-base database cache keys remain stable" , async ( t ) => {
268+ const config = createTestConfig ( { languages : [ "python" , "javascript" ] } ) ;
269+ const codeQlVersion = "2.23.0" ;
270+ const commitOid = "abc123def456" ;
271+ sinon . stub ( apiClient , "getAutomationID" ) . resolves ( "test-automation-id/" ) ;
272+ sinon . stub ( gitUtils , "getCommitOid" ) . resolves ( commitOid ) ;
273+ const saveKey = await getCacheSaveKey ( config , codeQlVersion , "checkout-path" ) ;
274+ const expectedSaveKey =
275+ "codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-abc123def456" ;
276+ t . is (
277+ saveKey ,
278+ expectedSaveKey ,
279+ "Cache save key changed unexpectedly. " +
280+ "This may indicate breaking changes in the cache key generation logic." ,
281+ ) ;
282+ const restoreKeyPrefix = await getCacheRestoreKeyPrefix (
283+ config ,
284+ codeQlVersion ,
285+ ) ;
286+ const expectedRestoreKeyPrefix =
287+ "codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-" ;
288+ t . is (
289+ restoreKeyPrefix ,
290+ expectedRestoreKeyPrefix ,
291+ "Cache restore key prefix changed unexpectedly. " +
292+ "This may indicate breaking changes in the cache key generation logic." ,
293+ ) ;
294+
295+ t . true (
296+ saveKey . startsWith ( restoreKeyPrefix ) ,
297+ `Expected save key "${ saveKey } " to start with restore key prefix "${ restoreKeyPrefix } "` ,
298+ ) ;
299+ } ) ;
0 commit comments