diff --git a/test/cache-restore.test.ts b/test/cache-restore.test.ts index 35c3aa2..a5c2bf8 100644 --- a/test/cache-restore.test.ts +++ b/test/cache-restore.test.ts @@ -13,7 +13,7 @@ import { MANIFEST_MAIN_FILENAME, } from "../src/cache.js"; import { Manifest, ManifestEntry } from "../src/manifest.js"; -import { ActionPackageNames } from "../src/packages.js"; +import { ActionPackageNames, findInstallScript } from "../src/packages.js"; // Cache resolves its directory from os.homedir(), so point it at a temp dir. const { HOME_DIR } = await vi.hoisted(async () => { @@ -29,6 +29,11 @@ vi.mock("node:os", async (importOriginal) => { const actual = await importOriginal(); return { ...actual, homedir: () => HOME_DIR }; }); +// Restore looks for install scripts under the real "/", so stub the lookup. +vi.mock("../src/packages.js", async (importOriginal) => { + const actual = await importOriginal(); + return { ...actual, findInstallScript: vi.fn() }; +}); vi.mock("@actions/cache", () => ({ restoreCache: vi.fn(), saveCache: vi.fn(), @@ -66,18 +71,20 @@ async function writeCache(archivedPackages = INSTALL_ORDER): Promise { archivedPackages.forEach((pkg) => fs.writeFileSync(archivePath(pkg), "")); } -/** Archive operations observed through the command runner. */ +/** Archive and install script operations observed through the command runner. */ interface TarCalls { created: [archive: string, files: string[]][]; extracted: string[]; /** Number of commands run that extracted archives. */ extractCommands?: number; + /** Extractions and script runs, in the order they ran. */ + events?: string[]; } const argValue = (args: string[], flag: string) => args.find((arg) => arg.startsWith(`${flag}=`))?.slice(flag.length + 1); -/** Records sudo tar calls, including the file list piped to tar create. */ +/** Records sudo tar and script calls, including the file list piped to tar create. */ function recordTar(calls: TarCalls) { return vi.fn(async (_command: string, args: string[] = [], options: CommandOptions = {}) => { const archive = argValue(args, "--file") ?? ""; @@ -88,6 +95,11 @@ function recordTar(calls: TarCalls) { if (args[0] === "sh" && args[1] === "-c") { calls.extracted.push(...args.slice(4)); calls.extractCommands = (calls.extractCommands ?? 0) + 1; + calls.events?.push(...args.slice(4).map((archive) => `extract ${path.basename(archive)}`)); + } + // Install scripts run as `sh -x