Skip to content

fix(printer): preserve Persian ESC/POS receipt lines with shaping - #450

Closed
khaira777 wants to merge 14 commits into
mainfrom
fix/437-persian-receipt-items
Closed

khaira777 wants to merge 14 commits into
mainfrom
fix/437-persian-receipt-items

Conversation

@khaira777

@khaira777 khaira777 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix issue #437: receipt item lines silently disappear from desktop ESC/POS receipts when the global 'Arabic/Persian shaping support' printer setting is enabled. Threads the arabicShaping flag consistently through backend and frontend print paths, includes shaping in Orders download-preview requests, preserves warning reasons in warnings-toast classification, allows Persian formatting characters in shaping guards. Follow-up commit 67ab89c addresses two greptile review comments on PR #450: strip C0/DEL control bytes from raw() shaping output and reproduce encoder centering via centerCols at centered call sites. User instructed resolving greptile comments before merge; English receipts stay byte-identical.

What Changed

  • Adds a default-off Arabic/Persian shaping setting and threads it through receipt, tax-bill, KOT, and Orders preview ESC/POS paths.
  • Allows shaping-safe Persian formatting characters, strips control bytes, preserves width and centering, and provides localized reason-aware warnings for skipped lines.
  • Updates printer documentation and adds regression coverage for Persian output, narrow layouts, sanitization, centering, and ASCII byte stability.

Risk Assessment

✅ Low: No source-verifiable defects were found; shaping is gated, shaped output is sanitized and width-bounded, and ASCII-only output remains unchanged.

Testing

The focused suites and real preview route demonstrate Persian item preservation, shaping warnings, control-byte sanitization, centering, width limits, KOT coverage, and English byte identity; no full suite, lint, formatter, or static analysis was run, and a visual Orders-page screenshot was unavailable because no browser connection existed.

Evidence: Print preview E2E evidence

Rendered route-level preview showing Persian lines omitted with shaping disabled and emitted with arabicShaping: true.

