Repository navigation
fix: resolve review findings for dev JWT recovery, KDS polling, and KOT notes - #1267
Conversation
… and KOT notes - security(jwt): only migrate to safeStorage in packaged Electron builds, keeping SQLite plaintext secret for unpackaged development runs (#1264) - fix(kds): preserve item status update refreshes while background REST poll is in flight (#1265) - feat(kot): propagate order notes through frontend builders and renderers with HTML escaping and thermal wrapping (#1266)
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@greptileai review this at apex |
[Medium impact] The changes appear safe to merge; no new actionable issues were found.
|
|
@greptileai review this at apex |
|
@greptileai review this at apex |
|
@greptileai review this at apex |
Fixes #1264
Fixes #1265
Fixes #1266
Intent
Resolve the three confirmed review findings from PR #1263 (commit e964eb1) in FreeOpenSourcePOS/FloCafe (tracked in GitHub issues #1264, #1265, and #1266):
main/security/jwt-secret.ts,docs/architecture/authentication-and-authorization.md,tests/jwt-secret-safe-storage.test.ts, GitHub issue fix(security): preserve shared dev database login after unpackaged Electron run #1264): Secure-storage migration must only run in packaged Electron builds (app.isPackaged === true). Unpackaged Electron development mode (app.isPackaged === false) shares<projectRoot>/flo.dbwithnode dev-server.js, which has nosafeStorage; without aJWT_SECREToverride, keeping the secret in SQLitesettings.jwt_secretduring unpackaged development runs preserves authentication compatibility across both runtimes while keeping OSsafeStoragemigration (safe-storage:v1) enforced in packaged builds.frontend/src/hooks/useKdsConnection.ts,tests/kds-broadcast-grouping.test.ts, GitHub issue fix(kds): preserve required post-mutation and conflict refreshes while REST poll is in flight #1265): Deduplicate overlapping background timer polls instartRestPolling(fetchOrdersRest({ skipIfInFlight: true })) while ensuring required refreshes (await fetchOrdersRest()after item statusPATCHsuccess in REST mode or409conflict) always incrementrestRequestSequenceRef.current(logically invalidating any stale in-flight poll) and fetch fresh KDS order state immediately. Track the active request sequence inrestInFlightRequestRefso an older superseded poll settling early cannot clear the in-flight marker of a newer request.main/printers/document-kot.ts,frontend/src/lib/printer/print-document.ts,frontend/src/lib/printer/kot-web-print.ts,frontend/src/lib/printer/kot-encoder.ts,tests/kot-order-notes.test.ts, GitHub issue fix(print): propagate order-level KOT notes through frontend HTML, WebUSB, and raster builders #1266): Propagate order-level notes (special_instructions,order_notes,orderNotes,notes) through all frontend KOT builders and renderers — browser HTML (generateKotHtmlwith HTML escaping and directional isolation), WebUSB ESC/POS bytes (buildKotByteswith wrapped bold double-height!! Note: ...lines above the item rule), and frontendKotDocument(buildFrontendKotDocumentpopulatingorder.orderNotesfor WebUSB rasterization) — plusthermalSafeTextfallback on the note label inmain/printers/document-kot.ts, and add comprehensive thermal, HTML, WebUSB bytes, and frontendKotDocumentregression tests intests/kot-order-notes.test.ts.What Changed
safeStorageJWT secret migration to packaged Electron builds and added development recovery inmain/security/jwt-secret.tsto restore encrypted secrets back into SQLitesettings.jwt_secretwhen running unpackaged, keeping Electron development andnode dev-server.jscompatible on shared databases.useKdsConnectionto deduplicate background polling withskipIfInFlightwhile sequencing active requests withrestInFlightRequestRef, ensuring required refreshes immediately invalidate older in-flight requests and fetch fresh KDS order state.generateKotHtml,buildKotBytes, andbuildFrontendKotDocument) with wrapped bold formatting, HTML escaping, and directional isolation, and added label fallback sanitization inmain/printers/document-kot.ts.Risk Assessment
✅ Low: The remediation changes are well-bounded, faithfully implement the authorized intent for issues #1264, #1265, and #1266, and introduce no security, performance, or functional regressions.
Testing
Exercised all three remediated PR #1263 review areas live: stood up dev-server on port 3001 to verify unpackaged SQLite JWT secret persistence, authentication, and safe-storage recovery; stood up KDS server on port 3002 to test live order polling, item PATCH transitions, 409 conflicts, and polling deduplication; rendered KOT HTML in headless Chromium via Playwright to capture a pixel-accurate visual screenshot showing the bold note banner positioned above items with verified HTML escaping; and validated WebUSB ESC/POS byte encoding and KotDocument v1 generation. All 3 scenarios passed.
Evidence: Scenario 1: Live Dev-Server Authentication & JWT Migration Transcript
=== SCENARIO 1: LIVE BACKEND-ONLY LOGIN (DEV-SERVER) === Database Path: /tmp/flo-scenario1-DEupSn/flo.db SQLite settings.jwt_secret format: 86acca8f... (length: 64 hex characters) POST /api/auth/login Response Status: 200 (access_token issued) Role: owner GET /api/auth/me Status: 200 (authenticated email: [email protected]) Adversarial safe-storage:v1 recovery to SQLite: true Dev-server reboot post-recovery login status: 200 Result: PASSEvidence: Scenario 2: Live KDS REST Polling & Request Sequence Evidence
=== SCENARIO 2: LIVE KDS REST POLLING DEDUPLICATION & REFRESH PRIORITY === KDS Port: 3002 Chef login successful: token obtained Live GET /api/kds/orders returned 1 active order Live PATCH /api/kds/items/1001/status -> status 'preparing' verified (200 OK) SQLite database verified: item 1001 status is now 'preparing' Refreshed GET /api/kds/orders confirmed item status updated to 'preparing' Adversarial PATCH with mismatched expected_status correctly returned 409 Conflict Result: PASS - Live KDS server and hook sequencing contract validatedEvidence: Scenario 3: ESC/POS Decoded Kitchen Ticket with Wrapped Note Banner
Source: Scenario 3: ESC/POS Decoded Kitchen Ticket with Wrapped Note Banner (local file:
~/.no-mistakes/evidence/01M5FKCY801J17D9YY1EKD0Q9W/kot-escpos-decoded.txt)Evidence: Scenario 3: Rendered Standalone KOT HTML Preview Page
Evidence: Scenario 3: Complete KOT Note Propagation & Sanity Summary
=== SCENARIO 3: COMPLETE FRONTEND KOT NOTE PROPAGATION === Order Number: ORD-902 Order Notes: "PEANUT ALLERGY: Clean prep surface thoroughly & pack utensils separately!" Browser HTML Preview: Saved to kot-order-notes-preview.html Browser Visual Screenshot: Saved to kot-order-notes-preview.png WebUSB ESC/POS Decoded: Saved to kot-escpos-decoded.txt HTML Placement: Note banner placed prominently above items divider with bold styling HTML Escaping: Verified - raw scripts and unescaped characters are fully sanitized ESC/POS Formatting: Wrapped bold double-height !! Note: lines above double rule divider KotDocument v1: Populates header.orderNotes for frontend WebUSB rasterization Field Fallbacks: special_instructions -> order_notes -> orderNotes -> notes supported across all paths Blank Handling: Whitespace and empty strings cleanly omit note banner Result: PASS - Frontend KOT note support is complete and visually verifiedPipeline
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.
node tests/run-electron-node-test.cjs tests/jwt-secret-safe-storage.test.tsnode tests/run-electron-node-test.cjs tests/kds-broadcast-grouping.test.tsts-node --transpile-only -P tests/tsconfig.json tests/kot-order-notes.test.tsLive dev-server Express API boot on port 3001 with isolated SQLite DB, POST /api/auth/login, GET /api/auth/me Bearer token validation, and unpackaged recovery checkLive startKdsServer boot on port 3002, chef login, GET /api/kds/orders, PATCH /api/kds/items/:id/status, and 409 conflict handlingPlaywright Chromium visual rendering and screenshot capture of generateKotHtml kitchen ticket preview with order notes (kot-order-notes-preview.png)WebUSB ESC/POS byte generation and decoding via buildKotBytes and escPosToText with wrapped double-height bold note bannerKotDocument v1 generation via buildFrontendKotDocument and line formatting via renderKotDocumentToLines✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.