A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
test: remediate offline font diagnostic review
Amruth Pillaiae8e2f76f1f6
diff --git a/.orchestration/plan-27a-diagnostic.md b/.orchestration/plan-27a-diagnostic.mdindex b3b9e869c..0a3ddccbb 100644--- a/.orchestration/plan-27a-diagnostic.md+++ b/.orchestration/plan-27a-diagnostic.md@@ -34,11 +34,11 @@ The exact markers are versioned as `offline-font-scripts-v1`:The four surfaces are separate tests:1. Font picker preview opens Typography → Font Family and waits for lazy `FontFace` preview loads.-2. Builder PDF preview navigates to the builder and records whether a PDF canvas appears.-3. Browser PDF download uses the Export dialog and extracts marker presence from the downloaded PDF when generation succeeds.-4. Server PDF calls the public PDF endpoint and extracts marker presence from its response when generation succeeds.+2. Builder PDF preview navigates to the builder, captures the active PDF canvas, and measures marker-local raster crops.+3. Browser PDF download uses the Export dialog, rasterizes the downloaded PDF, and measures marker-local crops when generation succeeds.+4. Server PDF calls the public PDF endpoint and records text-layer marker presence when generation succeeds.-PDF marker results classify missing text as a glyph result (`true`/`false` per marker), while blocked browser font requests classify the browser surface as `network-error`. The server report deliberately says `server-outbound-requests-unobservable-from-playwright`; it does not claim zero server requests.+Builder/browser-PDF reports keep PDF text extraction as a separate `textLayerMarkers` signal; it does not prove visible glyph outlines. Raster evidence attaches a rendered PNG and per-marker crop metrics, failing for blank or tofu-like visible crops. Blocked browser font requests classify browser surfaces as `network-error`. The server report deliberately says `server-outbound-requests-unobservable-from-playwright`; its cold-network gate remains unresolved because server outbound capture and verifiable restart identity require external host-level controls.## Run protocol and cold-cache boundary@@ -49,7 +49,7 @@ OFFLINE_FONT_DIAGNOSTIC=1 OFFLINE_FONT_DIAGNOSTIC_SERVER_RESTARTED=1 \pnpm exec playwright test tests/e2e/specs/offline-fonts.spec.ts --grep "picker preview"```-Stop and restart the production server before repeating the command with `builder PDF`, `browser PDF`, and `server PDF` grep patterns. The environment used for this change had no built `apps/server/dist` or `apps/web/dist`, no running PostgreSQL instance, and no production server to restart, so the cold E2E matrix was not run. This is an explicit infrastructure blocker, not a pass claim. The test still preserves the restart confirmation in its report (`serverRestartConfirmed`) for a later run.+Stop and restart the production server before repeating the command with `builder PDF`, `browser PDF`, and `server PDF` grep patterns. The environment used for this change had no built `apps/server/dist` or `apps/web/dist`, no running PostgreSQL instance, and no production server to restart, so the cold E2E matrix was not run. This is an explicit infrastructure blocker, not a pass claim. The test records `serverRestartFlag` only as caller input and labels it non-proof; it does not claim a completed cold-network gate.The current Playwright route guard cannot impose host-level egress denial on Node.js running the server. A genuinely cold server test therefore needs a separately restarted server plus host-level egress capture/deny (for example, a controlled network namespace or an approved outbound proxy). Do not infer server network behavior from an empty browser request list.@@ -124,7 +124,7 @@ Sizes are `Content-Length` bytes from a HEAD request to the exact current catalo| Noto Sans Thai | normal 400/700; italic reuses normal | `fonts.gstatic.com/s/notosansthai/v29` | OFL 1.1 | Thai fallback for both serif/sans slots | 55,173 | `packages/fonts`; `packages/pdf` script fallback || Noto Emoji | normal 400/700; italic reuses normal | `fonts.gstatic.com/s/notoemoji/v62` | OFL 1.1 for font files; assets/tools have separate licenses | Emoji outline fallback; verify renderer support | 1,153,847 | `packages/fonts`; `packages/pdf` script fallback |-Estimated transfer size for all rows and listed styles: **87,490,700 bytes (~83.45 MiB)**. This confirms why a full-catalog bundle is out of scope. A later implementation should subset by declared glyph requirements or make the administrator choose fallback families; it must not silently fetch another CDN.+Estimated transfer size for all rows and listed styles: **87,490,700 bytes (~83.44 MiB)**. This confirms why a full-catalog bundle is out of scope. A later implementation should subset by declared glyph requirements or make the administrator choose fallback families; it must not silently fetch another CDN.### Source and license obligations@@ -152,6 +152,6 @@ Completed read-only checks before handoff:- Web typography/regression suite: passed (940 tests across 135 files); web and server package typechecks passed.- `pnpm exec playwright test tests/e2e/specs/offline-fonts.spec.ts --list`: passed (4 diagnostic tests collected).- E2E diagnostic execution: blocked by missing build outputs and unavailable PostgreSQL/server; no success claim made.-- `pnpm exec turbo boundaries`: unresolved repository checker failure (418 parser-panicked `.js` files, including existing PDF/web source mirrors); no boundary violation was reported for the new TypeScript imports.+- `pnpm exec turbo boundaries`: passed on fresh rerun (Turbo 2.10.12, 1108 files, no issues).The implementation intentionally stops at diagnostic fixtures and manifest evidence. Shared source resolution, asset hosting, local-mode configuration, and production behavior remain Phase A step 3+ work.diff --git a/.orchestration/plan-27a-remediation.md b/.orchestration/plan-27a-remediation.mdnew file mode 100644index 000000000..c96cd6ecb--- /dev/null+++ b/.orchestration/plan-27a-remediation.md@@ -0,0 +1,24 @@+# Plan 27A remediation++Date: 2026-09-06+Base: `61b58ae9a`+Scope: concrete findings from `.orchestration/plan-27a-independent-review.md` only.++## Remediated findings++- Builder PDF preview and browser PDF download now produce raster evidence. The fixture stores each multilingual marker in its own summary paragraph, allowing the diagnostic to locate marker-local PDF text boxes and measure only those raster crops. Reports attach a rendered PNG plus per-marker `inkPixels`, trimmed dimensions, and status. Blank and tofu-like crops fail assertions; no whole-page snapshot is used.+- PDF text extraction is reported separately as `textLayerMarkers`. It is not described or asserted as proof of visible glyph outlines.+- Server PDF output remains text-extraction-only and is explicitly classified as `serverGateStatus: unresolved-external-host-level-blocker`. `serverRestartFlag` is caller input, not restart proof. Browser Playwright routing is not used to infer server egress, and no production resolver or instrumentation behavior was added.+- `.orchestration/plan-27a-diagnostic.md` now records a fresh boundaries pass and the corrected `87,490,700 bytes (~83.44 MiB)` arithmetic.+- Diagnostic remains opt-in through `OFFLINE_FONT_DIAGNOSTIC=1`; normal CI behavior remains unchanged. Request logs stay sanitized to hostname and pathname.++## Verification++- `pnpm exec biome check tests/e2e/specs/offline-fonts.spec.ts tests/e2e/fixtures/offline-fonts.ts` — passed.+- `git diff --check` — passed.+- `pnpm exec playwright test tests/e2e/specs/offline-fonts.spec.ts --list` — 4 tests collected.+- `pnpm --filter @reactive-resume/fonts test` — 55/55 passed.+- `pnpm --filter @reactive-resume/pdf exec vitest run src/hooks/use-register-fonts.test.ts` — 35/35 passed.+- `pnpm exec turbo boundaries` — passed on fresh rerun (Turbo 2.10.12, 1108 files, no issues).++Full diagnostic E2E remains unrun because this environment lacks production build output, PostgreSQL, and a production server. Server cold-network capture and verifiable restart identity remain external host-level blockers by design; this remediation does not claim that gate is complete.diff --git a/tests/e2e/fixtures/offline-fonts.ts b/tests/e2e/fixtures/offline-fonts.tsindex 6ecc6978b..38275ed06 100644--- a/tests/e2e/fixtures/offline-fonts.ts+++ b/tests/e2e/fixtures/offline-fonts.ts@@ -11,6 +11,7 @@ export const offlineFontScriptSamples = [] as const;const offlineFontFixtureText = offlineFontScriptSamples.map(({ marker }) => marker).join(" | ");+const offlineFontFixtureSummary = offlineFontScriptSamples.map(({ marker }) => `<p>${marker}</p>`).join("");export type OfflineFontResumeFixture = {builderURL: string;@@ -31,7 +32,8 @@ export async function seedOfflineFontResume(page: Page): Promise<OfflineFontResu{ path: ["picture", "hidden"], value: true },{ path: ["basics", "name"], value: "Offline Font Diagnostic Fixture" },{ path: ["basics", "headline"], value: offlineFontFixtureText },- { path: ["summary", "content"], value: `<p>${offlineFontFixtureText}</p>` },+ // Keep markers in separate blocks so raster evidence can map each script to a local PDF crop.+ { path: ["summary", "content"], value: offlineFontFixtureSummary },{ path: ["metadata", "typography", "body", "fontFamily"], value: "IBM Plex Serif" },{ path: ["metadata", "typography", "body", "fontWeights"], value: ["400", "700"] },{ path: ["metadata", "typography", "heading", "fontFamily"], value: "IBM Plex Serif" },diff --git a/tests/e2e/specs/offline-fonts.spec.ts b/tests/e2e/specs/offline-fonts.spec.tsindex eb35cbbd0..f1bda9261 100644--- a/tests/e2e/specs/offline-fonts.spec.ts+++ b/tests/e2e/specs/offline-fonts.spec.ts@@ -1,12 +1,13 @@import type { Browser, BrowserContext, Page, TestInfo } from "@playwright/test";import { readFile, writeFile } from "node:fs/promises";+import { createRequire } from "node:module";import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";import { offlineFontScriptSamples, seedOfflineFontResume } from "../fixtures/offline-fonts";import { createSampleResumeFromDashboard, openSidebarSection } from "../fixtures/resume";import { expect, test } from "../fixtures/test";const diagnosticEnabled = process.env.OFFLINE_FONT_DIAGNOSTIC === "1";-const serverRestartConfirmed = process.env.OFFLINE_FONT_DIAGNOSTIC_SERVER_RESTARTED === "1";+const serverRestartFlag = process.env.OFFLINE_FONT_DIAGNOSTIC_SERVER_RESTARTED === "1";type BlockedRequest = {hostname: string;@@ -20,6 +21,21 @@ type ColdContext = {type PdfMarkers = Record<(typeof offlineFontScriptSamples)[number]["name"], boolean>;+type RasterGlyphEvidence = {+ name: (typeof offlineFontScriptSamples)[number]["name"];+ status: "visible" | "blank" | "tofu-like" | "not-located";+ inkPixels: number;+ trimmedWidth: number;+ trimmedHeight: number;+};++type PdfRasterEvidence = {+ rasterDataUrl: string;+ textLayerMarkers: PdfMarkers;+ referenceGlyphs: RasterGlyphEvidence[];+ previewGlyphs: RasterGlyphEvidence[];+};+test.describe("offline font diagnostic", () => {test.describe.configure({ mode: "serial" });test.skip(!diagnosticEnabled, "Set OFFLINE_FONT_DIAGNOSTIC=1 to run network diagnostics.");@@ -49,7 +65,7 @@ test.describe("offline font diagnostic", () => {return { context, blockedRequests };}- function markerResult(text: string): PdfMarkers {+ function extractedMarkerResult(text: string): PdfMarkers {return Object.fromEntries(offlineFontScriptSamples.map((sample) => [sample.name, text.includes(sample.marker)]),) as PdfMarkers;@@ -74,6 +90,165 @@ test.describe("offline font diagnostic", () => {}}+ async function capturePdfBytes(page: Page) {+ await page.addInitScript(() => {+ const read = Blob.prototype.arrayBuffer;+ Blob.prototype.arrayBuffer = async function () {+ const buffer = await read.call(this);+ const bytes = new Uint8Array(buffer);+ if (String.fromCharCode(...bytes.subarray(0, 5)) === "%PDF-") {+ (window as Window & { offlineFontPdfBytes?: number[] }).offlineFontPdfBytes = Array.from(bytes);+ }+ return buffer;+ };+ });+ }++ async function renderPdfRasterEvidence(page: Page, bytes: Uint8Array): Promise<PdfRasterEvidence> {+ const require = createRequire(`${process.cwd()}/package.json`);+ await page.route("**/__offline_font_pdfjs/*", async (route) => {+ const worker = new URL(route.request().url()).pathname.endsWith("worker.mjs");+ await route.fulfill({+ contentType: "text/javascript",+ path: require.resolve(`pdfjs-dist/legacy/build/${worker ? "pdf.worker.mjs" : "pdf.mjs"}`),+ });+ });++ return page.evaluate(+ async ({ bytes, markers }) => {+ const moduleUrl = `${location.origin}/__offline_font_pdfjs/pdf.mjs`;+ const pdfjs: typeof import("pdfjs-dist/legacy/build/pdf.mjs") = await import(moduleUrl);+ pdfjs.GlobalWorkerOptions.workerSrc = `${location.origin}/__offline_font_pdfjs/worker.mjs`;+ const loadingTask = pdfjs.getDocument({ data: Uint8Array.from(bytes), useSystemFonts: false });+ try {+ const pdfDocument = await loadingTask.promise;+ const pdfPage = await pdfDocument.getPage(1);+ const textContent = await pdfPage.getTextContent();+ const textItems = textContent.items.flatMap((item) =>+ "str" in item+ ? [+ {+ str: item.str,+ x: item.transform[4] ?? 0,+ y: item.transform[5] ?? 0,+ width: item.width,+ height: Math.max(item.height, Math.abs(item.transform[3] ?? 0), 1),+ },+ ]+ : [],+ );+ const textLayer = textItems.map(({ str }) => str).join(" ");+ const baseViewport = pdfPage.getViewport({ scale: 1 });+ const rasterScale = 4;+ const viewport = pdfPage.getViewport({ scale: rasterScale });+ const raster = globalThis.document.createElement("canvas");+ raster.width = Math.ceil(viewport.width);+ raster.height = Math.ceil(viewport.height);+ const rasterContext = raster.getContext("2d");+ if (!rasterContext) throw new Error("Missing PDF raster context.");+ await pdfPage.render({+ canvas: raster,+ canvasContext: rasterContext,+ viewport,+ annotationMode: pdfjs.AnnotationMode.DISABLE,+ background: "white",+ }).promise;++ const boxes = markers.map((sample) => {+ const item = textItems.find(({ str }) => str.includes(sample.marker));+ if (!item) return { name: sample.name, marker: sample.marker, box: null };+ const height = Math.max(item.height, 1);+ const baseline = baseViewport.height - item.y;+ return {+ name: sample.name,+ marker: sample.marker,+ box: {+ x: item.x,+ y: baseline - height,+ width: Math.max(item.width, height),+ height,+ },+ };+ });++ function measure(canvas: HTMLCanvasElement, scale: number): RasterGlyphEvidence[] {+ const context = canvas.getContext("2d");+ if (!context) throw new Error("Missing PDF preview raster context.");+ const pixels = context.getImageData(0, 0, canvas.width, canvas.height);+ return boxes.map(({ name, box }) => {+ if (!box) return { name, status: "not-located", inkPixels: 0, trimmedWidth: 0, trimmedHeight: 0 };+ const padding = 2 * scale;+ const left = Math.max(0, Math.floor(box.x * scale - padding));+ const top = Math.max(0, Math.floor(box.y * scale - padding));+ const right = Math.min(canvas.width, Math.ceil((box.x + box.width) * scale + padding));+ const bottom = Math.min(canvas.height, Math.ceil((box.y + box.height) * scale + padding));+ let inkPixels = 0;+ let minX = right;+ let minY = bottom;+ let maxX = left;+ let maxY = top;+ for (let y = top; y < bottom; y += 1) {+ for (let x = left; x < right; x += 1) {+ const index = (y * pixels.width + x) * 4;+ const red = pixels.data[index] ?? 255;+ const green = pixels.data[index + 1] ?? 255;+ const blue = pixels.data[index + 2] ?? 255;+ if (red >= 245 && green >= 245 && blue >= 245) continue;+ inkPixels += 1;+ minX = Math.min(minX, x);+ minY = Math.min(minY, y);+ maxX = Math.max(maxX, x);+ maxY = Math.max(maxY, y);+ }+ }+ if (inkPixels === 0) {+ return { name, status: "blank", inkPixels, trimmedWidth: 0, trimmedHeight: 0 };+ }+ let interiorInk = 0;+ for (+ let y = minY + Math.floor((maxY - minY + 1) * 0.2);+ y < maxY - Math.floor((maxY - minY + 1) * 0.2);+ y += 1+ ) {+ for (+ let x = minX + Math.floor((maxX - minX + 1) * 0.2);+ x < maxX - Math.floor((maxX - minX + 1) * 0.2);+ x += 1+ ) {+ const index = (y * pixels.width + x) * 4;+ if (+ (pixels.data[index] ?? 255) < 245 ||+ (pixels.data[index + 1] ?? 255) < 245 ||+ (pixels.data[index + 2] ?? 255) < 245+ )+ interiorInk += 1;+ }+ }+ const trimmedWidth = maxX - minX + 1;+ const trimmedHeight = maxY - minY + 1;+ const interiorRatio = interiorInk / Math.max(inkPixels, 1);+ const status = interiorRatio < 0.08 && trimmedWidth >= 8 && trimmedHeight >= 8 ? "tofu-like" : "visible";+ return { name, status, inkPixels, trimmedWidth, trimmedHeight };+ });+ }++ const preview = document.querySelector<HTMLCanvasElement>('[aria-hidden="false"] canvas');+ return {+ rasterDataUrl: raster.toDataURL(),+ textLayerMarkers: Object.fromEntries(+ markers.map((sample) => [sample.name, textLayer.includes(sample.marker)]),+ ),+ referenceGlyphs: measure(raster, rasterScale),+ previewGlyphs: preview ? measure(preview, preview.width / baseViewport.width) : [],+ };+ } finally {+ await loadingTask.destroy();+ }+ },+ { bytes: Array.from(bytes), markers: offlineFontScriptSamples },+ );+ }+async function report(testInfo: TestInfo, name: string, reportData: Record<string, unknown>) {const body = JSON.stringify({version: 1,@@ -116,20 +291,33 @@ test.describe("offline font diagnostic", () => {const fixture = await seedOfflineFontResume(seedPage);const cold = await createColdContext(browser, seedPage, testInfo);const page = await cold.context.newPage();+ await capturePdfBytes(page);try {await page.goto(fixture.builderURL);await page.waitForTimeout(5_000);- const canvasVisible = await page- .locator('[aria-hidden="false"] canvas')- .first()- .isVisible()- .catch(() => false);+ const previewCanvas = page.locator('[aria-hidden="false"] canvas').first();+ const canvasVisible = await previewCanvas.isVisible().catch(() => false);+ const pdfBytes = await page.evaluate(+ () => (window as Window & { offlineFontPdfBytes?: number[] }).offlineFontPdfBytes,+ );+ expect(pdfBytes).toBeDefined();+ const rasterEvidence = pdfBytes ? await renderPdfRasterEvidence(page, Uint8Array.from(pdfBytes)) : null;+ if (rasterEvidence) {+ await testInfo.attach("builder-preview-raster.png", {+ body: Buffer.from(rasterEvidence.rasterDataUrl.split(",")[1] ?? "", "base64"),+ contentType: "image/png",+ });+ expect(rasterEvidence.previewGlyphs).toHaveLength(offlineFontScriptSamples.length);+ expect(rasterEvidence.previewGlyphs.every(({ status }) => status === "visible")).toBe(true);+ }+ expect(canvasVisible).toBe(true);await report(testInfo, "builder-preview", {cache: "new-browser-context",blockedExternalFontRequests: cold.blockedRequests,networkStatus: networkStatus(cold.blockedRequests),canvasVisible,- glyphStatus: "not-measured-preview-canvas",+ textLayerMarkers: rasterEvidence?.textLayerMarkers ?? "not-extracted",+ glyphStatus: rasterEvidence?.previewGlyphs ?? "not-rasterized",});} finally {await cold.context.close();@@ -145,6 +333,7 @@ test.describe("offline font diagnostic", () => {const cold = await createColdContext(browser, seedPage, testInfo);const page = await cold.context.newPage();let markerResultValue: PdfMarkers | null = null;+ let rasterEvidence: PdfRasterEvidence | null = null;let downloadStatus = "not-started";try {await page.goto(fixture.builderURL);@@ -156,7 +345,13 @@ test.describe("offline font diagnostic", () => {downloadStatus = "received";const path = testInfo.outputPath("offline-font-browser-download.pdf");await download.saveAs(path);- markerResultValue = markerResult(await readPdfText(new Uint8Array(await readFile(path))));+ const bytes = new Uint8Array(await readFile(path));+ markerResultValue = extractedMarkerResult(await readPdfText(bytes));+ rasterEvidence = await renderPdfRasterEvidence(page, bytes);+ await testInfo.attach("browser-download-raster.png", {+ body: Buffer.from(rasterEvidence.rasterDataUrl.split(",")[1] ?? "", "base64"),+ contentType: "image/png",+ });} catch {downloadStatus = "renderer-or-network-error";} finally {@@ -165,10 +360,15 @@ test.describe("offline font diagnostic", () => {blockedExternalFontRequests: cold.blockedRequests,networkStatus: networkStatus(cold.blockedRequests),downloadStatus,- glyphStatus: markerResultValue ?? "not-extracted",+ textLayerMarkers: markerResultValue ?? "not-extracted",+ glyphStatus: rasterEvidence?.referenceGlyphs ?? "not-rasterized",});await cold.context.close();}+ if (rasterEvidence) {+ expect(rasterEvidence.referenceGlyphs).toHaveLength(offlineFontScriptSamples.length);+ expect(rasterEvidence.referenceGlyphs.every(({ status }) => status === "visible")).toBe(true);+ }});test("exercises restarted-server PDF and records server observability boundary", async ({@@ -183,7 +383,7 @@ test.describe("offline font diagnostic", () => {let markerResultValue: PdfMarkers | null = null;try {await page.goto(fixture.builderURL);- if (!serverRestartConfirmed) {+ if (!serverRestartFlag) {responseStatus = "blocked-before-request";} else {const response = await page.request.get(@@ -193,19 +393,21 @@ test.describe("offline font diagnostic", () => {if (response.ok()) {const bytes = await response.body();await writeFile(testInfo.outputPath("offline-font-server.pdf"), bytes);- markerResultValue = markerResult(await readPdfText(new Uint8Array(bytes)));+ markerResultValue = extractedMarkerResult(await readPdfText(new Uint8Array(bytes)));}}} finally {await report(testInfo, "server-pdf", {cache: "new-browser-context; server-process-state-is-external",- serverRestartConfirmed,+ serverRestartFlag,+ serverGateStatus: "unresolved-external-host-level-blocker",blockedExternalFontRequests: cold.blockedRequests,networkStatus: "server-outbound-requests-unobservable-from-playwright",responseStatus,- glyphStatus: markerResultValue ?? "not-extracted",+ textLayerMarkers: markerResultValue ?? "not-extracted",+ glyphStatus: "not-rasterized-server-surface",limitation:- "Playwright route interception sees browser requests only; server fetches need a restarted process plus host-level egress capture.",+ "Server outbound request capture and verifiable restart identity remain unresolved external host-level blockers; the caller flag is not restart proof. Playwright route interception sees browser requests only; do not treat this run as a cold-network gate.",});await cold.context.close();}