Skip to content

test(printing): establish cross-renderer receipt parity and regression contract #439

Closed

Description

@khaira777

Refs: #438
Depends on: None
Can parallel with: None (this should merge first)
Related: #437

Context

FloCafe prints receipts through several independent renderers (backend thermal.ts classic/compact, frontend receipt-encoder.ts classic/compact, browser HTML via web-print.ts, KOT encoders). They share no abstraction, so any future refactor can silently change — or drop — content. Issue #437 (Persian product names missing from printed bills) demonstrated how easily renderer behavior loses financial content without anyone noticing.

Before any architectural migration lands, we need a durable parity and regression harness that treats receipt semantic content (items, totals, payments, headers, banners, warnings) as a contract, independent of bytes or exact formatting.

Architectural Decisions Relevant to This Issue

  • Epic principle "No silent data loss": tests must pin down where content could vanish.
  • Epic principle "Not showing Items in Bill #437 relationship": Not showing Items in Bill #437 stays a standalone bug; this issue promotes its lesson into permanent coverage without encoding its conditional legacy behavior as an eternal invariant.
  • Tests assert semantics (an item name appears; the total value appears), never byte-for-byte snapshots.

Scope / What to do

Create tests/print-parity.test.ts (plus fixtures module) covering, for each renderer runnable without hardware:

  1. Backend ESC-POS (main/printers/thermal.ts): formatClassicReceipt, formatCompactReceipt → decode via existing escPosToText.
  2. Frontend ESC-POS (frontend/src/lib/printer/receipt-encoder.ts): buildClassicReceiptBytes, buildCompactReceiptBytes (use the established module-loading hook pattern from tests/printer.test.ts).
  3. Browser HTML (web-print.ts): generateBillHtml string assertions.

Fixture matrix (single shared fixture set):

  • 3+ items: Latin name, Persian-script name, long name needing truncation.
  • Addons with prices, special instructions, quantity > 1.
  • Bill with subtotal/discount/tax/total, two payment rows, table + customer + phone.
  • Reprint variant; paper widths 32, 42, 48 columns (verify actual profiles in main/printers/profiles.ts; include one narrower profile if present).

Assertions per renderer:

  • every item name present (or explicit warning recorded by that renderer's warning mechanism — see below);
  • totals/subtotal/discount values present;
  • payment method rows present;
  • REPRINT banner present on reprint variant only;
  • header business name present.

Legacy-behavior markers: today, renderers skip lines containing unsupported scripts and emit warnings (the #437-era contract). Encode these as clearly-marked LEGACY assertions with comments stating they will be deliberately updated when the semantic print model replaces silent skipping — they must not be treated as permanent architecture.

Detailed Requirements

  • Reuse fixture-building helpers; do not copy-paste per test file.
  • Semantic assertion helpers: expectContent(text, {items, totals, payments, banner}).
  • Keep runtime < ~10s; no network, no hardware, no DB required beyond what printer.test.ts already needs (none).
  • Export the fixture builder so later issues (PrintDocument parity) reuse it.

Compatibility / Migration

Test-only PR: no app code changes. If it exposes a real bug, file it separately rather than fixing here.

What NOT to do

  • Do NOT refactor renderers to make tests pass.
  • Do NOT add new translation keys.
  • Do NOT touch the fix/437-persian-receipt-items branch or absorb Not showing Items in Bill #437 scope.
  • Do NOT make byte-level golden snapshots.
  • Do NOT encode "Persian items appear iff arabicShaping" as a forever-invariant — mark those cases as legacy-renderer behavior.

Acceptance Criteria

  • Parity test runs all three renderer families against the shared fixture at widths 32/42/48.
  • Item/totals/payments/banner semantics asserted per renderer; truncation case asserted (long name truncated with ellipsis/prefix preserved).
  • Legacy skip-with-warning behavior pinned AND explicitly commented as non-permanent.
  • Test passes via repository-real commands; added to package.json scripts if a new command is introduced.
  • No application source files modified.

Verification

npx ts-node --transpile-only -P tests/tsconfig.json tests/print-parity.test.ts
npx ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts
npm run build

Documentation

Add a short header comment in the test file explaining the contract and pointing to the epic. Deeper docs belong to the documentation issue.

Metadata

Metadata

Assignees

Labels

area:backendarea:frontend

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions