Skip to content

fix: distinguish disabled server bill printing and scope appended KOT items - #1461

Merged
khaira777 merged 2 commits into
mainfrom
fm/flocafe-server-app-print-polish
Nov 4, 2026
Merged

khaira777 merged 2 commits into
mainfrom
fm/flocafe-server-app-print-polish

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Apply the 3 verified, minimal YAGNI follow-up fixes from the post-merge review before tagging 3.13.23:

  1. Distinguish disabled Server App bill printing (BILL_PRINTING_DISABLED) from permission_denied (and other 403s) in main/server-app.ts, main/routes/printers.ts, and frontend/src/app/server-standalone/page.tsx (printOrderSlip) so status === 403 stays quiet only when errorCode === 'BILL_PRINTING_DISABLED' (matching KOT_PRINTING_DISABLED in printKotForOrder).
  2. Make the new Server App HTTP 400 E2E regression test in frontend/e2e/server-app-ordering.spec.ts (does not open browser print popup when no hardware printer is configured (400)) strictly falsifiable and race-free by using { exact: true } for 'Order sent', awaiting both /api/printers/print-kot and /api/printers/print-bill 400 responses via page.waitForResponse, and asserting that neither localized print-error toast ("Order sent, but the kitchen ticket didn't print" / "Order sent, but the bill didn't print") appears.
  3. In frontend/src/app/server-standalone/page.tsx (sendDraft append path), prefer data.added_items from POST /api/orders/:id/items when present (matching POSPage and OrdersPage) so concurrent appends from multiple waiters on the same table only print the items added by that call.

What Changed

  • Return code: 'BILL_PRINTING_DISABLED' on 403 responses from POST /api/printers/print-bill in main/routes/printers.ts and main/server-app.ts (and document the 403 error codes in docs/reference/api.md), and update printOrderSlip in frontend/src/app/server-standalone/page.tsx to suppress 403 errors only when code === 'BILL_PRINTING_DISABLED'.
  • Prefer data.added_items from POST /api/orders/:id/items in ServerStandalonePage.sendDraft when determining which newly appended items to print on KOT tickets, falling back to existingItemIds diffing only when absent.
  • Harden the Server App 400 printer E2E test in frontend/e2e/server-app-ordering.spec.ts to match the 'Order sent' toast with { exact: true }, await both /api/printers/print-kot and /api/printers/print-bill 400 responses before checking state, and assert that neither print-failure toast appears.

Risk Assessment

✅ Low: The changes are minimal, targeted follow-ups that add an explicit BILL_PRINTING_DISABLED error code on 403 responses, prefer backend added_items on order appends, and harden the Server App E2E print test assertions without introducing behavioral regressions.

Testing

Built the backend and static frontend, ran the full Playwright e2e/server-app-ordering.spec.ts suite (9/9 passing, including the strengthened HTTP 400 regression test) and backend Server App test suites (test:server-app-server-role, test:server-app-station-routing), and drove all four end-to-end scenarios live against disposable Main API, KDS, and Server App instances with Chromium browser contexts, capturing screenshots and JSON transcripts in the evidence directory.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Waiter sends an order when Server App bill printing is disabled: both Server App and Main API return HTTP 403 with code 'BILL_PRINTING_DISABLED' and the UI shows only 'Order sent' without any bill-pri… ✅ pass live ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-1-bill-printing-disabled-quiet.png and ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/live-valid…
Adversarial: Waiter whose printing.execute permission is denied sends an order when Server App bill printing is enabled: /api/printers/print-bill returns HTTP 403 with code 'permission_denied' and the… ✅ pass live ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-2-permission-denied-403-toast.png and ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/live-valida…
Waiter sends an order when no hardware printer is configured: both /api/printers/print-kot and /api/printers/print-bill return HTTP 400, no browser window.print() or window.open() popup is triggered,… ✅ pass live ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-3-no-hardware-printer-400.png and npx --prefix frontend playwright test e2e/server-app-ordering.spec.ts
Two waiters concurrently append items to the same table order without refreshing in between: the second waiter's /api/printers/print-kot request payload contains only the items from data.added_items a… ✅ pass live ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-4-concurrent-append-kot-items.png and ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/live-valida…

Scenario 1: Disabled Server App bill printing (403 BILL_PRINTING_DISABLED) stays quiet
Scenario 2 (Adversarial): 403 permission_denied on print-bill surfaces error toast
Scenario 3: No hardware printer configured (400) stays quiet without browser print popup or error toasts
Scenario 4: Concurrent multi-waiter append uses data.added_items for KOT print payload

Evidence: Live validation API & print payload transcript

