chore(memory): capitalize ⚠ WinAnsi hotfix — LRN-021 + EVAL-003 + journal

- LRN-021: pdf-lib StandardFonts use WinAnsi (cp1252) — any non-Latin-1
  codepoint throws on measure or draw. Fix paths: ASCII surrogate
  (quick) or embed TTF via pdfDoc.embedFont (right). CLAUDE.md spec
  prescribed TTF; current StandardFonts is a documented drift.
- EVAL-003: bug slipped past 154/154 CI because roundtrip tests had no
  observation with a requires_vet_referral leaf. Regression test now
  measures a prefixed label via widthOfTextAtSize to canary any future
  non-WinAnsi marker reintroduction.
- journal 2026-05-21 appended with the hotfix note and the
  TTF-migration follow-up.
This commit is contained in:
Bastien Chanot committed 2026-05-21 03:34:56 +02:00
1 parent 143fdc3208
commit f4bb7cf9e0
3 files changed
+21

No files matched your search

+11
View File
@@ -156,6 +156,17 @@ Inline is simpler when the helper is one expression. Apply: any closure that bri
---
## LRN-021 | 2026-05-21 | pdf-lib StandardFonts use WinAnsi — Latin-1 only, throws on any non-WinAnsi char
`PDFDocument.embedFont(StandardFonts.Helvetica)` (and the 13 other Adobe built-ins) returns a font whose encoding is WinAnsi (cp1252). Any text op (`widthOfTextAtSize`, `drawText`) on a string carrying a non-WinAnsi codepoint throws synchronously: `WinAnsi cannot encode "<glyph>" (0x<hex>)`. Common offenders: ⚠ U+26A0, → U+2192, ✓ U+2713, ★, em-dash variants outside cp1252, all CJK. The error surfaces at the FIRST measurement pass (text-height estimator) — well before any draw call — so even a `try/catch` around drawing won't save you.
Fix paths:
- Quick: replace the offending glyph with a WinAnsi-safe ASCII surrogate (`(!) ` instead of `⚠ `, `->` instead of `→`).
- Right: embed a TTF (Inter, NotoSans, Fraunces…) via `pdfDoc.embedFont(ttfBytes)`. pdf-lib then subsets the actually-used glyphs into the PDF; arbitrary Unicode works. Per CLAUDE.md spec our PDF should already use TTFs — current StandardFonts shipment is a drift.
**Why:** Slipped past CI because the existing PDF roundtrip tests exercised observations without vet-referral findings; the WinAnsi error only fires when the offending glyph is present in a measured string.
**How to apply:** When a new visual cue (icon, badge, arrow) is added to PDF output, either restrict to ASCII or audit the font path. Add a regression test that exercises the measurement path with a representative string. The cheap canary: `font.widthOfTextAtSize(candidateGlyph, 10)` in a test.
---
## LRN-020 | 2026-05-21 | Forward-compat Zod schema absorbs catalog version bump zero-code
Catalog JSON went v1.2→v2.0 (semantic breaking change per author doc), but `findings.ts` Zod schema declared `requires_vet_referral` boolean + `description_fr` optional from B0 day-one. Result: v2.0 file dropped in, parses clean, 154/154 tests stay green, no schema edit, no consumer rewrite. Picker + PDF already keyed on boolean (no textual `description_fr.includes('vétérinaire')` fallback ever existed in our code), so the v2.0 "removed redundant text" change is a no-op at consumption site. Lesson: when authoring a Zod schema for external content, mark anything that "might or might not" appear as `.optional()` + make booleans authoritative early. The schema then forms a stable contract that absorbs author-side simplifications without code churn.