@@ -11,6 +11,8 @@ import * as gitUtils from "./git-utils";
1111import { getRunnerLogger } from "./logging" ;
1212import {
1313 downloadOverlayBaseDatabaseFromCache ,
14+ getCacheRestoreKeyPrefix ,
15+ getCacheSaveKey ,
1416 OverlayDatabaseMode ,
1517 writeBaseDatabaseOidsFile ,
1618 writeOverlayChangesFile ,
@@ -261,3 +263,48 @@ test(
261263 } ,
262264 false ,
263265) ;
266+
267+ test ( "overlay-base database cache keys remain stable" , async ( t ) => {
268+ const logger = getRunnerLogger ( true ) ;
269+ const config = createTestConfig ( { languages : [ "python" , "javascript" ] } ) ;
270+ const codeQlVersion = "2.23.0" ;
271+ const commitOid = "abc123def456" ;
272+
273+ sinon . stub ( apiClient , "getAutomationID" ) . resolves ( "test-automation-id/" ) ;
274+ sinon . stub ( gitUtils , "getCommitOid" ) . resolves ( commitOid ) ;
275+ sinon . stub ( actionsUtil , "getWorkflowRunID" ) . returns ( 12345 ) ;
276+ sinon . stub ( actionsUtil , "getWorkflowRunAttempt" ) . returns ( 1 ) ;
277+
278+ const saveKey = await getCacheSaveKey (
279+ config ,
280+ codeQlVersion ,
281+ "checkout-path" ,
282+ logger ,
283+ ) ;
284+ const expectedSaveKey =
285+ "codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-abc123def456-12345-1" ;
286+ t . is (
287+ saveKey ,
288+ expectedSaveKey ,
289+ "Cache save key changed unexpectedly. " +
290+ "This may indicate breaking changes in the cache key generation logic." ,
291+ ) ;
292+
293+ const restoreKeyPrefix = await getCacheRestoreKeyPrefix (
294+ config ,
295+ codeQlVersion ,
296+ ) ;
297+ const expectedRestoreKeyPrefix =
298+ "codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-" ;
299+ t . is (
300+ restoreKeyPrefix ,
301+ expectedRestoreKeyPrefix ,
302+ "Cache restore key prefix changed unexpectedly. " +
303+ "This may indicate breaking changes in the cache key generation logic." ,
304+ ) ;
305+
306+ t . true (
307+ saveKey . startsWith ( restoreKeyPrefix ) ,
308+ `Expected save key "${ saveKey } " to start with restore key prefix "${ restoreKeyPrefix } "` ,
309+ ) ;
310+ } ) ;
0 commit comments