mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-10-17 23:15:16 +02:00
## Summary - Preserve class names in the save-cache bundle so `@actions/cache` error-name comparisons distinguish validation errors, benign cache-reservation races, and finalization errors correctly. - Add regression coverage that exercises the bundled `ValidationError`, `ReserveCacheError`, and `FinalizeCacheError` constructors. Fixes #1028 ## Verification - `npm run all` passed on Ubuntu 24.04 with Node 24.19.0: build, Biome, packaging, and all 159 tests across 15 suites. - `git diff --check` passed. The save-cache bundle increases by about 77 KB raw (14 KB gzip) to preserve the required names.
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { runInNewContext } from "node:vm";
|
|
import { expect, it } from "@jest/globals";
|
|
|
|
const saveCacheBundle = readFileSync(
|
|
new URL("../../dist/save-cache/index.cjs", import.meta.url),
|
|
"utf8",
|
|
);
|
|
|
|
function bundledErrorClass(name: string): new (message: string) => Error {
|
|
const start = saveCacheBundle.indexOf(`var ${name} = class`);
|
|
expect(start).toBeGreaterThanOrEqual(0);
|
|
|
|
const end = saveCacheBundle.indexOf("\n};", start);
|
|
expect(end).toBeGreaterThan(start);
|
|
|
|
const declaration = saveCacheBundle.slice(start, end + 3);
|
|
return runInNewContext(`${declaration}; ${name}`, {
|
|
__name: (target: object, value: string) =>
|
|
Object.defineProperty(target, "name", { configurable: true, value }),
|
|
}) as new (
|
|
message: string,
|
|
) => Error;
|
|
}
|
|
|
|
it.each(["ValidationError", "ReserveCacheError", "FinalizeCacheError"])(
|
|
"preserves the %s name in the save-cache bundle",
|
|
(name) => {
|
|
const ErrorClass = bundledErrorClass(name);
|
|
|
|
expect(new ErrorClass("test").name).toBe(ErrorClass.name);
|
|
},
|
|
);
|