Repository navigation
fix(print): fix WebUSB reconnect and E2E spec - #1651
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoHarden WebUSB reconnect, printer errors, and E2E isolation
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
… (Shard 1/4) (which caused End-to-End Playwright Tests and Required Checks Gate to fail): - **Root cause**: `frontend/e2e/delivery-slip-payment.spec.ts` (lines 451-510) still asserted the pre-fix ordering where `printDeliverySlip` dispatched to `/api/printers/print-delivery-slip` (host fallback) before awaiting `printerService.awaitPendingReconnect()`. Because PR #1651 fixed `usePrinter.ts` to await pending WebUSB reconnect before deciding host vs local WebUSB, `usbNativeNoDefaultReached` never fired while `claimInterface` was held, causing `blockedUsbPaymentRequest` at line 485 to time out after 5000ms. - **Fix**: Updated `frontend/e2e/delivery-slip-payment.spec.ts` to wait for the synchronous popup reservation (`__deliverySlipPrintOpenCount`), assert that no host fallback request (`/api/printers/print-delivery-slip`) is issued while WebUSB reconnect is pending, release the held WebUSB claim, and verify that the delivery slip prints directly over WebUSB with `nativePrintRequests` unchanged. - **Verification**: - `npm run lint` passed (0 errors) - `npm run build` and `npm run build:frontend` passed - `npx playwright test e2e/delivery-slip-payment.spec.ts e2e/pos-prepaid-auto-print.spec.ts --config=playwright.config.ts --project=chromium` passed (3/3 passed) - `node scripts/ci/check-changed-format.cjs --base 3cef902` passed
…Validation (Linux)` (which caused `Required Checks Gate` to fail): - **Root cause**: `scripts/ci/check-changed-format.cjs` checks Oxfmt formatting across all JS/TS files changed between base `3cef9027417a44d514d5e0f9b7712bfa04255aa3` and `HEAD`. `frontend/e2e/delivery-slip-payment.spec.ts` (edited in the previous fix round) failed `oxfmt --check`. All other 7 changed files (2 root, 5 frontend) already passed. - **Fix**: Formatted `frontend/e2e/delivery-slip-payment.spec.ts` using `npx oxfmt --write -- e2e/delivery-slip-payment.spec.ts` from `frontend/` (formatting-only change, no behavioral edits). - **Verification**: - `node scripts/ci/check-changed-format.cjs --base 3cef902` passed (2 root + 6 frontend changed files) - `(cd frontend && npm run lint)` passed (0 errors, 3 pre-existing warnings) - `npm run lint:budget` passed (backend 981/1000, frontend 3/5) - `npm run build:frontend` passed - `git status --short` confirmed only `frontend/e2e/delivery-slip-payment.spec.ts` was modified
|
@greptile review |
[Low impact] The changes stay within browser printing and printer settings. No functional blocker was found, but the added test comments must satisfy the repository’s comment rule before merging. Findings
|
…-print-e2e-bugs # Conflicts: # tests/printer-error-toast-clarity.test.ts
Intent
Fix the five confirmed non-product WebUSB printing and E2E test-isolation bugs tracked in #1645 from the post-3.14.0 dual review: awaiting pending WebUSB reconnect before host fallback, surfacing plain Error messages in WebUSB Test Print, only caching
lastResolvedUsbDeviceafter successful/printersrefresh, returningthis.isConnectedfromPrinterService.tryReconnect(), and isolatingpos-prepaid-auto-print.spec.tsfrom configured host printers. Ship cleanly viano-mistakesclosing #1645.What Changed
usePrinterStore.printBillandprintDeliverySlipbefore falling back to host dispatch, cachelastResolvedUsbDeviceonly whenrefreshHardwarePrinter()succeeds, and returnthis.isConnectedfromPrinterService.tryReconnect()instead of unconditionally returningtrue.formatPrinterSettingsErrorMessage()infrontend/src/lib/printer/warnings.tsand use it inPrintersSettingsTab.tsxso sanitized Axios API errors and plainErrormessages (such as WebUSB test-print failures) are surfaced instead of falling back to a generic message.printMethodto'browser'inflo-printer-settingsinsidefrontend/e2e/pos-prepaid-auto-print.spec.tsto isolate the test from configured host printers, and add unit coverage intests/printer-error-toast-clarity.test.tsandtests/printer-service-browser-mode.test.tsfor reconnect ordering,/printersrefresh caching, error formatting, andtryReconnect()return values.Risk Assessment
✅ Low: All five targeted WebUSB reconnect, error-surfacing, cache-gating, and E2E test-isolation fixes are minimal, conform to user intent, and have behavioral regression coverage.
Testing
Ran targeted printer tests (
npm run test:thermal-capabilities), built the backend and static frontend, and drove four live scenarios in Chromium against an isolated running FloCafe server (tests/e2e-server.cjs) covering WebUSB Test Print error-toast surfacing (with screenshot), adversarialpos-prepaid-auto-print.spec.tsisolation with a pre-configured default host printer, awaiting pending WebUSB reconnect before host fallback (with screenshot and request metrics), and transientGET /api/printersretry/caching behavior; all four live scenarios and the targeted module test forPrinterService.tryReconnect()passed.Evidence: Live browser Scenario 3 pending WebUSB reconnect metrics (zero host fallback posts, 1 local WebUSB transfer)
Evidence: Live browser Scenario 4 transient GET /api/printers 503 retry and cache hit metrics
Evidence: Playwright pos-prepaid-auto-print.spec.ts with pre-configured default host printer in live DB
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run test:thermal-capabilities(includestests/printer-service-browser-mode.test.tsandtests/printer-error-toast-clarity.test.ts)npm run build && npm run build:frontendLive Chromium check against isolatedtests/e2e-server.cjs(ports 13001-13003): Settings -> Printers WebUSB Test Print error toast + screenshotLive adversarial Playwright run: seeded default host network printer intests/e2e-server.cjsDB, then rannpx playwright test e2e/pos-prepaid-auto-print.spec.ts --config=playwright.config.ts --project=chromium --retries=0Live Chromium check against isolatedtests/e2e-server.cjswith syntheticnavigator.usb: heldclaimInterfaceduring POS prepaid checkout to verify pending WebUSB reconnect is awaited before host fallback + screenshotLive Chromium check against isolatedtests/e2e-server.cjswith syntheticnavigator.usband HTTP 503 interception onGET /api/printers: verified transient refresh failure does not poisonlastResolvedUsbDevicecache and subsequent successful refresh caches properly✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Issues
Closes #1645