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:
Garry Tan
2026-05-29 07:04:46 -07:00
parent 065f7ed9f6
commit afaa40b796
3 changed files with 194 additions and 0 deletions
+28
View File
@@ -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);