mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2026-11-13 21:36:56 +00:00
package-version-list held every installed package and both outputs were identical. Outputs also carried arch suffixes inconsistently and followed install order. - package-version-list lists only requested packages; all-package-version-list lists every installed package. - Entries are name=version, with :arch only for packages installed for a non-native architecture (e.g. libc6:i386), so native output matches v1. - Entries are sorted with PackageName.compareTo. - Requested packages are matched by name, and by arch when both specify one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
3.6 KiB
TypeScript
129 lines
3.6 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}`,
|
|
);
|
|
});
|
|
});
|