{ "scenario1": { "mainApiDirect403": { "status": 403, "body": { "error": "Bill printing is disabled for the server role. An owner or manager can enable it in Settings.", "code": "BILL_PRINTING_DISABLED" } }, "serverAppProxy403": { "status": 403, "body": { "error": "Bill printing is disabled for the Server Companion App. An owner or manager can enable it in Settings.", "code": "BILL_PRINTING_DISABLED" } }, "billErrorToastCount": 0, "kotErrorToastCount": 0 }, "scenario2": { "forwardedPrintBill403": { "status": 403, "body": { "error": "Insufficient permissions", "code": "permission_denied", "permission": "printing.execute" } }, "billErrorToastVisible": true }, "scenario3": { "kot400": { "status": 400 }, "bill400": { "status": 400 }, "browserPrintCalls": 0, "kotErrorToastCount": 0, "billErrorToastCount": 0, "rawErrorToastCount": 0 }, "scenario4": { "orderId": 4, "waiter1AppendAddedItems": [{ "id": 5, "product_name": "E2E Tea", "quantity": 1 }], "waiter1KotPrintedItems": [{ "id": 5, "product_name": "E2E Tea", "quantity": 1 }], "waiter2AppendOrderAllItemsCount": 3, "waiter2AppendAddedItems": [{ "id": 6, "product_name": "E2E Croissant", "quantity": 2 }], "waiter2KotPrintedItems": [{ "id": 6, "product_name": "E2E Croissant", "quantity": 2 }] } }

{
  "scenario1": {
    "mainApiDirect403": {
      "status": 403,
      "body": {
        "error": "Bill printing is disabled for the server role. An owner or manager can enable it in Settings.",
        "code": "BILL_PRINTING_DISABLED"
      }
    },
    "serverAppProxy403": {
      "status": 403,
      "body": {
        "error": "Bill printing is disabled for the Server Companion App. An owner or manager can enable it in Settings.",
        "code": "BILL_PRINTING_DISABLED"
      }
    },
    "kotResponse": {
      "status": 403,
      "body": {
        "error": "KOT printing is disabled for this business",
        "code": "KOT_PRINTING_DISABLED"
      }
    },
    "billErrorToastCount": 0,
    "kotErrorToastCount": 0,
    "screenshot": "~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-1-bill-printing-disabled-quiet.png"
  },
  "scenario2": {
    "forwardedPrintBill403": {
      "status": 403,
      "body": {
        "error": "Insufficient permissions",
        "code": "permission_denied",
        "permission": "printing.execute"
      }
    },
    "billErrorToastVisible": true,
    "billErrorToastCount": 2,
    "screenshot": "~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-2-permission-denied-403-toast.png"
  },
  "scenario3": {
    "kot400": {
      "status": 400,
      "body": {
        "error": "No default printer configured. Add a printer in Settings."
      }
    },
    "bill400": {
      "status": 400,
      "body": {
        "error": "No default printer configured. Add a printer in Settings."
      }
    },
    "browserPrintCalls": 0,
    "kotErrorToastCount": 0,
    "billErrorToastCount": 0,
    "rawErrorToastCount": 0,
    "screenshot": "~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-3-no-hardware-printer-400.png"
  },
  "scenario4": {
    "orderId": 4,
    "waiter1AppendAddedItems": [
      {
        "id": 5,
        "product_name": "E2E Tea",
        "quantity": 1
      }
    ],
    "waiter1KotPrintedItems": [
      {
        "id": 5,
        "product_name": "E2E Tea",
        "quantity": 1
      }
    ],
    "waiter2AppendOrderAllItemsCount": 3,
    "waiter2AppendAddedItems": [
      {
        "id": 6,
        "product_name": "E2E Croissant",
        "quantity": 2
      }
    ],
    "waiter2KotPrintedItems": [
      {
        "id": 6,
        "product_name": "E2E Croissant",
        "quantity": 2
      }
    ],
    "screenshot": "~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-4-concurrent-append-kot-items.png"
  }
}

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.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Waiter sends an order when Server App bill printing is disabled: both Server App and Main API return HTTP 403 with code 'BILL_PRINTING_DISABLED' and the UI shows only 'Order sent' without any bill-pri… ✅ pass live ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-1-bill-printing-disabled-quiet.png and ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/live-valid…
Adversarial: Waiter whose printing.execute permission is denied sends an order when Server App bill printing is enabled: /api/printers/print-bill returns HTTP 403 with code 'permission_denied' and the… ✅ pass live ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-2-permission-denied-403-toast.png and ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/live-valida…
Waiter sends an order when no hardware printer is configured: both /api/printers/print-kot and /api/printers/print-bill return HTTP 400, no browser window.print() or window.open() popup is triggered,… ✅ pass live ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-3-no-hardware-printer-400.png and npx --prefix frontend playwright test e2e/server-app-ordering.spec.ts
Two waiters concurrently append items to the same table order without refreshing in between: the second waiter's /api/printers/print-kot request payload contains only the items from data.added_items a… ✅ pass live ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/scenario-4-concurrent-append-kot-items.png and ~/.no-mistakes/evidence/01M6JGMRAMHFM2HQM2FHY1D3FW/live-valida…
  • npm run build && npm run build:frontend
  • E2E_BASE_URL=http://127.0.0.1:43001 E2E_KDS_BASE_URL=http://127.0.0.1:43002 E2E_SERVER_APP_BASE_URL=http://127.0.0.1:43003 CI=1 npx --prefix frontend playwright test e2e/server-app-ordering.spec.ts --config=frontend/playwright.config.ts --project=chromium --retries=0
  • npm run test:server-app-server-role
  • npm run test:server-app-station-routing
  • NODE_PATH="$(pwd)/node_modules:$(pwd)/frontend/node_modules" node tests/run-electron-node-test.cjs ~/.gemini/antigravity-cli/brain/a742b408-11a6-4a22-bda3-72e9db16af93/scratch/live-verify.ts
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Distinguish disabled bill printing and scope appended KOT items

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Identify disabled Server App bill printing explicitly so other 403 errors remain visible.
• Print only items added by the current order append when the API provides them.
• Make the no-printer E2E test wait for both responses and reject print-error toasts.
Diagram

