From 8d302d2dade726f720520fa1addaaabfda6212e5 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 26 Nov 2026 17:07:14 +0800 Subject: [PATCH] fix(ci): include the cache retention helper dependency (#14689) --- .github/workflows/cache-retention.yml | 1 + .../boundary/filesystem/ciCachePolicy.test.ts | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/cache-retention.yml b/.github/workflows/cache-retention.yml index 9c932c79c7..5763ca235b 100644 --- a/.github/workflows/cache-retention.yml +++ b/.github/workflows/cache-retention.yml @@ -46,6 +46,7 @@ jobs: sparse-checkout: | /.nvmrc /scripts/ci/cache-retention.mjs + /scripts/ci/github-api.mjs - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: ref: ${{ github.event.workflow_run.head_sha }} diff --git a/tests/boundary/filesystem/ciCachePolicy.test.ts b/tests/boundary/filesystem/ciCachePolicy.test.ts index 08f16a3c01..ccfc7e3323 100644 --- a/tests/boundary/filesystem/ciCachePolicy.test.ts +++ b/tests/boundary/filesystem/ciCachePolicy.test.ts @@ -9,7 +9,7 @@ import { readdir, writeFile, } from "node:fs/promises"; -import { delimiter, join } from "node:path"; +import { delimiter, dirname, join } from "node:path"; import { runInNewContext } from "node:vm"; import { beforeAll, describe, expect, it } from "vitest"; @@ -224,6 +224,7 @@ const retentionKeyFiles = [ async function exerciseTrustedRetentionWithLegacyTarget( retentionRun: unknown, retentionEnv: Record, + trustedSparseCheckout: string, ) { const runnerWorkspace = await createTestTempDirectory( "rea-ci-retention-trusted-checkout-", @@ -243,13 +244,14 @@ async function exerciseTrustedRetentionWithLegacyTarget( trustedSource, "scripts/ci/cache-retention.mjs", ); - await mkdir(join(trustedSource, "scripts/ci"), { recursive: true }); - for (const filename of ["cache-retention.mjs", "github-api.mjs"]) { - await copyFile( - join(repository, "scripts/ci", filename), - join(trustedSource, "scripts/ci", filename), - ); + for (const pattern of trustedSparseCheckout.trim().split("\n")) { + expect(pattern).toMatch(/^\/(?:\.nvmrc|scripts\/ci\/[\w-]+\.mjs)$/u); + const filename = pattern.slice(1); + const destination = join(trustedSource, filename); + await mkdir(dirname(destination), { recursive: true }); + await copyFile(join(repository, filename), destination); } + await expect(access(join(trustedSource, ".nvmrc"))).resolves.toBeUndefined(); await expect( access(join(legacyTarget, "scripts/ci/cache-retention.mjs")), ).rejects.toMatchObject({ code: "ENOENT" }); @@ -649,7 +651,6 @@ it("deletes superseded caches only from the trusted follow-up workflow", async ( path: "trusted-retention", "persist-credentials": false, "sparse-checkout-cone-mode": false, - "sparse-checkout": "/.nvmrc\n/scripts/ci/cache-retention.mjs\n", }); const targetCheckout = checkouts[1]; expect(targetCheckout?.with).toMatchObject({ @@ -687,7 +688,14 @@ it("deletes superseded caches only from the trusted follow-up workflow", async ( expect(retentionEnv.GH_TOKEN).toBe("${{ github.token }}"); // Exercise the selected trusted helper against a legacy target tree. - await exerciseTrustedRetentionWithLegacyTarget(retention?.run, retentionEnv); + const trustedInputs = z + .object({ "sparse-checkout": z.string() }) + .parse(trustedCheckout?.with); + await exerciseTrustedRetentionWithLegacyTarget( + retention?.run, + retentionEnv, + trustedInputs["sparse-checkout"], + ); const ci = workflows.find(({ file }) => file === "ci.yml")?.workflow; if (ci === undefined) throw new Error("Missing CI workflow"); expect(ci.permissions).toMatchObject({ contents: "read" });