Skip to content

fix(frontend): align browser labels with canonical print pipeline - #487

Merged
khaira777 merged 4 commits into
mainfrom
fm/flocafe-480-browser-label-pipeline
Aug 23, 2026
Merged

khaira777 merged 4 commits into
mainfrom
fm/flocafe-480-browser-label-pipeline

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Implement FloCafe issue #480 by aligning browser printing label resolution in frontend/src/lib/printer/web-print.ts with the canonical shared PrintDocument label pipeline used by the other semantic renderers. Route browser label lookup through the shared frontend PrintDocument bridge, canonical catalog resolver, receipt language policy, and registry-derived direction, while preserving existing browser user-visible output for supported locales, including Persian/RTL direction, localized labels, merchant-template label overrides where applicable, and unknown-label English fallback behavior. Keep browser/LAN printing independent of Electron APIs; preserve popup/print-preview and WebUSB behavior; do not alter ESC/POS transport bytes or unrelated printer profiles. Extend existing browser/semantic/parity printing tests for representative receipt and POS labels across supported locale/RTL paths plus fallback behavior, update the relevant printing capability documentation to narrow the browser-label exception and link the enforcing code/tests, and run focused printing tests, lint, backend/frontend builds, i18n checks, and required validation. Use a descriptive conventional PR title and PR body containing Fixes #480 Refs #438 Refs #444; do not merge the PR.

What Changed

  • Routed browser receipt label resolution through the shared frontend PrintDocument bridge, canonical catalog resolver, receipt-language policy, and registry-derived direction while preserving browser-specific wording, layout, and fallback behavior.
  • Updated the print-test HTML download path, browser receipt/parity coverage, and printing documentation to capture canonical localized labels, RTL handling, merchant-template label fallback, and unknown-language English fallback.

Fixes #480
Refs #438
Refs #444

Risk Assessment

✅ Low: The scoped browser label refactor is bounded, preserves existing supported-locale wording and RTL behavior, routes through the shared policy/document resolver, and does not alter ESC/POS transport paths.

Testing

Exercised focused browser, PrintDocument, semantic parity, WebUSB, popup, merchant-template, receipt-policy, and locale-regression paths; captured reviewer-visible HTML/PNG evidence and removed test-created dependency directories. Repository-wide lint/build/static checks were not run because this assigned test phase explicitly prohibited them.

  • Evidence: Persian RTL receipt (local file: /Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/01_persian_receipt_rial_persian_digits.png)
  • Evidence: English browser receipt (local file: /Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/05_english_receipt_baseline.png)
  • Evidence: End-to-end Persian print bridge (local file: /Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/web_print_bill_fa_ir.png)
  • Evidence: Popup fallback simulation (local file: /Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/popup_window_simulation.png)
  • Evidence: System print fallback receipt (local file: /Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/fallback_receipt_80mm_preview.png)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed (2) ✅
  • 🚨 frontend/src/lib/printer/web-print.ts:262 - generateBillHtml now follows receipt policy, but only printWebBill preloads locale bundles. The direct HTML preview caller can therefore produce English labels with Persian RTL direction on a cold start when policy is fixed to fa. Preload resolved languages before synchronous preview generation.
  • ⚠️ docs/printers.md:26 - The documentation claims labels do not diverge by transport, but browser intentionally preserves wording such as Grand Total versus WebUSB TOTAL. Document shared resolver parity while retaining surface-specific wording.
  • ⚠️ docs/merchant-print-templates.md:201 - The required intent asks for links to enforcing code/tests. The documentation names web-print.ts and print-document.ts, but fallback warning ownership is in usePrinter.ts/warnings.ts, and the tests are referenced only generically. Please confirm correcting these links and owners.

🔧 Fix: Fix preview locale preload and clarify label parity
1 warning still open:

  • ⚠️ docs/merchant-print-templates.md:202 - The required intent says to “update the relevant printing capability documentation to narrow the browser-label exception and link the enforcing code/tests.” The new section names web-print.ts, print-document.ts, and generic browser/parity tests, but merchant-template fallback is actually produced by frontend/src/hooks/usePrinter.ts using frontend/src/lib/printer/warnings.ts, with behavioral tests in tests/printer.test.ts. Correct the documentation links and owners.

🔧 Fix: Link merchant fallback ownership and behavioral coverage
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • EVIDENCE_DIR=... REQUIRE_VISUAL_EVIDENCE=1 npm run test:browser-receipts
  • npm run test:print-parity
  • npm run test:print-document
  • npm run test:print-labels
  • npx ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts
  • npm run test:merchant-print-templates
  • EVIDENCE_DIR=... npm run test:printer-fallback-and-popup-verification
  • EVIDENCE_DIR=... npm run test:i18n-audit-remediations
  • npx ts-node --transpile-only -P tests/tsconfig.json tests/print-language-settings.test.ts
  • npm run test:decoupled-ui-locale
  • Visual inspection of generated receipt and popup PNGs via view_image
  • Final git status --short --untracked-files=all and transient-artifact cleanup
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ Configured ESLint could not run because the repository dependencies are absent (eslint: command not found).
✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR routes browser receipt labels and text direction through the shared PrintDocument language and catalog pipeline while retaining browser-specific wording and layout.

  • Resolves and preloads receipt-policy languages before browser printing and HTML downloads.
  • Sources browser labels from semantic document blocks and the canonical catalog resolver.
  • Extends browser and parity tests for Persian labels, direction, and unknown-language fallback.
  • Updates printing and internationalization documentation to describe the shared pipeline and merchant-template fallback boundaries.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code defect identified in the supported browser printing paths.

Current callers resolve nonempty validated language tuples, preload selected locale bundles where asynchronous loading is possible, and escape semantic labels before inserting them into receipt HTML; the updated tests cover supported RTL localization and catalog fallback.

Important Files Changed

Filename Overview
frontend/src/lib/printer/web-print.ts Replaces the browser-specific translator path with resolved print languages, semantic document labels, canonical fallback resolution, and document-derived direction.
frontend/src/app/(dashboard)/print-test/page.tsx Preloads resolved receipt-language bundles before synchronously generating downloadable test HTML.
tests/browser-receipts.test.ts Adds coverage for canonical Persian browser labels and English fallback for an unknown language.
tests/print-parity.test.ts Extends semantic parity checks to browser HTML catalog labels and fallback behavior.
docs/merchant-print-templates.md Clarifies shared label resolution versus structural template fallback and links the responsible implementation and tests.
docs/printers.md Documents the shared browser/WebUSB label resolver while preserving renderer-specific wording and layout differences.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Policy[Receipt language policy] --> Resolver[resolveBillPrintLanguages]
  Resolver --> Loader[ensurePrintLanguagesLoaded]
  Resolver --> Bridge[Frontend PrintDocument bridge]
  Loader --> Bridge
  Bridge --> Document[Semantic PrintDocument]
  Document --> Labels[Canonical label resolver]
  Labels --> HTML[Browser receipt HTML]
  Document --> Direction[Registry-derived direction]
  Direction --> HTML
Loading

Reviews (1): Last reviewed commit: "no-mistakes(document): Clarify receipt p..." | Re-trigger Greptile

@khaira777
khaira777 merged commit 43def4e into main Aug 23, 2026
13 checks passed
@khaira777
khaira777 deleted the fm/flocafe-480-browser-label-pipeline branch August 23, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(printing): align browser label resolution (web-print.ts) with document-label pipeline

1 participant