[DB] Opening database at: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-preview-e2e-MolcLG/flo.db
[DB] Schema: v0 → v71
[DB] Triggering auto-backup before migrating v0 → v71...
[DB] Auto-backup before migrating v0 → v71 created at /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-preview-e2e-MolcLG/backups/flo-backup-2026-08-22T01-07-50-900Z-pre-v0-to-v71.db
[DB] Applying migration v1: initial_schema
[DB] Install defaults loaded; first-run setup pending
[DB] Migration v1 complete
[DB] Applying migration v2: hash_plaintext_pins
[DB] Migration v2 complete
[DB] Applying migration v3: cloud_identity_and_outbox
[DB] Migration v3 complete
[DB] Applying migration v4: add_notes_limits_settings
[DB] Migration v4 complete
[DB] Applying migration v5: add_print_logs_table
[DB] Migration v5 complete
[DB] Applying migration v6: add_loyalty_settings
[DB] Migration v6 complete
[DB] Applying migration v7: add_discount_settings
[DB] Migration v7 complete
[DB] Applying migration v8: add_loyalty_index
[DB] Migration v8 complete
[DB] Applying migration v9: add_sequences_table
[DB] Migration v9 complete
[DB] Applying migration v10: fix_sequences_composite_key
[DB] Migration v10 complete
[DB] Applying migration v11: first_run_setup_uses_welcome_form
[DB] Migration v11 complete
[DB] Applying migration v12: fix_table_integer_ids
[DB] Migration v12 complete
[DB] Applying migration v13: fix_null_table_ids
[DB] Migration v13 complete
[DB] Applying migration v14: simplify_loyalty_settings
[DB] Migration v14 complete
[DB] Applying migration v15: add_instagram_handle_setting
[DB] Migration v15 complete
[DB] Applying migration v16: add_terms_accepted_at_to_users
[DB] Migration v16 complete
[DB] Applying migration v17: add_held_orders_table
[DB] Migration v17 complete
[DB] Applying migration v18: fix_null_category_ids
[DB] Migration v18 complete
[DB] Applying migration v19: backfill_product_cb_percent_and_tags
[DB] Migration v19 complete
[DB] Applying migration v20: add_tables_is_active
[DB] Migration v20 complete
[DB] Applying migration v21: clear_legacy_loyalty_expiry
[DB] Migration v21 complete
[DB] Applying migration v22: add_customers_phone_digits
[DB] Migration v22 complete
[DB] Applying migration v23: normalize_customer_phones
[MIGRATION v23] normalized: 0, unparseable: 0
[MIGRATION v23] merged 0 duplicate customer(s)
[MIGRATION v23] verification: 0 customers, 0 still non-E.164
[DB] Migration v23 complete
[DB] Applying migration v24: normalize_customer_phones_retry
[MIGRATION v24] normalized: 0, unparseable: 0
[DB] Migration v24 complete
[DB] Applying migration v25: add_order_item_addons_table
[MIGRATION v25] backfilled addons for 0 order items (0 unparseable, skipped)
[DB] Migration v25 complete
[DB] Applying migration v26: add_kds_default_view
[DB] Migration v26 complete
[DB] Applying migration v27: add_station_printer_link_and_user_stations
[DB] Migration v27 complete
[DB] Applying migration v28: seed_telemetry_settings
[DB] Migration v28 complete
[DB] Applying migration v29: whatsapp_messaging
[DB] Migration v29 complete
[DB] Applying migration v30: drop_order_items_addons_json_column
[MIGRATION v30] backfilled 0 order_item(s) still missing a normalized addons snapshot
[MIGRATION v30] Dropped order_items.addons — order_item_addons is now the only place selected addons live.
[DB] Migration v30 complete
[DB] Applying migration v31: add_customers_tag_counts_column
[DB] Migration v31 complete
[DB] Applying migration v32: add_kds_and_kot_printing_toggles
[DB] Migration v32 complete
[DB] Applying migration v33: add_addon_groups_allow_multiple_quantities
[DB] Migration v33 complete
[DB] Applying migration v34: add_order_items_voided_at
[DB] Migration v34 complete
[DB] Applying migration v35: add_tax_pack_configuration_tables
[DB] Migration v35 complete
[DB] Applying migration v36: add_product_and_addon_tax_categories
[DB] Migration v36 complete
[DB] Applying migration v37: add_transaction_tax_snapshots_and_charge_categories
[DB] Migration v37 complete
[DB] Applying migration v38: register_bundled_tax_pack_versions
[DB] Migration v38 complete
[DB] Applying migration v39: add_users_tokens_valid_after
[DB] Migration v39 complete
[DB] Applying migration v40: v2_cloud_defaults_and_tax_toggle
[DB] Migration v40 complete
[DB] Applying migration v41: support_ticket_outbox
[DB] Migration v41 complete
[DB] Applying migration v42: add_global_cashback_percent
[DB] Migration v42 complete
[DB] Applying migration v43: telemetry_default_on_for_new_installs
[DB] Migration v43 complete
[DB] Applying migration v44: store_diagnostics_outbox
[DB] Migration v44 complete
[DB] Applying migration v45: add_performance_indexes_and_normalize_timestamps
[DB] Migration v45 complete
[DB] Applying migration v46: normalize_cloud_enabled_flags_to_01
[DB] Migration v46 complete
[DB] Applying migration v47: store_diagnostics_enabled_by_default
[DB] Migration v47 complete
[DB] Applying migration v48: deactivate_reusable_demo_credentials
[DB] Migration v48 complete
[DB] Applying migration v49: add_payment_idempotency_records
[DB] Migration v49 complete
[DB] Applying migration v50: add_order_idempotency_records
[DB] Migration v50 complete
[DB] Applying migration v51: enforce_global_payment_transaction_refs
[DB] Migration v51 complete
[DB] Applying migration v52: restore_method_scoped_transaction_refs
[DB] Migration v52 complete
[DB] Applying migration v53: scope_idempotency_records_to_user
[DB] Migration v53 complete
[DB] Applying migration v54: repair_retry_ownership_and_payment_reference_history
[DB] Migration v54 complete
[DB] Applying migration v55: durable_token_revocations
[DB] Migration v55 complete
[DB] Applying migration v56: persist_station_assignment_scope
[DB] Migration v56 complete
[DB] Applying migration v57: rename_gstin_to_generic_tax_registration_number
[DB] Migration v57 complete
[DB] Applying migration v58: configurable_manual_payment_methods
[DB] Migration v58 complete
[DB] Applying migration v59: split_checks_by_item_quantity
[DB] Migration v59 complete
[DB] Applying migration v60: seed_split_checks_disabled_setting
[DB] Migration v60 complete
[DB] Applying migration v61: seed_server_app_enabled_setting
[DB] Migration v61 complete
[DB] Applying migration v62: normalize_cloud_last_error
[DB] Migration v62 complete
[DB] Applying migration v63: seed_printer_trim_decimals_setting
[DB] Migration v63 complete
[DB] Applying migration v64: drop_unused_printer_usb_device_path
[DB] Migration v64 complete
[DB] Applying migration v65: seed_bill_content_visibility_settings
[DB] Migration v65 complete
[DB] Applying migration v66: seed_bill_template_settings
[DB] Migration v66 complete
[DB] Applying migration v67: persist_order_item_inventory_deductions
[DB] Migration v67 complete
[DB] Applying migration v68: add_invoice_numbering_settings
[DB] Migration v68 complete
[DB] Applying migration v69: installed_plugin_print_templates
[DB] Migration v69 complete
[DB] Applying migration v70: rename_waiter_role_to_server
[DB] Migration v70 complete
[DB] Applying migration v71: repair_durable_token_revocations
[DB] Migration v71 complete
[DB] integrity_check: ok
[DB] foreign_key_check: clean
[Print Bill] Request received { useUnicode: true, isReprint: false, preview: true }
[Print Bill] Resolved printer: undefined
[Print Bill] Preparing receipt { template: 'compact' }
[Printer] formatReceipt - template: compact
[Printer] formatReceipt - order: ORD-E2E-FA bill: INV-E2E-FA
[Printer] formatReceipt - items count: 1 cols: 42
[Print Bill] Request received { useUnicode: true, isReprint: false, preview: true }
[Print Bill] Resolved printer: undefined
[Print Bill] Preparing receipt { template: 'compact' }
[Printer] formatReceipt - template: compact
[Printer] formatReceipt - order: ORD-E2E-FA bill: INV-E2E-FA
[Printer] formatReceipt - items count: 1 cols: 42
Orders download-preview request contract:
{
  "billId": 1,
  "useUnicode": true,
  "isReprint": false,
  "preview": true,
  "arabicShaping": true
}