graph TD
  UI["Server UI"] -->|"append order"| Orders["Orders API"] -->|"added items"| Scope["KOT item scope"] --> Gateway["Server App"] --> Routes["Printer routes"] --> Device["Hardware printer"]
  UI -->|"print bill"| Gateway
  Settings["Print settings"] --> Gateway
  Settings --> Routes
Loading
High-Level Assessment

Use the API's added_items as the authoritative scope for an append, retain the existing fallback, and return a specific code from both bill-printing gates. This is more targeted than inferring concurrent additions from the full order or suppressing every 403.

Files changed (5) +31 / -10

Bug fix (3) +12 / -4
page.tsxScope appended KOT items and identify quiet bill failures +10/-4

Scope appended KOT items and identify quiet bill failures

• Prefers added_items from the order append response, falling back to the existing item-ID comparison. Suppresses a bill-printing 403 only when its code is BILL_PRINTING_DISABLED, leaving other 403 errors visible.

frontend/src/app/server-standalone/page.tsx

printers.tsCode disabled server-role bill-printing responses +1/-0

Code disabled server-role bill-printing responses

• Adds BILL_PRINTING_DISABLED to the 403 response when the server role is blocked by the bill-printing setting.

main/routes/printers.ts

server-app.tsCode disabled Server App bill-printing responses +1/-0

Code disabled Server App bill-printing responses

• Adds BILL_PRINTING_DISABLED to the Server App gateway's 403 response when its bill-printing setting is off.

main/server-app.ts

Tests (1) +16 / -3
server-app-ordering.spec.tsStrengthen the no-printer Server App regression test +16/-3

Strengthen the no-printer Server App regression test

• Matches the success toast exactly, waits for both mocked 400 printer responses, and verifies that neither browser printing nor print-failure toasts occur.

frontend/e2e/server-app-ordering.spec.ts

Documentation (1) +3 / -3
api.mdDocument printer permission and disabled-printing responses +3/-3

Document printer permission and disabled-printing responses

• Corrects the print-bill permission listing and documents the BILL_PRINTING_DISABLED and KOT_PRINTING_DISABLED 403 codes, including the Server App forwarding route.

docs/reference/api.md

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Print-failure toasts can escape the test 🐞 Bug ☼ Reliability
Description
The new response waits resolve when Playwright receives the status and headers, while the single
zero-delay timer does not guarantee that Axios has handled the response and React has rendered a
toast. If either print path begins showing an error toast after that timer, the absence assertions
can pass before the toast appears.
Code

frontend/e2e/server-app-ordering.spec.ts[R134-135]

+    await Promise.all([kotResponsePromise, billResponsePromise]);
+    await page.evaluate(() => new Promise((resolve) => setTimeout(resolve, 0)));
Relevance

●●● Strong

Accepted pattern: asynchronous UI assertions require a positive completion signal beyond response
events or fixed delays.

PR-#1260

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The test awaits the two 400 responses, then waits only one zero-delay timer before checking for
absent toasts. Playwright documents that its response event occurs when status and headers arrive,
before the response body finishes downloading; neither that event nor the timer establishes that the
frontend's catch handlers have run.

frontend/e2e/server-app-ordering.spec.ts[124-146]
frontend/src/app/server-standalone/page.tsx[949-992]
🌐 Playwright emits the response event upon receipt of status and headers, and requestfinished only after the response body is downloaded.

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The test can check that print-failure toasts are absent before the frontend has handled both 400 responses.
## Fix Focus Areas
- frontend/e2e/server-app-ordering.spec.ts[124-146]
## Recommended Fix
Replace the zero-delay timer with a reliable signal that both frontend print handlers have completed before asserting toast absence. If no completion signal is available, observe for late toasts over an explicit bounded interval rather than relying on `toHaveCount(0)` immediately after the responses.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #39
  🌐 PR #10
  🌐 PR #34
✅ Compliance rules (platform): 5 rules
✅ Web pages:
  +2 more
✅ Cross-repo context — repo relationships
✅ REVIEW.md
Review mode: Auto: ⚖️ Balanced: Behavioral changes affect printing permissions, API errors, concurrency, and E2E coverage.

Grey Divider

Tip of the day
💡 Did you know, you can commit Qodo's fix in one click with committable suggestions (GitHub & GitLab)

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@khaira777
khaira777 merged commit 09108be into main Nov 4, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-server-app-print-polish branch November 4, 2026 05:56
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