Repository navigation
fix(orders): sync KDS readiness to pickup board - #1404
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoReconcile KDS order status and prepaid customer-display readiness
AI Description
Diagram
High-Level Assessment
Files changed (22)
|
Code Review by Qodo
1.
|
Reconcile active non-terminal parent order statuses (pending, preparing, ready, served) transactionally from the full live order_items set across all KDS item-status writers and order-item append, cancel, edit, and restore routes when KDS is enabled. Project effective board statuses for upfront-paid completed orders that still have unserved KDS items on both authenticated /customer-display and paired /api/customer-display/feed boards via idx_order_items_active_kds without mutating completed orders or scanning closed sales history, omitting them automatically once all live items are served. Fixes #1401
…ile refunds, optimize active query"}
…nd audit assertion"}
…end/e2e/customer-display-kds-readiness.spec.ts that caused strict-mode pos-product-card locator failures in diagnostics-checkout-recovery.spec.ts (and downstream End-to-End Playwright Tests / Required Checks Gate failures). Root cause & invariant: - Every Playwright spec sharing the single-worker tests/e2e-server.cjs backend must clean up any catalog categories, products, display tokens, settings overrides, and active KDS items it creates before subsequent specs run so the baseline single-product POS fixture (e2e-category / e2e-product) remains intact across specs and worker retries. - customer-display-kds-readiness.spec.ts created Pickup KDS 1401, Pickup Espresso 1401, and Pickup Croissant 1401 in beforeAll without deleting them in afterAll, leaving 3 pos-product-card buttons in /pos when diagnostics-checkout-recovery.spec.ts called addOneProduct(). Changes in frontend/e2e/customer-display-kds-readiness.spec.ts: - Added cleanupPickupCatalog() and wired test.afterAll to delete the created products first, then delete the now-empty Pickup KDS 1401 category, and restore snapshotted settings. - Guarded settingsSnapshot restoration in afterEach/afterAll if beforeAll fails early, and recorded orderId in cleanupOrderIds immediately on POST /api/orders in the prepaid test before awaiting bill/payment responses. Verification: - Reproduced the exact 4 failures before the fix by running customer-display-kds-readiness.spec.ts followed by diagnostics-checkout-recovery.spec.ts. - Re-ran both specs together after the fix: 7/7 passed. - Ran the full CI Playwright Shard 1/4 command (--shard=1/4 --retries=0): 87/87 passed. - Ran npm run lint, npm run lint:budget, node scripts/ci/check-changed-format.cjs --base 1d04ad3, npm run build, npm run build:frontend, and git diff --check: all passed. (Shards 2-4 of npm run test:e2e:browser were not re-run locally as they already passed in CI and only customer-display-kds-readiness.spec.ts in Shard 1/4 was modified.)
Bound completed-order KDS board projection to a shared rolling 24-hour orders.created_at window across paired and authenticated active feeds while keeping non-completed active orders unbounded. Replace unbounded completed-candidate fetching in buildDisplayFeed with 200-row keyset batches and deferred page-level bill_number lookups, and restore the cursor-friendly correlated activeOrderPredicate in GET /api/orders.
…an on active queries"}
Add a ?board_status query filter on GET /api/orders backed by shared pickup-board page selection so signed-in /customer-display filters effective board statuses (including <24h KDS-projected completed orders) before pagination instead of spending its 50-page fetch budget on excluded active statuses.
…t and format tests
8cd6288 to
f2acccf
Compare
Fixes #1401
Intent
Fix FloCafe issue #1401 ("Bug: Takeaway Order Status Not Updating") across order types and prepaid counter orders using a minimal YAGNI approach with no major product changes, no new settings UI, and no schema version bump:
completed, non-cancelled) parentorders.status(pending,preparing,ready,served) transactionally from the order's full authoritative live item set across all order types (dine_in,takeaway,delivery,online) across all KDS item-status write paths and order-item mutation endpoints: promotepending -> preparingwhen kitchen work starts while unfinished items remain, promote toready(Ready for pickupon/customer-display) only once all live positive-quantity items areready(or mixedreadywith alreadyserved/completedlines), promote toservedonce all live items areserved/completedso handed-over orders clear off/customer-displayautomatically, and demotereadyorservedback topreparing(clearing staleready_at/served_at) if unfinished items are appended, restored, edited to add pending work, or requeued.orders.status = 'completed') orders that still have live items inpending,preparing, orreadyon both authenticated and paired/customer-displayfeeds by projecting their effective board status (pending/preparing-> Preparing,ready-> Ready for pickup) from live item statuses without reopening or mutatingorders.status = 'completed', and automatically omit them from/customer-displayonce KDS marks all live itemsserved(Delivered)./customer-displayorder-type eligibility,CustomerDisplayConfig.statusesfiltering, KDS-disabled manual order-status workflows, andcancelledterminal orders unchanged.What Changed
orders.status(pending,preparing,ready,served) and lifecycle timestamps transactionally from live positive-quantityorder_itemswhen KDS is enabled viaderiveOrderStatusFromItemsandreconcileActiveOrderStatusFromItems, wired across KDS REST/standalone/WebSocket status updates,PATCH /api/order-items/:id/status, order-item append/cancel/edit/restore routes, and item refunds with order audit and cloud-sync events.pending,preparing,ready) from unserved live items forcompletedorders created within a rolling 24-hour window without mutatingorders.status = 'completed', omitting them once all live items areservedacross pairedGET /api/customer-display/feedand signed-in/customer-display.?board_statusfiltering onGET /api/orders, keyset-batched completed-order projection with page-levelbill_numberlookup on customer display feeds, and runtime-ensured partial indexidx_order_items_active_kdsat schema v121+ without bumping the schema version.Risk Assessment
✅ Low: Active order status reconciliation runs transactionally only when KDS is enabled without mutating completed or cancelled orders or bumping the schema version, and both GET /api/orders (?view=active, ?status=active, ?board_status=...) and paired GET /api/customer-display/feed combine indexed active-queue selection with a bounded 24-hour completed-order KDS projection window (keyset-batched at LIMIT 200) so historical closed orders are never scanned.
Testing
Built the backend and static desktop frontend in the isolated worktree, ran the focused backend test suites for customer-display feeds, KDS contracts and integration, active order search, and schema-reference caching plus the Chromium Playwright pickup-board readiness and TV pagination E2E specs, and stood up an isolated multi-server FloCafe instance (Main API, standalone KDS HTTP/WebSocket, and Server App backed by a disposable SQLite database) to drive all five derived happy-path and adversarial scenarios live in Chromium with ten reviewer-visible screenshots and a sanitized JSON transcript captured in the evidence directory; every automated check and live scenario passed cleanly.
Evidence: Sanitized JSON transcript of all 5 live multi-service browser, HTTP, and WebSocket scenarios
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
🔧 **Rebase** - 1 issue found → auto-fixed ✅
docs/reference/api.md- merge conflict rebasing onto origin/main🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run build && npm run build:frontendnpm run test:customer-display-feednpm run test:kds-contractnpm run test:kds-integrationnpm run test:schema-reference-cachenode tests/run-electron-node-test.cjs tests/orders-search-api.test.tscd frontend && CI=1 E2E_TASK_LOCAL_PORTS=1 E2E_BASE_URL=http://127.0.0.1:13401 E2E_KDS_BASE_URL=http://127.0.0.1:13402 E2E_SERVER_APP_BASE_URL=http://127.0.0.1:13403 npx playwright test --config=playwright.config.ts --project=chromium --retries=0 e2e/customer-display-kds-readiness.spec.tscd frontend && CI=1 E2E_TASK_LOCAL_PORTS=1 E2E_BASE_URL=http://127.0.0.1:13401 E2E_KDS_BASE_URL=http://127.0.0.1:13402 E2E_SERVER_APP_BASE_URL=http://127.0.0.1:13403 npx playwright test --config=playwright.config.ts --project=chromium --retries=0 e2e/layout-integrity.spec.ts -g "customer display wraps full receipt numbers and pages on TV"Live isolated 5-scenario validation againstnode tests/e2e-server.cjson ports13501/13502/13503driving Playwright Chromium signed-in/customer-display, paired/customer-display, standalone/kds-standalone, REST endpoints (/api/kds/items/:id/statuson:13501and:13502,/api/order-items/:id/status,/api/orders,/api/refunds,/api/customer-display/feed), and KDS WebSocket (ws://127.0.0.1:13502/kds)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.