Response with arabicShaping=false (Persian line is skipped, English-safe output remains):
{
  "status": 200,
  "success": true,
  "preview": true,
  "columns": 42,
  "printer": {
    "id": 0,
    "name": "Default 80mm Preview"
  },
  "warnings": [
    {
      "field": "store name",
      "text": "کافه فلو تهران",
      "message": "Store name was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: کافه فلو تهران"
    },
    {
      "field": "receipt line",
      "text": "چای زعفرانی مخصوص       1    IRR250,000.00",
      "message": "Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: چای زعفرانی مخصوص       1    IRR250,000.00"
    }
  ],
  "text": "==========================================\nBill #: INV-E2E-FA\nDate: 1405/5/30 21:07:50\n------------------------------------------\nItem                    Qty         Amount\n------------------------------------------\n------------------------------------------\nSubtotal                     IRR250,000.00\nTOTAL                        IRR250,000.00\n==========================================\nThank you!\nPowered by FloPOS\nhttps://flopos.com"
}

Response with arabicShaping=true (same preview endpoint emits the Persian item line):
{
  "status": 200,
  "success": true,
  "preview": true,
  "columns": 42,
  "printer": {
    "id": 0,
    "name": "Default 80mm Preview"
  },
  "warnings": [],
  "text": "کافه فلو تهران\n==========================================\nBill #: INV-E2E-FA\nDate: 1405/5/30 21:07:50\n------------------------------------------\nItem                    Qty         Amount\n------------------------------------------\nچای زعفرانی مخصوص       1    IRR250,000.00\n------------------------------------------\nSubtotal                     IRR250,000.00\nTOTAL                        IRR250,000.00\n==========================================\nThank you!\nPowered by FloPOS\nhttps://flopos.com"
}
[DB] Database closed
Evidence: Printer test transcript

Focused printer transcript with rendered receipt output and shaping/control-byte/centering checks.


> [email protected] test:printer
> ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts && npm run test:printer-api

🧪 FloDesktop Printer Tests
============================================================

✅ Test 1: buildEscPos emits correct control bytes
   ✓ emits ESC @ (init)
   ✓ emits ESC a 1 (center)
   ✓ emits ESC a 0 (left)
   ✓ emits ESC E 1 (bold on)
   ✓ emits GS V 0 (full cut)
   ✓ emits LF after text lines
   ✓ contains visible "HEADER" text
   ✓ contains visible "plain line" text
   ✓ no stray {TOKEN} markers remain

✅ Test 1b: Unsupported receipt text is skipped with a warning
   ✓ skips unsupported Arabic line
   ✓ keeps the rest of the receipt printable
   ✓ reports the skipped store name

✅ Test 1b2: Arabic shaping capability gate
   ✓ frontend safePrinterText skips Persian by default
   ✓ frontend safePrinterText emits Persian with shaping on
   ✓ frontend safePrinterText still skips mixed-script line with shaping on
   ✓ frontend shaping accepts Persian ZWNJ
   ✓ frontend shaping accepts Persian ZWJ
   ✓ frontend shaping accepts Persian RLM
   ✓ frontend shaping accepts Persian ellipsis
   ✓ frontend shaping bounds raw text to the layout width
   ✓ isArabicShapingSafeLine accepts ASCII+Persian
   ✓ isArabicShapingSafeLine rejects other non-ASCII
   ✓ without flag, Persian line is skipped
   ✓ without flag, warning names Arabic shaping as the cause
   ✓ with flag, Persian line is emitted
   ✓ with flag, pure Persian line emits no warning
   ✓ with flag, Persian line with Unicode currency is emitted
   ✓ with flag, Persian line with Unicode currency emits no warning
   ✓ backend shaping accepts Persian ZWNJ
   ✓ backend shaping accepts Persian ZWJ
   ✓ backend shaping accepts Persian RLM
   ✓ backend shaping accepts Persian ellipsis
   ✓ backend shaping strips embedded printer-control bytes
   ✓ backend shaping still prints sanitized Persian text
   ✓ backend shaping emits no warning for sanitized text
   ✓ ASCII output stays byte-identical with shaping enabled
   ✓ mixed Persian+Latin line is skipped even with flag
   ✓ mixed-script line still emits a warning
   ✓ mixed Arabic warnings show the shaping remedy
