mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2026-11-13 21:36:56 +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>
113 lines
3.5 KiB
TypeScript
113 lines
3.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { runAction, type ActionInputs, type ActionOutputs } from "../src/action.js";
|
|
import { Manifest, ManifestEntry } from "../src/manifest.js";
|
|
import { CacheKey } from "../src/cache.js";
|
|
import { createPackageName } from "ts-apt";
|
|
import { ActionPackageNames } from "../src/packages.js";
|
|
|
|
const NATIVE_ARCH = "amd64";
|
|
const FOREIGN_ARCH = "i386";
|
|
|
|
vi.mock("ts-apt", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("ts-apt")>();
|
|
return {
|
|
...actual,
|
|
createPackageManager: async () => ({
|
|
getNativeArchitecture: async () => NATIVE_ARCH,
|
|
}),
|
|
};
|
|
});
|
|
|
|
describe("runAction", () => {
|
|
const PKG_NAME = "curl";
|
|
const PKG_VER = "1.2.3";
|
|
const PKG2_NAME = "git";
|
|
const PKG3_NAME = "jq";
|
|
|
|
it("returns expected outputs for cache hit", async () => {
|
|
const inputs: ActionInputs = {
|
|
packages: `${PKG_NAME},${PKG2_NAME},${PKG3_NAME}`,
|
|
version: PKG_VER,
|
|
executeInstallScripts: false,
|
|
emptyPackagesBehavior: "error",
|
|
debug: false,
|
|
};
|
|
|
|
const packageNames = ActionPackageNames.fromInput(inputs.packages);
|
|
const cacheKey = new CacheKey(inputs.version, "0", process.arch, packageNames);
|
|
const manifest = new Manifest(
|
|
new Date(),
|
|
[
|
|
new ManifestEntry(createPackageName(PKG_NAME, PKG_VER, undefined), []),
|
|
new ManifestEntry(createPackageName(PKG2_NAME, PKG_VER, undefined), []),
|
|
new ManifestEntry(createPackageName(PKG3_NAME, PKG_VER, undefined), []),
|
|
],
|
|
cacheKey,
|
|
);
|
|
|
|
const mockCache = {
|
|
loadAndRestore: async () => manifest,
|
|
archiveAndSave: async () => {},
|
|
};
|
|
|
|
const mockCommandRunner = {
|
|
run: async () => {},
|
|
};
|
|
|
|
const mockLogger = {
|
|
info: () => {},
|
|
error: () => {},
|
|
debug: () => {},
|
|
};
|
|
|
|
const outputs: ActionOutputs = await runAction(
|
|
inputs,
|
|
mockCommandRunner as never,
|
|
mockCache as never,
|
|
mockLogger as never,
|
|
);
|
|
|
|
expect(outputs.cacheHit).toBe(true);
|
|
expect(outputs.packageVersionList).toBe(
|
|
`${PKG_NAME}=${PKG_VER},${PKG2_NAME}=${PKG_VER},${PKG3_NAME}=${PKG_VER}`,
|
|
);
|
|
expect(outputs.allPackageVersionList).toBe(
|
|
`${PKG_NAME}=${PKG_VER},${PKG2_NAME}=${PKG_VER},${PKG3_NAME}=${PKG_VER}`,
|
|
);
|
|
});
|
|
|
|
it("runAction cache hit with dependencies lists requested and all packages sorted with foreign arch only", async () => {
|
|
const inputs: ActionInputs = {
|
|
packages: `${PKG2_NAME} ${PKG_NAME}`,
|
|
version: PKG_VER,
|
|
executeInstallScripts: false,
|
|
emptyPackagesBehavior: "error",
|
|
debug: false,
|
|
};
|
|
const cacheKey = new CacheKey(
|
|
inputs.version,
|
|
"0",
|
|
process.arch,
|
|
ActionPackageNames.fromInput(inputs.packages),
|
|
);
|
|
// Install order, with a native-arch dependency and a foreign-arch request.
|
|
const manifest = new Manifest(
|
|
new Date(),
|
|
[
|
|
new ManifestEntry(createPackageName(PKG2_NAME, PKG_VER, FOREIGN_ARCH)),
|
|
new ManifestEntry(createPackageName(PKG3_NAME, PKG_VER, NATIVE_ARCH)),
|
|
new ManifestEntry(createPackageName(PKG_NAME, PKG_VER, undefined)),
|
|
],
|
|
cacheKey,
|
|
);
|
|
const mockCache = { loadAndRestore: async () => manifest };
|
|
|
|
const outputs = await runAction(inputs, {} as never, mockCache as never, {} as never);
|
|
|
|
expect(outputs.packageVersionList).toBe(`${PKG_NAME}=${PKG_VER},${PKG2_NAME}:${FOREIGN_ARCH}=${PKG_VER}`);
|
|
expect(outputs.allPackageVersionList).toBe(
|
|
`${PKG_NAME}=${PKG_VER},${PKG2_NAME}:${FOREIGN_ARCH}=${PKG_VER},${PKG3_NAME}=${PKG_VER}`,
|
|
);
|
|
});
|
|
});
|