Skip to content

Commit 2fbbe40

Browse files
committed
Add test to ensure overlay-base cache keys are stable
1 parent 0c5185d commit 2fbbe40

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/overlay-database-utils.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
OverlayDatabaseMode,
1515
writeBaseDatabaseOidsFile,
1616
writeOverlayChangesFile,
17+
getCacheRestoreKeyPrefix,
18+
getCacheSaveKey,
1719
} from "./overlay-database-utils";
1820
import {
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+
});

src/overlay-database-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ export async function downloadOverlayBaseDatabaseFromCache(
448448
* The key consists of the restore key prefix (which does not include the
449449
* commit SHA) and the commit SHA of the current checkout.
450450
*/
451-
async function getCacheSaveKey(
451+
export async function getCacheSaveKey(
452452
config: Config,
453453
codeQlVersion: string,
454454
checkoutPath: string,
@@ -475,7 +475,7 @@ async function getCacheSaveKey(
475475
* not include the commit SHA. This allows us to restore the most recent
476476
* compatible overlay-base database.
477477
*/
478-
async function getCacheRestoreKeyPrefix(
478+
export async function getCacheRestoreKeyPrefix(
479479
config: Config,
480480
codeQlVersion: string,
481481
): Promise<string> {

0 commit comments

Comments
 (0)