[Printer] formatReceipt - template: compact
[Printer] formatReceipt - order: ORD-20260421-0001 bill: INV-20260421-0001
[Printer] formatReceipt - items count: 2 cols: 48
   ✓ formatReceipt without flag skips Persian business name
   ✓ formatReceipt without flag skips Persian item name
   ✓ formatReceipt without flag retains English item name
   ✓ formatReceipt without flag retains financial lines
   ✓ formatReceipt without flag emits precise Arabic shaping warnings
[Printer] formatReceipt - template: compact
[Printer] formatReceipt - order: ORD-20260421-0001 bill: INV-20260421-0001
[Printer] formatReceipt - items count: 2 cols: 48
   ✓ formatReceipt with arabicShaping prints the Persian business name
   ✓ formatReceipt with arabicShaping prints the Persian item name
   ✓ formatReceipt with arabicShaping prints Persian addons
   ✓ formatReceipt with arabicShaping prints Persian notes
   ✓ formatReceipt with arabicShaping emits no unsupported warning
   ✓ formatKOT without flag skips Persian station name
   ✓ formatKOT without flag skips Persian item name
   ✓ formatKOT without flag retains English item name
   ✓ formatKOT without flag emits precise Arabic shaping warnings
   ✓ formatKOT with arabicShaping prints Persian station name
   ✓ formatKOT with arabicShaping prints Persian item name
   ✓ formatKOT with arabicShaping prints Persian addons
   ✓ formatKOT with arabicShaping prints Persian notes
   ✓ formatKOT with arabicShaping emits no unsupported warning
   ✓ backend shaping bounds raw double-width lines
[Printer] formatReceipt - template: compact
[Printer] formatReceipt - order: ORD-20260421-0001 bill: INV-20260421-0001
[Printer] formatReceipt - items count: 1 cols: 32
   ✓ shaped compact receipt stays within 32 columns
   ✓ shaped compact receipt emits no width warnings
[Printer] formatReceipt - template: classic
[Printer] formatReceipt - order: ORD-20260421-0001 bill: INV-20260421-0001
[Printer] formatReceipt - items count: 1 cols: 32
   ✓ shaped classic receipt stays within 32 columns
   ✓ shaped classic receipt emits no width warnings
   ✓ shaped KOT stays within 32 columns
   ✓ shaped KOT emits no width warnings

✅ Test 1c: ESC/POS output can be previewed without a printer
   ✓ paperless preview keeps receipt text
   ✓ paperless preview strips ESC/POS commands

✅ Test 2: Compact receipt (80mm, 48 cols)
[Printer] formatReceipt - template: compact
[Printer] formatReceipt - order: ORD-20260421-0001 bill: INV-20260421-0001
[Printer] formatReceipt - items count: 3 cols: 48
   ✓ renders business name
   ✓ renders bill number
   ✓ renders Cheeseburger row
   ✓ renders addon "Extra Cheese"
   ✓ renders addon "Bacon"
   ✓ renders special instruction
   ✓ renders subtotal ₹925.00
   ✓ renders discount line with negative sign
   ✓ renders tax total ₹40.00
   ✓ renders TOTAL with grand amount
   ✓ renders Cash payment
   ✓ renders UPI payment
   ✓ renders tax registration number
   ✓ renders non-configurable FloPOS footer
   ✓ long product name is truncated to fit
   ✓ ends with cut byte sequence
   ✓ item row columns are aligned (no smashed qty)
   ✓ item row right-edge total lines up at col 48
   ✓ item table has no redundant tax column

   — Rendered compact (80mm) —
────────────────────────────────────────────────
Flo Test Cafe
================================================
Bill #: INV-20260421-0001
Date: 4/21/2026 6:30:00 AM
Table: T3
------------------------------------------------
Item                              Qty     Amount
------------------------------------------------
Cheeseburger                      2      ₹540.00
  + Extra Cheese                          ₹20.00
  + Bacon                                 ₹20.00
  Note: No onions
Fresh Lime Soda                   1       ₹70.00
Very Long Product Name That Shou..3      ₹315.00
------------------------------------------------
Subtotal                                 ₹925.00
Discount                               -  ₹15.00
Tax                                       ₹40.00
TOTAL                                    ₹950.00
------------------------------------------------
Cash                                     ₹500.00
UPI                                      ₹450.00
================================================
42 MG Road, Bengaluru 560001
Ph: +91 98765 43210
Tax ID: TAXID-0001
Thank you!
Powered by FloPOS
https://flopos.com
────────────────────────────────────────────────

✅ Test 3: Compact receipt on 58mm paper (32 cols)
[Printer] formatReceipt - template: compact
[Printer] formatReceipt - order: ORD-20260421-0001 bill: INV-20260421-0001
[Printer] formatReceipt - items count: 3 cols: 32
   ✓ still renders business name
   ✓ still renders TOTAL
   ✓ no content line exceeds 32 cols

   — Rendered compact (58mm) —
