Repository navigation
feat(print): add 76mm impact printer support - #1502
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoAdd 76mm impact printing and capability-based printer onboarding
AI Description
Diagram
High-Level Assessment
Files changed (50)
|
Code Review by Qodo
1.
|
…1502: 1. **Core Test Suite (Shard 1/4) - `test:print-labels`**: - **Invariant**: `isThermalTextRepresentable`, `selectThermalCodePage`, and `thermalTextFallback` must evaluate native codepage representability (plus single-diacritic `LATIN_ASCII_MAP` fallback when no native codepage encodes the string), while extended Latin fallback folding (`LATIN_EXTENDED_ASCII_MAP` and Unicode NFD `\p{Diacritic}` stripping on `\p{Script=Latin}\p{Mark}*`) must only run inside `normalizeThermalText` when raster fallback does not intercept the text and no native codepage can encode it. - **Fix**: Kept `transliterateThermalText` in `shared/print/thermal-capabilities.ts` scoped to native codepage checks and `LATIN_ASCII_MAP`, updated `thermalTextFallback` to check `transliterateThermalText` so explicit English/ASCII financial fallbacks (e.g. `'Tổng cộng'` -> `'TOTAL'`) and raster triggers on thermal profiles are preserved, and applied extended Latin / NFD diacritic folding in `normalizeThermalText`. Updated the post-normalization `isThermalTextRepresentable` assertions in `tests/impact-printer-support.test.ts`. 2. **Core Test Suite (Shard 4/4) - `test:backup`, Playwright E2E (Shard 1/4), End-to-End Playwright Tests, and Required Checks Gate**: - **Invariant**: Every test fixture and assertion expecting the current latest database schema version must match `getCurrentSchemaVersion()` (`125` after migration `125` `add_printer_profile_id`). - **Fix**: Updated `tests/backup-restore-production.test.ts` (expected migrated schema version `124` -> `125`) and `frontend/e2e/database-export-import.spec.ts` (`contaminatedPayload` `schema_version` `'124'` -> `'125'` so `/api/db/import` does not flag a version mismatch requiring a Master PIN). Verified locally with `npm run test:print-labels`, `npm run test:impact-printer`, `npm run test:thermal-capabilities`, `npm run test:receipt-column-oracle`, `npm run test:backup`, `npm run test:release-regressions`, `npm run test:upgrade-path`, `npm run test:schema-health`, `npm run test:migration-registry`, `npm run lint`, `npm run build`, `npm run build:frontend`, and Playwright E2E (`e2e/database-export-import.spec.ts` and `e2e/qa-settings-receipts-printers.spec.ts`)
…1502: 1. **Core Test Suite (Shard 1/4) - `test:print-labels`**: - **Invariant**: `isThermalTextRepresentable`, `selectThermalCodePage`, and `thermalTextFallback` must evaluate native codepage representability (plus single-diacritic `LATIN_ASCII_MAP` fallback when no native codepage encodes the string), while extended Latin fallback folding (`LATIN_EXTENDED_ASCII_MAP` and Unicode NFD `\p{Diacritic}` stripping on `\p{Script=Latin}\p{Mark}*`) must only run inside `normalizeThermalText` when raster fallback does not intercept the text and no native codepage can encode it. - **Fix**: Kept `transliterateThermalText` in `shared/print/thermal-capabilities.ts` scoped to native codepage checks and `LATIN_ASCII_MAP`, updated `thermalTextFallback` to check `transliterateThermalText` so explicit English/ASCII financial fallbacks (e.g. `'Tổng cộng'` -> `'TOTAL'`) and raster triggers on thermal profiles are preserved, and applied extended Latin / NFD diacritic folding in `normalizeThermalText`. Updated the post-normalization `isThermalTextRepresentable` assertions in `tests/impact-printer-support.test.ts`. 2. **Core Test Suite (Shard 4/4) - `test:backup`, Playwright E2E (Shard 1/4), End-to-End Playwright Tests, and Required Checks Gate**: - **Invariant**: Every test fixture and assertion expecting the current latest database schema version must match `getCurrentSchemaVersion()` (`125` after migration `125` `add_printer_profile_id`). - **Fix**: Updated `tests/backup-restore-production.test.ts` (expected migrated schema version `124` -> `125`) and `frontend/e2e/database-export-import.spec.ts` (`contaminatedPayload` `schema_version` `'124'` -> `'125'` so `/api/db/import` does not flag a version mismatch requiring a Master PIN). Verified locally with `npm run test:print-labels`, `npm run test:impact-printer`, `npm run test:thermal-capabilities`, `npm run test:receipt-column-oracle`, `npm run test:backup`, `npm run test:release-regressions`, `npm run test:upgrade-path`, `npm run test:schema-health`, `npm run test:migration-registry`, `npm run lint`, `npm run build`, `npm run build:frontend`, and Playwright E2E (`e2e/database-export-import.spec.ts` and `e2e/qa-settings-receipts-printers.spec.ts`)
…nce with implementation
1af4228 to
b2e2528
Compare
Intent
Implement native 76mm impact printer support (
escpos-impact-76,cols-32,raster.enabled: false, partial cut, 64mm printable width), extended Latin fallback transliteration, raster capability guards for receipt logos and QR codes, OS printer compatibility classification, database migration 125 (printers.profile_id), and Settings -> Printers profile onboarding across all 32 supported locales.Fixes #1481
What Changed
escpos-impact-7632-column printer profile (raster.enabled: false,cutMode: 'partial', 64mm printable width) and narrowedepson-tm-seriesmatching soTM-U*impact,TM-L*label, and non-TM Epson queues are not misclassified as 48-column thermal raster printers.GS v 0raster logo andGS ( kQR code emissions behindrasterCapabilityEnabled(capabilities)across receipt, merchant copy, payment ticket, and browser/WebUSB encoders, and expandednormalizeThermalTextfallback transliteration with extended Latin foldings and Unicode NFD diacritic stripping on Latin characters.125(printers.profile_id), backend profile validation/resolution and OS printer compatibility classification (escpos_thermal|escpos_impact|driver_only), and Settings -> Printers UI for explicit profile selection, driver-only warnings with 1-click Browser print switching, and localized strings across all 32 supported locales.Risk Assessment
✅ Low: The 76mm impact printer profile, Latin fallback transliteration, logo/QR capability guards (including WebUSB, preview, and native extended-Latin wrapping paths), OS printer compatibility classification, database migration 125, settings UI onboarding, translations, documentation, and tests are well-bounded and conform to the stated intent without regressions.
Testing
Exercised the focused impact-printer test suite, receipt column oracle, database upgrade-path migration 125 checks, script-coverage, i18n parity across all locales, documentation checks, and the live Playwright Chromium E2E flow for Settings -> Printers (e2e/qa-settings-receipts-printers.spec.ts), capturing visual screenshots of detected impact anddriver_onlyprinters, the 1-click Browser Print switch, the 76mm impact profile form, and the configured impact printer card alongside live API and ESC/POS byte verification artifacts. All checks and live scenarios passed.Evidence: Live API & ESC/POS verification payload (POST/PUT /api/printers profile_id persistence + 400 validation, /api/printers/detect compatibility classification, and 76mm impact receipt/payment-ticket ESC/POS byte verification)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (2) ✅
main/printers/thermal.ts:2560- Gating{RAW_BYTES:...}logo emission onrasterCapabilityEnabled(capabilities)inmain/printers/document-classic.ts:529,main/printers/document-compact.ts:243, andfrontend/src/lib/printer/receipt-encoder.ts:640,1170causesnativeFallbackCapabilities(...)(which clones a thermal printer's capabilities withraster.enabled: falseto force text transliteration) to strip theGS v 0logo in the pre-raster native pass.rasterizeReceiptIfEnabled(main/printers/thermal.ts:2560) was updated to checkresult.rasterSelected || document.lines.some((line) => line.startsWith('{RAW_BYTES:')), but its sibling paths still drop the logo on raster-capable thermal printers:main/printers/thermal.ts:2444(rasterizePrintDocumentForWebUsb): returnsrasterSelected: result.rasterSelectedwithout|| lines.some((line) => line.startsWith('{RAW_BYTES:')). Whenfrontend/src/hooks/usePrinter.ts:498-569prints a bill with a logo via WebUSB in Electron (useElectronRaster === true) and all text lines are representable in the printer's native codepage (result.rasterSelected === false),buildClassicReceiptBytes/buildCompactReceiptBytes(frontend/src/lib/printer/receipt-encoder.ts:640,1170) runs withnativeFallbackCapabilities(webusbCapabilities)(raster.enabled: false) and omits the logo frombytes, andusePrinter.ts:561discardsrasterResult.databecauserasterResult.rasterSelectedisfalse, sending a logo-less receipt to the WebUSB thermal printer.main/printers/thermal.ts:2106(prepareReceipt, consumed byPOST /api/printers/print-billwithpreview: trueatmain/routes/printers.ts:1169and as the fallback atmain/printers/thermal.ts:2558): passesnativeCapabilities(raster.enabled: false) toformatReceipt, omitting{RAW_BYTES:...}logo bands fromprepared.dataeven when the resolved printer profile hascapabilities.raster.enabled === true. UpdaterasterizePrintDocumentForWebUsb(main/printers/thermal.ts:2444) to include|| lines.some((line) => line.startsWith('{RAW_BYTES:'))inrasterSelected.🔧 Fix applied.
3 issues (2 errors, 1 warning) still open:
main/printers/thermal.ts:2560- Gating{RAW_BYTES:...}logo emission onrasterCapabilityEnabled(capabilities)inmain/printers/document-classic.ts:529,main/printers/document-compact.ts:243, andfrontend/src/lib/printer/receipt-encoder.ts:640,1170causesnativeFallbackCapabilities(...)(which clones a thermal printer's capabilities withraster.enabled: falseto force text transliteration) to strip theGS v 0logo in the pre-raster native pass.rasterizeReceiptIfEnabled(main/printers/thermal.ts:2560) was updated to checkresult.rasterSelected || document.lines.some((line) => line.startsWith('{RAW_BYTES:')), but its sibling paths still drop the logo on raster-capable thermal printers:main/printers/thermal.ts:2444(rasterizePrintDocumentForWebUsb): returnsrasterSelected: result.rasterSelectedwithout|| lines.some((line) => line.startsWith('{RAW_BYTES:')). Whenfrontend/src/hooks/usePrinter.ts:498-569prints a bill with a logo via WebUSB in Electron (useElectronRaster === true) and all text lines are representable in the printer's native codepage (result.rasterSelected === false),buildClassicReceiptBytes/buildCompactReceiptBytes(frontend/src/lib/printer/receipt-encoder.ts:640,1170) runs withnativeFallbackCapabilities(webusbCapabilities)(raster.enabled: false) and omits the logo frombytes, andusePrinter.ts:561discardsrasterResult.databecauserasterResult.rasterSelectedisfalse, sending a logo-less receipt to the WebUSB thermal printer.main/printers/thermal.ts:2106(prepareReceipt, consumed byPOST /api/printers/print-billwithpreview: trueatmain/routes/printers.ts:1169and as the fallback atmain/printers/thermal.ts:2558): passesnativeCapabilities(raster.enabled: false) toformatReceipt, omitting{RAW_BYTES:...}logo bands fromprepared.dataeven when the resolved printer profile hascapabilities.raster.enabled === true. UpdaterasterizePrintDocumentForWebUsb(main/printers/thermal.ts:2444) to include|| lines.some((line) => line.startsWith('{RAW_BYTES:'))inrasterSelected.tests/impact-printer-support.test.ts:698- Intests/impact-printer-support.test.ts:698andtests/impact-printer-support.test.ts:717,.run(insertedPrinter.lastInsertRowid)referencesinsertedPrinter, which was removed when the preceding payment-ticket test was switched totargetPrinterin commit6c8cc76b, causingReferenceError: insertedPrinter is not definedat runtime. In addition,tests/impact-printer-support.test.ts:444-447callsrasterizePrintDocumentForWebUsb(webUsbDocument, 'epson-tm-series', 'classic', ...), swapping the second parameter (template: 'classic' | 'compact') and third parameter (profileId: string) ofrasterizePrintDocumentForWebUsb(main/printers/thermal.ts:2366-2370), soresolvePrinterProfile({ profile_id: 'classic' })falls back togeneric-escpos-80instead of testingepson-tm-series.main/printers/thermal.ts:2106- Inmain/printers/thermal.ts:2103-2120,prepareReceiptwas changed in commit6c8cc76bto passcapabilities(raster.enabled: trueon thermal profiles) directly toformatReceiptinstead ofnativeFallbackCapabilities(capabilities)so{RAW_BYTES:...}store logos would be retained. However,formatReceiptis a synchronous native ESC/POS formatter that callsbuildEscPoswithoutrenderUnsupportedRasterLines(rasterUnitsisundefined). Whencapabilities.raster.enabled === true,normalizeThermalText(shared/print/thermal-capabilities.ts:154) and the receipt layout helpers (pushWrappedatmain/printers/formatting-helpers.ts:479,pushCenteredWrappedatmain/printers/formatting-helpers.ts:498,truncateatmain/printers/formatting-helpers.ts:418,classicItemHeaderatmain/printers/document-classic.ts:317,compactItemHeaderatmain/printers/document-compact.ts:130) skip fallback Latin transliteration (LATIN_EXTENDED_ASCII_MAPand NFD diacritic stripping) and skip line wrapping (wrapText) for any text containing extended Latin characters (e.g.Ł/ł,Đ/đ,Ğ/ğ,İ/ı,Ş/ş,Ơ/ơ,Ư/ư,č,ř,š,ž), assuming Chromium rasterization will render the full line.buildEscPos(main/printers/formatting-helpers.ts:726-731,806) then folds the unwrapped line withraster.enabled: falseand hard-slices it atresolvedColumnsviafitThermalLine, silently truncating multi-line addresses or item names whenprepareReceiptruns (such as WebUSB fallback whenrasterizeReceiptIfEnabledfails or preview mode).🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run test:impact-printernpm run test:impact-printernpm run test:upgrade-path, and `npx playwright test e2e/qa-settings-receipts-printers…npm run test:impact-printernpm run test:receipt-column-oraclenpm run test:upgrade-pathnpm run test:script-coveragenpm run test:rasternpm run test:thermal-capabilitiesnpm run test:printernode tests/run-electron-node-test.cjs tests/backup-restore-production.test.tsnpm run i18n:checkcd frontend && EVIDENCE_DIR=~/.no-mistakes/evidence/01M6VT1Y5MB9ZNKQCZ97QEQYD4 npx playwright test --config=playwright.config.ts --project=chromium --retries=0 e2e/qa-settings-receipts-printers.spec.ts e2e/database-export-import.spec.ts✅ No issues found.
npm run test:impact-printernpm run test:receipt-column-oraclenpm run test:upgrade-pathnpm run test:script-coveragenpm run i18n:checknpm run docs:checkcd frontend && EVIDENCE_DIR=~/.no-mistakes/evidence/01M6VT1Y5MB9ZNKQCZ97QEQYD4 npx playwright test e2e/qa-settings-receipts-printers.spec.ts --config=playwright.config.ts --project=chromium --retries=0✅ **Document** - passed
✅ No issues found.
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.