mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-22 01:30:03 +02:00
test(make-pdf): emoji render gate (pdffonts + pixel proof)
pdftotext is a false oracle for emoji: Skia preserves the Unicode in the text cluster even when the glyph drew as .notdef tofu, so extraction passes on a broken render. The gate instead asserts (1) pdffonts shows an emoji family embedded and (2) pdftoppm rasterizes the page to color (measured ~1650 saturated pixels vs ~0 for tofu). pdfimages is not used: macOS embeds color emoji as Type 3 fonts, so it lists nothing even on a correct render. Adds resolvePopplerTool() (DRY resolver, returns null for clean skips) and a fixture exercising FE0F variation-selector emoji. Skips cleanly when poppler tools or a color-emoji font are unavailable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -114,6 +114,34 @@ export function resolvePdftotext(env: NodeJS.ProcessEnv = process.env): Pdftotex
|
||||
].join("\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate a poppler companion tool (pdffonts, pdfimages, pdftoppm) used by the
|
||||
* emoji render gate. Mirrors resolvePdftotext's resolution order:
|
||||
* 1. $GSTACK_<TOOL>_BIN env override (e.g. GSTACK_PDFFONTS_BIN)
|
||||
* 2. PATH via Bun.which
|
||||
* 3. standard POSIX locations (Homebrew + distro)
|
||||
*
|
||||
* Returns null (does NOT throw) when the tool is missing — the emoji gate skips
|
||||
* cleanly rather than failing on a box without full poppler-utils.
|
||||
*/
|
||||
export function resolvePopplerTool(
|
||||
tool: "pdffonts" | "pdfimages" | "pdftoppm",
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): string | null {
|
||||
const override = resolveOverride(env[`GSTACK_${tool.toUpperCase()}_BIN`], env);
|
||||
if (override) return override;
|
||||
|
||||
const PATH = env.PATH ?? env.Path ?? "";
|
||||
const onPath = Bun.which(tool, { PATH });
|
||||
if (onPath) return onPath;
|
||||
|
||||
for (const dir of ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin"]) {
|
||||
const candidate = findExecutable(path.join(dir, tool));
|
||||
if (candidate) return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isExecutable(p: string): boolean {
|
||||
try {
|
||||
fs.accessSync(p, fs.constants.X_OK);
|
||||
|
||||
Reference in New Issue
Block a user