────────────────────────────────
Flo Test Cafe
================================
Bill #: INV-20260421-0001
Date: 4/21/2026 6:30:00 AM
Table: T3
--------------------------------
Item              Qty     Amount
--------------------------------
Cheeseburger      2      ₹540.00
  + Extra Cheese          ₹20.00
  + Bacon                 ₹20.00
  Note: No onions
Fresh Lime Soda   1       ₹70.00
Very Long Produc..3      ₹315.00
--------------------------------
Subtotal                 ₹925.00
Discount               -  ₹15.00
Tax                       ₹40.00
TOTAL                    ₹950.00
--------------------------------
Cash                     ₹500.00
UPI                      ₹450.00
================================
42 MG Road, Ben

... [29951 bytes truncated] ...

zed: 0, unparseable: 0
[MIGRATION v23] merged 0 duplicate customer(s)
[MIGRATION v23] verification: 0 customers, 0 still non-E.164
[DB] Migration v23 complete
[DB] Applying migration v24: normalize_customer_phones_retry
[MIGRATION v24] normalized: 0, unparseable: 0
[DB] Migration v24 complete
[DB] Applying migration v25: add_order_item_addons_table
[MIGRATION v25] backfilled addons for 0 order items (0 unparseable, skipped)
[DB] Migration v25 complete
[DB] Applying migration v26: add_kds_default_view
[DB] Migration v26 complete
[DB] Applying migration v27: add_station_printer_link_and_user_stations
[DB] Migration v27 complete
[DB] Applying migration v28: seed_telemetry_settings
[DB] Migration v28 complete
[DB] Applying migration v29: whatsapp_messaging
[DB] Migration v29 complete
[DB] Applying migration v30: drop_order_items_addons_json_column
[MIGRATION v30] backfilled 0 order_item(s) still missing a normalized addons snapshot
[MIGRATION v30] Dropped order_items.addons — order_item_addons is now the only place selected addons live.
[DB] Migration v30 complete
[DB] Applying migration v31: add_customers_tag_counts_column
[DB] Migration v31 complete
[DB] Applying migration v32: add_kds_and_kot_printing_toggles
[DB] Migration v32 complete
[DB] Applying migration v33: add_addon_groups_allow_multiple_quantities
[DB] Migration v33 complete
[DB] Applying migration v34: add_order_items_voided_at
[DB] Migration v34 complete
[DB] Applying migration v35: add_tax_pack_configuration_tables
[DB] Migration v35 complete
[DB] Applying migration v36: add_product_and_addon_tax_categories
[DB] Migration v36 complete
[DB] Applying migration v37: add_transaction_tax_snapshots_and_charge_categories
[DB] Migration v37 complete
[DB] Applying migration v38: register_bundled_tax_pack_versions
[DB] Migration v38 complete
[DB] Applying migration v39: add_users_tokens_valid_after
[DB] Migration v39 complete
[DB] Applying migration v40: v2_cloud_defaults_and_tax_toggle
[DB] Migration v40 complete
[DB] Applying migration v41: support_ticket_outbox
[DB] Migration v41 complete
[DB] Applying migration v42: add_global_cashback_percent
[DB] Migration v42 complete
[DB] Applying migration v43: telemetry_default_on_for_new_installs
[DB] Migration v43 complete
[DB] Applying migration v44: store_diagnostics_outbox
[DB] Migration v44 complete
[DB] Applying migration v45: add_performance_indexes_and_normalize_timestamps
[DB] Migration v45 complete
[DB] Applying migration v46: normalize_cloud_enabled_flags_to_01
[DB] Migration v46 complete
[DB] Applying migration v47: store_diagnostics_enabled_by_default
[DB] Migration v47 complete
[DB] Applying migration v48: deactivate_reusable_demo_credentials
[DB] Migration v48 complete
[DB] Applying migration v49: add_payment_idempotency_records
[DB] Migration v49 complete
[DB] Applying migration v50: add_order_idempotency_records
[DB] Migration v50 complete
[DB] Applying migration v51: enforce_global_payment_transaction_refs
[DB] Migration v51 complete
[DB] Applying migration v52: restore_method_scoped_transaction_refs
[DB] Migration v52 complete
[DB] Applying migration v53: scope_idempotency_records_to_user
[DB] Migration v53 complete
[DB] Applying migration v54: repair_retry_ownership_and_payment_reference_history
[DB] Migration v54 complete
[DB] Applying migration v55: durable_token_revocations
[DB] Migration v55 complete
[DB] Applying migration v56: persist_station_assignment_scope
[DB] Migration v56 complete
[DB] Applying migration v57: rename_gstin_to_generic_tax_registration_number
[DB] Migration v57 complete
[DB] Applying migration v58: configurable_manual_payment_methods
[DB] Migration v58 complete
[DB] Applying migration v59: split_checks_by_item_quantity
[DB] Migration v59 complete
[DB] Applying migration v60: seed_split_checks_disabled_setting
[DB] Migration v60 complete
[DB] Applying migration v61: seed_server_app_enabled_setting
[DB] Migration v61 complete
[DB] Applying migration v62: normalize_cloud_last_error
[DB] Migration v62 complete
[DB] Applying migration v63: seed_printer_trim_decimals_setting
[DB] Migration v63 complete
[DB] Applying migration v64: drop_unused_printer_usb_device_path
[DB] Migration v64 complete
[DB] Applying migration v65: seed_bill_content_visibility_settings
[DB] Migration v65 complete
[DB] Applying migration v66: seed_bill_template_settings
[DB] Migration v66 complete
[DB] Applying migration v67: persist_order_item_inventory_deductions
[DB] Migration v67 complete
[DB] Applying migration v68: add_invoice_numbering_settings
[DB] Migration v68 complete
[DB] Applying migration v69: installed_plugin_print_templates
[DB] Migration v69 complete
[DB] Applying migration v70: rename_waiter_role_to_server
[DB] Migration v70 complete
[DB] Applying migration v71: repair_durable_token_revocations
[DB] Migration v71 complete
[DB] integrity_check: ok
[DB] foreign_key_check: clean
Printer API Tests (supertest)
==================================================

