mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2026-11-14 05:46:50 +00:00
Without a repo config, the Prettier CLI and Trunk used the default width of 80, while editors with a user printWidth reflowed files on save, producing formatting-only diffs. Pin the width in .prettierrc.json and reformat source, tests, scripts and JS/TS config files to match. Files that already failed Prettier at width 80 for unrelated reasons (tsconfig*.json, .trunk/*, V2_FAQ.MD) are left untouched. No code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
3.7 KiB
TypeScript
112 lines
3.7 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import winston from "winston";
|
|
import { Manifest, ManifestEntry } from "../src/manifest.js";
|
|
import { CacheKey } from "../src/cache.js";
|
|
import { ActionPackageNames } from "../src/packages.js";
|
|
import { createPackageManager, createPackageName } from "ts-apt";
|
|
|
|
import { ActionRunner } from "../src/action.js";
|
|
|
|
vi.mock("ts-apt", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("ts-apt")>();
|
|
return {
|
|
...actual,
|
|
createPackageManager: vi.fn(),
|
|
};
|
|
});
|
|
|
|
const NATIVE_ARCH = "amd64";
|
|
|
|
describe("ActionRunner", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
vi.mocked(createPackageManager).mockReset();
|
|
});
|
|
|
|
function createRunner() {
|
|
const cache = {
|
|
loadAndRestore: vi.fn(),
|
|
archiveAndSave: vi.fn(),
|
|
};
|
|
|
|
const commandRunner = {
|
|
run: vi.fn(),
|
|
};
|
|
|
|
const logger = winston.createLogger({ silent: true });
|
|
return {
|
|
runner: new ActionRunner(cache as never, commandRunner as never, logger),
|
|
cache,
|
|
commandRunner,
|
|
};
|
|
}
|
|
|
|
it("returns cache-hit outputs when manifest is restored", async () => {
|
|
const { runner, cache } = createRunner();
|
|
const packageNames = ActionPackageNames.fromInput("curl git");
|
|
const cacheKey = new CacheKey("v1", "0", process.arch, packageNames);
|
|
const restored = new Manifest(new Date(), [], cacheKey);
|
|
cache.loadAndRestore.mockResolvedValue(restored);
|
|
vi.mocked(createPackageManager).mockResolvedValue({
|
|
getNativeArchitecture: vi.fn().mockResolvedValue(NATIVE_ARCH),
|
|
} as never);
|
|
|
|
const result = await runner.runAction({
|
|
packages: "curl git",
|
|
version: "v1",
|
|
executeInstallScripts: false,
|
|
emptyPackagesBehavior: "error",
|
|
debug: false,
|
|
});
|
|
|
|
expect(result.cacheHit).toBe(true);
|
|
expect(cache.archiveAndSave).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("runAction cache hit creates package manager without apt-fast", async () => {
|
|
const { runner, cache } = createRunner();
|
|
const packageNames = ActionPackageNames.fromInput("curl");
|
|
const cacheKey = new CacheKey("v1", "0", process.arch, packageNames);
|
|
cache.loadAndRestore.mockResolvedValue(new Manifest(new Date(), [], cacheKey));
|
|
vi.mocked(createPackageManager).mockResolvedValue({
|
|
getNativeArchitecture: vi.fn().mockResolvedValue(NATIVE_ARCH),
|
|
} as never);
|
|
|
|
await runner.runAction({
|
|
packages: "curl",
|
|
version: "v1",
|
|
executeInstallScripts: false,
|
|
emptyPackagesBehavior: "error",
|
|
debug: false,
|
|
});
|
|
|
|
expect(vi.mocked(createPackageManager).mock.calls[0]?.[0]).toBe(false);
|
|
});
|
|
|
|
it("runAction cache miss archives installed packages with their files", async () => {
|
|
// Unlikely to have dpkg install scripts on the test host.
|
|
const installedPackage = createPackageName("test-pkg-not-real", "1.0.0");
|
|
// buildFileList keeps only files that exist, so use this test file.
|
|
const installedFile = import.meta.filename;
|
|
const { runner, cache } = createRunner();
|
|
cache.loadAndRestore.mockResolvedValue(undefined);
|
|
vi.mocked(createPackageManager).mockResolvedValue({
|
|
install: vi.fn().mockResolvedValue([{ name: installedPackage }]),
|
|
listInstalledFiles: vi.fn().mockResolvedValue([installedFile]),
|
|
getNativeArchitecture: vi.fn().mockResolvedValue(NATIVE_ARCH),
|
|
} as never);
|
|
|
|
await runner.runAction({
|
|
packages: installedPackage.serialize(),
|
|
version: "v1",
|
|
executeInstallScripts: false,
|
|
emptyPackagesBehavior: "error",
|
|
debug: false,
|
|
});
|
|
|
|
expect(cache.archiveAndSave).toHaveBeenCalledTimes(1);
|
|
const [manifest] = cache.archiveAndSave.mock.calls[0]!;
|
|
expect(manifest.entries).toEqual([new ManifestEntry(installedPackage, [installedFile.slice(1)])]);
|
|
});
|
|
});
|