mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
On Windows 11 with Smart App Control on, Code Integrity refuses sharp's
unsigned libvips DLL. With `--against`, the per-frame render | reference
pair sheet called sharp unguarded, so a blocked sharp failed the whole
snapshot with sharp's multi-line error dump, after the first frame.
Guard the pair sheet: a sharp load failure prints one warning, later
frames skip their pair sheet without retrying, and every frame and
reference frame is still written. Any other pair-sheet error still fails
the snapshot. captureSnapshots reports the skip, so the summary lists
only ref-*.png when no pair sheets were made.
describeSharpLoadFailure turns sharp's load error into one line and names
Windows App Control for Win32 error 4551 ("An Application Control policy
has blocked this file"). The contact-sheet warning keeps warning on every
failure and uses it to shorten sharp's message, and --describe no longer
tells the user to install a sharp that is installed but blocked.
Refs #4845
Claude-Session: https://claude.ai/code/session_01JSZqP4FbpqviXu9v2LjBwE
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.7 KiB
TypeScript
61 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { describeSharpLoadFailure } from "./sharpLoadFailure.js";
|
|
|
|
// The shape of the error sharp throws when no native binding loads (sharp/dist/sharp.mjs).
|
|
function sharpLoadError(...causes: string[]): Error {
|
|
return new Error(
|
|
[
|
|
'Could not load the "sharp" module using the win32-x64 runtime',
|
|
...causes,
|
|
"Possible solutions:",
|
|
"- Ensure optional dependencies can be installed:",
|
|
" npm install --include=optional sharp",
|
|
].join("\n"),
|
|
);
|
|
}
|
|
|
|
describe("describeSharpLoadFailure", () => {
|
|
it("names Windows App Control when Code Integrity blocked the DLL", () => {
|
|
const err = sharpLoadError(
|
|
"ERR_DLOPEN_FAILED: \\\\?\\C:\\npm\\node_modules\\@img\\sharp-win32-x64\\sharp.node: An Application Control policy has blocked this file.",
|
|
);
|
|
expect(describeSharpLoadFailure(err)).toMatch(/^Windows App Control \(Smart App Control/);
|
|
});
|
|
|
|
it("keeps sharp's own first cause for any other failed load", () => {
|
|
const err = sharpLoadError("ERR_DLOPEN_FAILED: The specified module could not be found.");
|
|
expect(describeSharpLoadFailure(err)).toBe(
|
|
'Could not load the "sharp" module using the win32-x64 runtime (ERR_DLOPEN_FAILED: The specified module could not be found.)',
|
|
);
|
|
});
|
|
|
|
it("drops the carriage return Windows error text ends its lines with", () => {
|
|
const err = new Error(
|
|
'Could not load the "sharp" module using the win32-x64 runtime\r\nERR_DLOPEN_FAILED: %1 is not a valid Win32 application.\r\nPossible solutions:',
|
|
);
|
|
expect(describeSharpLoadFailure(err)).toBe(
|
|
'Could not load the "sharp" module using the win32-x64 runtime (ERR_DLOPEN_FAILED: %1 is not a valid Win32 application.)',
|
|
);
|
|
});
|
|
|
|
it("falls back to sharp's header when every cause was a missing package", () => {
|
|
expect(describeSharpLoadFailure(sharpLoadError())).toBe(
|
|
'Could not load the "sharp" module using the win32-x64 runtime',
|
|
);
|
|
});
|
|
|
|
it("finds sharp's error inside the CLI's own could-not-load wrapper", () => {
|
|
const err = new Error(
|
|
`contact sheets needs sharp, which is installed but could not load (${sharpLoadError("ERR_DLOPEN_FAILED: The specified module could not be found.").message}). Reinstall hyperframes with optional dependencies enabled, or run: npm i sharp`,
|
|
);
|
|
expect(describeSharpLoadFailure(err)).toBe(
|
|
'Could not load the "sharp" module using the win32-x64 runtime (ERR_DLOPEN_FAILED: The specified module could not be found.)',
|
|
);
|
|
});
|
|
|
|
it("ignores errors that are not a failed sharp load", () => {
|
|
expect(describeSharpLoadFailure(new Error("ENOENT: no such file"))).toBeNull();
|
|
expect(describeSharpLoadFailure("Input file is missing")).toBeNull();
|
|
});
|
|
});
|