Test 1: first printer becomes default
  ✓ creating the first printer returns 201 (got 201)
  ✓ the first printer is automatically the default
  ✓ exactly one default printer exists

Test 2: a second default replaces the first
  ✓ creating a second printer returns 201 (got 201)
  ✓ the explicitly-default printer is default
  ✓ exactly one default printer remains after a new default is created

Test 2b: concurrent default changes leave exactly one default
  ✓ concurrent set-default requests leave exactly one default

Test 3: PUT validates connection_type and port
  ✓ invalid connection_type returns 400 (got 400)
  ✓ invalid port 0 returns 400 (got 400)
  ✓ invalid port 65536 returns 400 (got 400)
  ✓ invalid port -1 returns 400 (got 400)
  ✓ invalid port 1.5 returns 400 (got 400)
  ✓ invalid port "9100" returns 400 (got 400)
  ✓ non-boolean is_default returns 400 (got 400)

Test 4: PUT distinguishes omitted from explicit fields
  ✓ updating only the name returns 200 (got 200)
  ✓ the explicit name is applied
  ✓ omitted connection_type keeps the existing value
  ✓ omitted port keeps the existing value
  ✓ explicit null ip_address is accepted (got 200)
  ✓ explicit null ip_address clears the stored value

Test 5: unsetting the default picks a replacement
  ✓ unsetting the default returns 200 (got 200)
  ✓ a replacement default is chosen
  ✓ the replacement is a different printer

Test 6: deleting the default printer
  ✓ deleting the default with others returns 200 (got 200)
  ✓ a replacement default is chosen after deletion
  ✓ one printer remains and is default
  ✓ deleting the only default printer is refused (got 409)

Test 7: kitchen stations validate printer identifiers
  ✓ create with empty printer_id returns 400 (got 400)
  ✓ create with unknown printer_id returns 400 (got 400)
  ✓ create with a valid printer_id returns 201 (got 201)
  ✓ update with empty printer_id returns 400 (got 400)
  ✓ update with explicit null printer_id clears the assignment (got 200)
  ✓ the cleared station has a null printer_id

Test 8: print-bill preview fallback when 0 printers exist
[Print Bill] Request received { useUnicode: false, isReprint: false, preview: true }
[Print Bill] Resolved printer: undefined
[Print Bill] Preparing receipt { template: 'classic' }
[Printer] formatReceipt - template: classic
[Printer] formatReceipt - order: ORD-PREVIEW-1 bill: BILL-PREVIEW-1
[Printer] formatReceipt - items count: 1 cols: 42
  ✓ preview generation with 0 printers succeeds (got 200)
  ✓ preview generation returns valid 80mm columns (got 42)
  ✓ preview contains formatted receipt text
[Print Bill] Request received { useUnicode: false, isReprint: false, preview: false }
[Print Bill] Resolved printer: undefined
[Print Bill] Error: No default printer
  ✓ direct hardware print with 0 printers fails with 400 (got 400)
  ✓ proper error message returned
[Printer] printReceipt called, template: classic useUnicode: false isReprint: false
[Printer] No printer configured
  ✓ direct printReceipt without printers fails fast

==================================================
39/39 passed, 0 failed
[DB] Database closed
Evidence: Bill print API transcript

Source: Bill print API transcript (local file: /Users/gurkiratkhaira/.no-mistakes/evidence/01M0KADV9T5AMPSAXYEF3G2J0Z/bills-print-api-transcript.txt)

