Skip to content

Commit c97f06e

Browse files
authored
fix: preserve cache error class names in save-cache bundle (#1093)
## 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.
1 parent 8ca4be0 commit c97f06e

3 files changed

Lines changed: 2567 additions & 720 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { readFileSync } from "node:fs";
2+
import { runInNewContext } from "node:vm";
3+
import { expect, it } from "@jest/globals";
4+
5+
const saveCacheBundle = readFileSync(
6+
new URL("../../dist/save-cache/index.cjs", import.meta.url),
7+
"utf8",
8+
);
9+
10+
function bundledErrorClass(name: string): new (message: string) => Error {
11+
const start = saveCacheBundle.indexOf(`var ${name} = class`);
12+
expect(start).toBeGreaterThanOrEqual(0);
13+
14+
const end = saveCacheBundle.indexOf("\n};", start);
15+
expect(end).toBeGreaterThan(start);
16+
17+
const declaration = saveCacheBundle.slice(start, end + 3);
18+
return runInNewContext(`${declaration}; ${name}`, {
19+
__name: (target: object, value: string) =>
20+
Object.defineProperty(target, "name", { configurable: true, value }),
21+
}) as new (
22+
message: string,
23+
) => Error;
24+
}
25+
26+
it.each(["ValidationError", "ReserveCacheError", "FinalizeCacheError"])(
27+
"preserves the %s name in the save-cache bundle",
28+
(name) => {
29+
const ErrorClass = bundledErrorClass(name);
30+
31+
expect(new ErrorClass("test").name).toBe(ErrorClass.name);
32+
},
33+
);

0 commit comments

Comments
 (0)