Bill-print API transcript covering the shaping override.
- Outcome: ⚠️ 1 warning across 1 run (4m39s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed (5) ✅
  • 🚨 frontend/src/lib/printer/receipt-encoder.ts:266 - The intent requires “reproduce encoder centering via centerCols at centered call sites,” but the classic encoder keeps alignment centered after line 259 and the changed Persian-capable calls at lines 266 and 270 omit centerCols. With shaping enabled, safePrinterText uses raw(), so table/customer lines become left-aligned instead of preserving the existing centered output. Pass the appropriate centerCols value or confirm the intentional alignment change.
  • 🚨 main/printers/thermal.ts:1697 - The backend shaping guard treats C0/DEL bytes as acceptable ASCII, so a Persian item such as چای\u001b p... passes arabicOnly and is emitted by Buffer.from at line 1742. The desktop print route therefore still allows embedded ESC/POS control commands when shaping is enabled, despite the follow-up sanitizing the frontend raw() path. Sanitize or reject C0/DEL bytes at buildEscPos before emission so receipts, plugins, and KOTs share the boundary.
  • ⚠️ frontend/src/lib/printer/warnings.ts:103 - raw() is called without a layout length, so it bypasses the encoder's wrapping. Several newly shape-enabled fields remain unbounded, such as Table: ${order.table.name} and the classic customer name; a long Persian value is emitted as an over-width physical line without warning, whereas the same path with shaping disabled goes through enc.text() and wraps. Preserve the encoder's width contract by wrapping or bounding shape-safe values at the shared helper/call sites.

🔧 Fix: Fixed printer control-byte sanitization and shaped-line width bounds
1 error still open:

  • 🚨 frontend/src/lib/printer/warnings.ts:121 - safePrinterText manually adds centering spaces, then calls raw() without a layout length. ReceiptPrinterEncoder v3 treats the raw segment as zero-width and adds another half-line of centering on flush, so shaped centered headers and footer lines can overflow or appear far right. Pass the raw display width or disable the second centering at this shared boundary; see alignment behavior.

🔧 Fix: Disabled duplicate centering around shaped raw printer segments
1 warning still open:

  • ⚠️ frontend/src/lib/printer/kot-encoder.ts:94 - For a long add-on name, truncate(addonText, cols - 4) can produce cols - 4 characters, and the five-character + prefix makes the line cols + 1 columns wide. With Arabic shaping enabled, safePrinterText sends this line through raw() without a maxCols bound, so the KOT can emit an over-width physical line instead of the wrapping used when shaping is disabled. Use cols - 5 or pass an explicit maxCols: cols bound.

🔧 Fix: Bound KOT add-on truncation to printer width
1 warning still open:

  • ⚠️ main/printers/thermal.ts:1697 - When arabicShaping is enabled, the new arabicOnly branch at line 1697 emits unbounded backend lines. For example, a 32-column KOT with a Persian product name longer than 32 columns reaches formatKOT line 1554 and is written in full at line 1744, producing an over-width ticket without warning; compact receipts similarly leave long Persian store/customer/table fields unbounded. Bound or wrap these shaped fields before emission, matching the frontend width contract.

🔧 Fix: Bound shaped backend printer lines to column widths
2 issues (1 error, 1 warning) still open:

  • 🚨 main/printers/thermal.ts:1691 - The intent requires “English receipts stay byte-identical,” but line 1691 removes every C0/DEL byte from every backend line before the Arabic-shaping branch. An ASCII note such as No onions\nNo garlic is changed even with shaping disabled. Restrict sanitization to shaped output while preserving non-shaped ASCII bytes.
  • ⚠️ frontend/src/lib/printer/warnings-toast.ts:43 - Arabic warnings containing another unsupported character, such as کافه Café, are classified as generic because isArabicShapingSafeLine returns false, despite the warning reason identifying Persian/Arabic text. Classify using hasArabicScript or the warning reason so the shaping/browser remedy remains visible.

🔧 Fix: Preserve ASCII bytes and classify mixed Arabic warnings
✅ Re-checked - no issues remain.

⚠️ **Test** - 1 warning
  • ⚠️ No Orders-page screenshot could be captured because the browser runtime reported no available browser connections. Route-level preview evidence and rendered receipt text were collected instead.
  • npm run test:printer
  • npm run test:bills-print-api
  • Temporary-database supertest check of POST /api/printers/print-bill with preview: true and arabicShaping: false/true
  • Captured rendered ESC/POS receipt previews and warning payloads
  • Attempted read-only browser discovery; no browser connections were available
  • git status --short --untracked-files=all
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…nes (#437)

ESC/POS encoders silently skipped every receipt line containing
Persian/Arabic script unless the printer profile declared
arabicShaping, and nothing exposed that flag — so merchants with
Persian product names got bills with no items at all.

Add a renderer-global 'printerArabicShaping' setting that threads
through the same paths as the existing useUnicode option:

- pos-settings store + Settings → Printing toggle (en/fa/es/pt)
- frontend encoders: safePrinterText emits pure ASCII+Arabic lines
  when shaping is enabled; other non-ASCII scripts stay blocked
- backend print-bill/print-kot accept an arabicShaping body field;
  an explicit boolean overrides the profile default, absence keeps it
- warning toast now localized (printWarnings.* namespace) naming the
  new setting when Persian/Arabic lines were dropped

Default stays off so generic printers never receive unshaped text.
@greptile-apps

greptile-apps Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR consistently threads the Arabic/Persian shaping preference through frontend and backend print paths and adds regression coverage for shaped receipt output. The follow-up changes also sanitize control characters and preserve centered alignment when shaped text is emitted as raw UTF-8.

  • Adds and persists the printer shaping setting across receipt, KOT, tax-bill, and preview flows.
  • Applies explicit request overrides in backend thermal-print preparation.
  • Expands shaping guards, localized warning handling, documentation, and regression tests.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
frontend/src/lib/printer/warnings.ts Safely emits eligible shaped text as UTF-8 while stripping printer controls and explicitly accounting for centered alignment.
frontend/src/lib/printer/receipt-encoder.ts Threads the shaping preference through receipt templates and supplies the appropriate centering widths for shaped store names.
frontend/src/lib/printer/kot-encoder.ts Threads Arabic/Persian shaping through frontend kitchen-ticket text encoding.
frontend/src/lib/printer/tax-bill-encoder.ts Applies shaping support to tax-bill output, including centered business-name rendering.
frontend/src/hooks/usePrinter.ts Propagates the persisted shaping preference through hardware and local frontend print paths.
main/printers/thermal.ts Applies explicit shaping overrides and allows supported Persian formatting characters in backend ESC/POS generation.
main/routes/printers.ts Accepts boolean shaping overrides on bill and KOT print requests and passes them to thermal printing.
tests/printer.test.ts Adds regression coverage for shaped UTF-8 output, formatting controls, mixed-script rejection, sanitization, and alignment.
tests/bills-print-api.test.ts Verifies that request-level shaping configuration overrides the printer profile during receipt preparation.

Reviews (2): Last reviewed commit: "no-mistakes(document): Documented Arabic..." | Re-trigger Greptile

Comment thread frontend/src/lib/printer/warnings.ts Resolved
Comment thread frontend/src/lib/printer/warnings.ts Resolved
@khaira777 khaira777 changed the title fix(printer): thread arabicShaping flag to prevent Persian item lines from silently disappearing fix(printer): preserve Persian ESC/POS receipt lines with shaping Aug 22, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

This work continues in #452, which carries the same fix plus all review fixes (control-byte sanitization, shaped-line width bounds, centralized centering preserved inside safePrinterText, mixed-script warning classification, ASCII byte stability) and a strict-typecheck build repair for the TS2722 failure that broke the last CI runs on this branch. Checks are green there (12 passed / 0 failed / 1 skipped), so closing this PR as superseded.

@khaira777 khaira777 closed this Aug 22, 2026
khaira777 added a commit that referenced this pull request Aug 22, 2026
…print paths (#452)

* fix(printers): global Arabic/Persian shaping setting restores item lines (#437)

ESC/POS encoders silently skipped every receipt line containing
Persian/Arabic script unless the printer profile declared
arabicShaping, and nothing exposed that flag — so merchants with
Persian product names got bills with no items at all.

Add a renderer-global 'printerArabicShaping' setting that threads
through the same paths as the existing useUnicode option:

- pos-settings store + Settings → Printing toggle (en/fa/es/pt)
- frontend encoders: safePrinterText emits pure ASCII+Arabic lines
  when shaping is enabled; other non-ASCII scripts stay blocked
- backend print-bill/print-kot accept an arabicShaping body field;
  an explicit boolean overrides the profile default, absence keeps it
- warning toast now localized (printWarnings.* namespace) naming the
  new setting when Persian/Arabic lines were dropped

Default stays off so generic printers never receive unshaped text.

* no-mistakes(review): Preserve Persian ESC/POS items with Unicode currency

* no-mistakes(review): Allow Persian formatting controls in printer shaping guards

* no-mistakes(review): Fix frontend shaping propagation, previews, and warning reasons

* no-mistakes(review): Allow Persian RLM and ellipsis in shaping guards

* no-mistakes(test): Use enc.raw() for Persian UTF-8 bytes in safePrinterText shaping path

* no-mistakes(document): Fixed API docs missing arabicShaping param and ESLint any-cast errors

* fix(printers): sanitize controls and center shaped Persian lines

Addresses greptile P1/P2 on #450: raw() shaping output now strips
C0/DEL control bytes (preventing printer-command injection via labels)
and reproduces encoder centering via an explicit column budget at
centered call sites, so double-width Persian business names keep their
heading padding.

* no-mistakes(review): Fixed printer control-byte sanitization and shaped-line width bounds

* no-mistakes(review): Disabled duplicate centering around shaped raw printer segments

* no-mistakes(review): Bound KOT add-on truncation to printer width

* no-mistakes(review): Bound shaped backend printer lines to column widths

* no-mistakes(review): Preserve ASCII bytes and classify mixed Arabic warnings

* no-mistakes(document): Documented Arabic/Persian printer shaping support

* fix(printer): satisfy strict null check on shaped centering align calls

The cancelled review pipeline left safePrinterText calling the optional
align() method without optional chaining, so Next.js typecheck failed
with TS2722 at warnings.ts:122 and :127 and broke both the Lint & Build
and Playwright CI jobs. centerRawLine already guarantees align exists;
optional chaining keeps runtime behavior identical.
@khaira777
khaira777 deleted the fix/437-persian-receipt-items branch August 22, 2026 05:31
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.

1 participant