Skip to content

fix(macos): route MAS USB print via CUPS socket - #1383

Merged
khaira777 merged 5 commits into
mainfrom
fm/flocafe-1347-mas-cups-ipp-scout
Oct 26, 2026
Merged

khaira777 merged 5 commits into
mainfrom
fm/flocafe-1347-mas-cups-ipp-scout

Conversation

@khaira777

@khaira777 khaira777 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix #1347 (bug(macos): Mac App Store USB printing via CUPS/IPP (needs device repro)):

  1. In main/printers/ipp-client.ts:
  • Connect to the local macOS CUPS daemon over the UNIX domain socket /private/var/run/cupsd by default (with configurable endpoint override for tests and TCP 127.0.0.1:631 fallback on ENOENT), because /System/Library/Sandbox/Profiles/application.sb blocks outbound TCP to localhost:631 (EPERM) while allowing /private/var/run/cupsd under com.apple.security.print, and launchd (org.cups.cupsd.plist) only socket-activates /private/var/run/cupsd after cupsd's 60s idle exit.
  • Send document-format = application/vnd.cups-raw in ippPrintRaw() so CUPS bypasses auto-typing and PPD filters (lp -o raw parity).
  • Export IPP request/response builders and status error mapping (formatIppStatusError), mapping 0x0406 (client-error-not-found) to a clear actionable message instructing the user to add the USB printer in macOS System Settings > Printers & Scanners and match the CUPS queue name.
  1. In main/printers/thermal.ts and frontend/src/components/settings/PrintersSettingsTab.tsx:
  • Route printViaUSB() through printViaLocalIpp() on macOS MAS runtime (isMasRuntime()) so all USB print entry points (receipts, KOT, delivery slip, menu, test print, active test print, cash drawer kick, and Z-report) use local IPP instead of spawning /usr/bin/lp / /usr/bin/lpstat.
  • Return failureClass: 'not_configured' with the actionable missing-queue message when the CUPS queue does not exist (0x0406), and show the printerNameMismatchWarning banner in PrintersSettingsTab.tsx even when detectedPrinters.length === 0.
  1. Add unit and loopback mock-server tests in tests/ipp-client.test.ts (wired into test:printer in package.json) and document macOS / Mac App Store USB printer setup in docs/printers.md and docs/architecture/printing.md.
  2. Include Fixes #1347 in the PR body and keep the PR title 50 characters or fewer (fix(macos): route MAS USB print via CUPS socket).
  3. Document the macOS CUPS/IPP and application.sb sandbox reproduction & verification findings (both with a Generic/Raw CUPS queue and without a queue) in docs/printers.md and tests/ipp-client.test.ts.
  4. main/printers/ipp-client.ts:40: IPP_STATUS_SERVER_ERROR_NOT_ACCEPTING_JOBS is currently 0x0508 (which is server-error-job-canceled in RFC 8011); set IPP_STATUS_SERVER_ERROR_NOT_ACCEPTING_JOBS = 0x0506, add a separate constant/message for 0x0508 (job canceled, not queue_unavailable), and test both in tests/ipp-client.test.ts.
  5. main/printers/ipp-client.ts:298: On UNIX socket ENOENT, do not immediately return the TCP fallback call outside the ECONNREFUSED retry loop; instead switch to the TCP endpoint for the remaining retry loop attempts and add a test where the socket is missing, the first TCP attempt gets ECONNREFUSED, and the retry succeeds.
  6. frontend/src/components/settings/PrintersSettingsTab.tsx:622: Track whether printer detection completed successfully separately from detectedPrinters=[], so a failed detection request does not show a false USB queue-name mismatch warning.
  7. tests/ipp-client.test.ts: Ensure the mock CUPS UNIX socket test does not break on Windows CI (attach once('error', reject) on server listen promises, and on win32 use a named pipe \?\pipe... or skip UNIX filesystem socket binding).

What Changed

  • Update main/printers/ipp-client.ts to connect to the local macOS CUPS UNIX domain socket /private/var/run/cupsd by default (switching to loopback TCP 127.0.0.1:631 across remaining retry attempts on ENOENT), send document-format = application/vnd.cups-raw in ippPrintRaw(), and map IPP status errors (0x0406 missing queue, 0x0506 not accepting jobs, and 0x0508 job canceled) via formatIppStatusError().
  • Route printViaUSB() through printViaLocalIpp() on macOS Mac App Store builds in main/printers/thermal.ts with classifyPrintFailure() classification (not_configured on missing queues), and track completed printer detection in frontend/src/components/settings/PrintersSettingsTab.tsx so the USB queue-name mismatch warning renders when zero queues are detected without false-triggering on failed detection requests.
  • Add IPP protocol, status mapping, and mock-server transport tests in tests/ipp-client.test.ts (wired into test:printer in package.json) and document macOS/MAS CUPS queue setup and socket transport in docs/printers.md and docs/architecture/printing.md.

Fixes #1347

Risk Assessment

✅ Low: The change is well-bounded to local macOS CUPS/IPP transport, error classification, printer settings UI feedback, documentation, and mock-server unit tests, matching all requirements in the user intent with no identified defects.

Testing

Ran the targeted IPP client and printer test suites (tests/ipp-client.test.ts, npm run test:printer, npm run test:script-coverage), built the backend and static frontend (npm run build, npm run build:frontend), and drove 5 live end-to-end scenarios against the real macOS /private/var/run/cupsd daemon and sandbox-exec (application.sb), the live Express API across all 8 MAS USB print entry points over a UNIX domain socket CUPS endpoint, and the live Settings > Printers UI in Chromium, capturing 2 protocol transcripts and 4 UI screenshots in the evidence directory.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Under macOS App Sandbox (application.sb), outbound TCP to localhost:631 is blocked with EPERM while FloCafe's IPP client connects over UNIX socket /private/var/run/cupsd to the real macOS cupsd daemon ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/macos-sandbox-and-ipp-live.txt
On macOS MAS runtime (MAS_BUILD=1), USB printer detection and all 8 USB print entry points (test print, active test print, cash drawer kick, receipt bill, KOT, delivery slip, menu, and Z-report) route… ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/mas-usb-print-entry-points-live.txt
Printing to a USB printer whose queue name does not exist in macOS CUPS returns IPP status 0x0406 (client-error-not-found), classifies as failureClass 'not_configured', and surfaces actionable System… ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/usb-missing-cups-queue-toast.png
Adversarial transport & RFC 8011 status check: missing UNIX socket (ENOENT) switches to loopback TCP inside the ECONNREFUSED retry loop and succeeds when the TCP listener comes up on retry, and IPP 0x… ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/macos-sandbox-and-ipp-live.txt
Settings > Printers shows the amber queue-name mismatch warning for a manual USB printer even when 0 printers are detected, clears it when the name matches a detected CUPS queue, and suppresses false… ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/usb-mismatch-warning-zero-detected.png, ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/usb-no-false-misma…
Evidence: macOS App Sandbox (application.sb), real /private/var/run/cupsd socket, ENOENT->ECONNREFUSED retry, and RFC 8011 status verification transcript
=== 1. Real macOS /private/var/run/cupsd & application.sb Sandbox Verification ===
Real macOS cupsd (/private/var/run/cupsd) ippGetPrinters count: 1
Real macOS cupsd (/private/var/run/cupsd) ippGetDefaultPrinterName: null
Real macOS cupsd (/private/var/run/cupsd) ippGetPrinterAttributes(missing): {"exists":false,"statusCode":1030,"detail":"Printer queue \"FloCafe_NonExistent_USB_Queue_1347\" was not found in macOS Printers & Scanners. Add the USB printer in System Settings > Printers & Scanners and make sure the printer name in FloCafe matches the CUPS queue name."}
Real macOS cupsd (/private/var/run/cupsd) printViaUSB(missing): {"ok":false,"detail":"Printer queue \"FloCafe_NonExistent_USB_Queue_1347\" was not found in macOS Printers & Scanners. Add the USB printer in System Settings > Printers & Scanners and make sure the printer name in FloCafe matches the CUPS queue name.","failureClass":"not_configured"}
sandbox-exec (application.sb:772-784 rules) result: {"tcp127_631":"EPERM: connect EPERM 127.0.0.1:631 - Local (0.0.0.0:0)","unixCupsdStatus":1030,"unixCupsdExists":false,"detail":"Printer queue \"FloCafe_Sandbox_Test_Queue\" was not found in macOS Printers & Scanners. Add the USB printer in System Settings > Printers & Scanners and make sure the printer name in FloCafe matches the CUPS queue name."}

=== 2. UNIX Socket ENOENT -> Loopback TCP Fallback inside ECONNREFUSED Retry Loop ===
Fallback after ENOENT + initial ECONNREFUSED succeeded: {"exists":true,"statusCode":0,"tcpAcceptCount":1}

=== 3. RFC 8011 Status Codes 0x0506 (not-accepting-jobs) vs 0x0508 (job-canceled) ===
0x506 -> {"msg":"Printer \"EPSON_TM_T20II\" is not accepting jobs","failureClass":"queue_unavailable"}
0x508 -> {"msg":"Print job for \"EPSON_TM_T20II\" was canceled at the printer","failureClass":"unknown"}
Evidence: Live Express API + UNIX socket CUPS IPP transcript across all 8 MAS USB print entry points and 0x0406 missing-queue handling
=== Live Express API + UNIX Socket CUPS IPP Verification (MAS_BUILD=1) ===
1. GET /api/printers/detect -> HTTP 200: {"printers":[{"name":"EPSON_TM_T20II","make":"EPSON","model":"TM-T20II","connectionType":"usb","deviceUri":"usb://EPSON/TM-T20II?serial=544336594580510000","status":"idle","isDefault":true,"paperWidth":"cols-48","profileId":"epson-tm-series"}]}
2. POST /api/printers -> HTTP 201 (id=8ccdbf5c-0cd0-4823-a96e-64ee9a60fb5b, profile=epson-tm-series)
3. POST /api/printers/:id/test -> HTTP 200: {"success":true}
4. POST /api/printers/test-active -> HTTP 200: {"success":true}
5. POST /api/printers/kick-drawer -> HTTP 200: {"success":true}
6. POST /api/printers/print-bill -> HTTP 200: {"success":true,"warnings":[]}
7. POST /api/printers/print-kot -> HTTP 200: {"success":true,"warnings":[]}
8. POST /api/printers/print-delivery-slip -> HTTP 200: {"success":true,"warnings":[]}
9. POST /api/printers/print-menu -> HTTP 200: {"success":true,"printerName":"EPSON_TM_T20II","warnings":[]}
10. POST /api/cash-closures/1/print -> HTTP 200: {"success":true,"isReprint":false,"warnings":[]}

Total IPP Print-Job requests received over UNIX socket: 8
  Job #1: url=/printers/EPSON_TM_T20II format=application/vnd.cups-raw bytes=654 preview="Flo Printer Test ================================================ Network / USB test print ============================="
  Job #2: url=/printers/EPSON_TM_T20II format=application/vnd.cups-raw bytes=654 preview="Flo Printer Test ================================================ Network / USB test print ============================="
  Job #3: url=/printers/EPSON_TM_T20II format=application/vnd.cups-raw bytes=5 preview="�"
  Job #4: url=/printers/EPSON_TM_T20II format=application/vnd.cups-raw bytes=705 preview="FloCafe MAS Bistro Customer Details Alex Rivera +12125550199 Delivery address: 742 Evergreen Terrace -------------------"
  Job #5: url=/printers/EPSON_TM_T20II format=application/vnd.cups-raw bytes=322 preview="KITCHEN ORDER TICKET Station: Kitchen Order #ORD-101 Type: Delivery Customer: Alex Rivera Time: 6:16:29 PM ============="
  Job #6: url=/printers/EPSON_TM_T20II format=application/vnd.cups-raw bytes=463 preview="DELIVERY SLIP Order #ORD-101 Type: Delivery Time: 6:16:29 PM ================================================ Alex River"
  Job #7: url=/printers/EPSON_TM_T20II format=application/vnd.cups-raw bytes=224 preview="FloCafe MAS Bistro Menu Oct 26, 2026, 6:16 PM --- Coffee --- Flat White...........................$4.50 Total items: 1 P"
  Job #8: url=/printers/EPSON_TM_T20II format=application/vnd.cups-raw bytes=1411 preview="FloCafe MAS Bistro Z REPORT #1 ================================================ Date: 2026-10-26 Period start: 10/26/202"

=== Missing CUPS Queue (0x0406 client-error-not-found) via Live Express API ===
11. POST /api/printers/:id/test (missing queue) -> HTTP 502: {"error":"Printer queue \"Unconfigured_Mac_USB_Printer\" was not found in macOS Printers & Scanners. Add the USB printer in System Settings > Printers & Scanners and make sure the printer name in FloCafe matches the CUPS queue name.","detail":"Printer queue \"Unconfigured_Mac_USB_Printer\" was not found in macOS Printers & Scanners. Add the USB printer in System Settings > Printers & Scanners and make sure the printer name in FloCafe matches the CUPS queue name."}
12. POST /api/printers/print-bill (missing queue) -> HTTP 502: {"error":"Printer queue \"Unconfigured_Mac_USB_Printer\" was not found in macOS Printers & Scanners. Add the USB printer in System Settings > Printers & Scanners and make sure the printer name in FloCafe matches the CUPS queue name.","detail":"Printer queue \"Unconfigured_Mac_USB_Printer\" was not found in macOS Printers & Scanners. Add the USB printer in System Settings > Printers & Scanners and make sure the printer name in FloCafe matches the CUPS queue name.","failure_class":"not_configured","code":"print.receipt.failed","correlation_id":"f9a2078b-90f6-461a-ac71-adce0de1601c","stage":"dispatch","warnings":[]}
![Settings > Printers manual USB form showing amber queue-name mismatch warning when 0 OS printers are detected](https://github.com/user-attachments/assets/d374df07-18fe-4f50-af83-857cfcd56be7) ![Settings > Printers Test Print toast surfacing actionable macOS System Settings > Printers & Scanners guidance on IPP 0x0406](https://github.com/user-attachments/assets/32d21426-43b5-4e9e-8a88-965303336a7b) ![Settings > Printers USB edit form suppressing false queue-name mismatch warning when /api/printers/detect fails (HTTP 500)](https://github.com/user-attachments/assets/3f3ec0d3-5d53-415d-b496-8c6bbd229319) ![Settings > Printers showing detected EPSON_TM_T20II USB queue over CUPS UNIX socket and successful Test Print toast](https://github.com/user-attachments/assets/493ca3c7-3227-4df6-944b-33cde5d44afb)

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 - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Under macOS App Sandbox (application.sb), outbound TCP to localhost:631 is blocked with EPERM while FloCafe's IPP client connects over UNIX socket /private/var/run/cupsd to the real macOS cupsd daemon ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/macos-sandbox-and-ipp-live.txt
On macOS MAS runtime (MAS_BUILD=1), USB printer detection and all 8 USB print entry points (test print, active test print, cash drawer kick, receipt bill, KOT, delivery slip, menu, and Z-report) route… ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/mas-usb-print-entry-points-live.txt
Printing to a USB printer whose queue name does not exist in macOS CUPS returns IPP status 0x0406 (client-error-not-found), classifies as failureClass 'not_configured', and surfaces actionable System… ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/usb-missing-cups-queue-toast.png
Adversarial transport & RFC 8011 status check: missing UNIX socket (ENOENT) switches to loopback TCP inside the ECONNREFUSED retry loop and succeeds when the TCP listener comes up on retry, and IPP 0x… ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/macos-sandbox-and-ipp-live.txt
Settings > Printers shows the amber queue-name mismatch warning for a manual USB printer even when 0 printers are detected, clears it when the name matches a detected CUPS queue, and suppresses false… ✅ pass live ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/usb-mismatch-warning-zero-detected.png, ~/.no-mistakes/evidence/01M5X3SPK4TMV7A9978J96WK43/usb-no-false-misma…
  • ./node_modules/.bin/ts-node --transpile-only -P tests/tsconfig.json tests/ipp-client.test.ts
  • npm run test:printer
  • npm run test:script-coverage
  • npm run build && npm run build:frontend
  • Live macOS /private/var/run/cupsd and /usr/bin/sandbox-exec (application.sb network rules) verification of ippGetPrinters, ippGetDefaultPrinterName, ippGetPrinterAttributes, printViaUSB, ENOENT -> ECONNREFUSED retry fallback, and 0x0506 vs 0x0508 status handling
  • Live Express API + SQLite + UNIX domain socket CUPS IPP verification under MAS_BUILD=1 across GET /api/printers/detect, POST /api/printers/:id/test, POST /api/printers/test-active, POST /api/printers/kick-drawer, POST /api/printers/print-bill, POST /api/printers/print-kot, POST /api/printers/print-delivery-slip, POST /api/printers/print-menu, and POST /api/cash-closures/:id/print
  • Live browser verification in Playwright of Settings > Printers (PrintersSettingsTab.tsx) across 0 detected printers, failed /api/printers/detect (HTTP 500), missing CUPS queue (0x0406) Test Print error toast, and detected EPSON_TM_T20II USB queue Test Print success
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Oct 26, 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

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix Mac App Store USB printing through the CUPS socket

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Route Mac App Store USB printing through sandbox-permitted CUPS IPP instead of shelling out to
 lp.
• Preserve raw ESC/POS output and provide actionable guidance when a CUPS queue is missing.
• Add mock-server coverage and document macOS printer setup.
Diagram

graph TD
  A["USB print entry"] --> B["USB dispatch"] --> C["MAS runtime"] --> D["IPP client"] --> E["CUPS socket"] --> G["CUPS queue"]
  E -- "ENOENT" --> F["TCP fallback"] --> G
  G -- "missing queue" --> H["Actionable failure"]
Loading
High-Level Assessment

Keep the shared printViaUSB routing and existing minimal IPP client: they cover USB print callers without duplicating dispatch logic. Continuing to use lp or relying on loopback TCP alone would not address the stated Mac App Store sandbox restrictions; a separate IPP dependency would add scope for this targeted fix.

Files changed (7) +793 / -100

Bug fix (3) +339 / -95
PrintersSettingsTab.tsxWarn about unmatched USB printer names without detections +2/-1

Warn about unmatched USB printer names without detections

• Shows the name-mismatch warning for a configured USB printer even when detection returns no printers, while suppressing it during detection.

frontend/src/components/settings/PrintersSettingsTab.tsx

ipp-client.tsUse socket-based CUPS IPP and raw print jobs +298/-76

Use socket-based CUPS IPP and raw print jobs

• Defaults to the local CUPS UNIX socket, with TCP fallback on ENOENT and configurable test endpoints. Sends CUPS raw jobs, improves response parsing, and formats actionable IPP status errors.

main/printers/ipp-client.ts

thermal.tsRoute Mac App Store USB printing through IPP +39/-18

Route Mac App Store USB printing through IPP

• Moves Mac App Store routing into printViaUSB so callers use local IPP rather than the command-line CUPS path. Classifies IPP failures, including missing queues as not_configured.

main/printers/thermal.ts

Documentation (2) +13 / -4
printing.mdDescribe Mac App Store CUPS socket transport +1/-1

Describe Mac App Store CUPS socket transport

• Updates the transport reference to describe UNIX-socket IPP, loopback fallback, and the raw document format used for sandboxed printing.

docs/architecture/printing.md

printers.mdDocument macOS CUPS queue setup +12/-3

Document macOS CUPS queue setup

• Explains that macOS USB printers need an OS print queue and that FloCafe must use its exact queue name. Adds setup steps and points transport details to the architecture guide.

docs/printers.md

Other (2) +441 / -1
package.jsonInclude IPP tests in the printer test suite +1/-1

Include IPP tests in the printer test suite

• Adds the new IPP client test file to the test:printer script.

package.json

ipp-client.test.tsCover CUPS IPP transport and Mac App Store dispatch +440/-0

Cover CUPS IPP transport and Mac App Store dispatch

• Adds request, response, and error-mapping checks plus UNIX-socket and TCP-fallback mock-server tests. Verifies raw payload delivery, Mac App Store USB routing without lp/lpstat, and missing-queue classification.

tests/ipp-client.test.ts

@qodo-code-review

qodo-code-review Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Ticket lacks Mac printing reproduction results ✓ Resolved
Description
The pull request adds simulated CUPS tests and setup instructions but does not record results from
testing the Mac App Store build with or without a CUPS queue. The ticket therefore lacks the
requested FloCafe diagnostics and /var/log/cups/error_log output for either real-device scenario.
Code

tests/ipp-client.test.ts[R331-347]

+  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'flo-ipp-test-'));
+  const socketPath = path.join(tmpDir, 'cupsd.sock');
+  const unixServer = http.createServer(handler);
+  const tcpServer = http.createServer(handler);
+
+  const originalPlatform = process.platform;
+  const originalMasEnv = process.env.MAS_BUILD;
+  const originalPath = process.env.PATH;
+
+  try {
+    await new Promise<void>((resolve) => unixServer.listen(socketPath, resolve));
+    await new Promise<void>((resolve) => tcpServer.listen(0, '127.0.0.1', resolve));
+    const tcpPort = (tcpServer.address() as { port: number }).port;
+
+    // 1. Direct UNIX domain socket transport test
+    setIppEndpointForTesting({ socketPath });
+    const printers = await ippGetPrinters();
Relevance

●●● Strong

The PR explicitly targets a device-reproduction issue but records only mocks and setup guidance, not
requested diagnostics.

PR-#1129

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance ID 4229624 requires real Mac App Store reproduction results for both the configured-queue
and no-queue scenarios, including diagnostics and CUPS logs. The added test uses temporary local
mock servers and the documentation only describes setup; neither provides evidence of real-device
outcomes or the requested ticket diagnostics.

Record Mac App Store USB printing reproduction results
tests/ipp-client.test.ts[331-347]
tests/ipp-client.test.ts[401-426]
docs/printers.md[197-204]

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 change adds loopback mock-server coverage but does not provide the required Mac App Store USB printer reproduction results, FloCafe diagnostics, or CUPS error log output in the issue.

## Fix Focus Areas
- tests/ipp-client.test.ts[331-347]
- docs/printers.md[197-204]

## Recommended Fix
Test the signed Mac App Store build with a USB ESC/POS printer configured as a Generic/raw CUPS queue and again without a CUPS queue. Record both outcomes in issue #1347, including the relevant FloCafe diagnostics and `/var/log/cups/error_log` output.

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



Remediation recommended

2. Failed detection warns about valid names ✓ Resolved
Description
fetchDetectedPrinters turns a detection error into an empty list, while the new USB warning
condition treats an empty list as evidence that the entered name does not match. If printer
detection fails while someone adds or edits a USB printer, the form displays the mismatch warning
without having checked that name against any printers.
Code

frontend/src/components/settings/PrintersSettingsTab.tsx[R621-622]

+                    !detectingPrinters &&
+                    (printerForm.connection_type === 'usb' || detectedPrinters.length > 0) &&
Relevance

●●● Strong

Failed detection is incorrectly presented as a confirmed name mismatch; accepted history favors
explicit load-failure handling.

PR-#1306

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The catch handler stores an empty list and the finally handler clears the loading flag. Those values
satisfy the newly added USB condition for any nonempty name; the warning text asserts that the name
does not match a detected printer.

frontend/src/components/settings/PrintersSettingsTab.tsx[221-231]
frontend/src/components/settings/PrintersSettingsTab.tsx[619-625]
frontend/src/lib/i18n/messages/en.json[2246-2246]

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 USB name warning cannot distinguish a successful empty detection result from a failed detection request.
## Fix Focus Areas
- frontend/src/components/settings/PrintersSettingsTab.tsx[183-186]
- frontend/src/components/settings/PrintersSettingsTab.tsx[221-231]
- frontend/src/components/settings/PrintersSettingsTab.tsx[619-625]
## Recommended Fix
Track whether detection completed successfully separately from the detected list, and show the empty-list USB warning only after a successful check. Handle detection errors with their own state or message.

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


3. Canceled jobs appear to need queue repair ✓ Resolved
Description
IPP_STATUS_SERVER_ERROR_NOT_ACCEPTING_JOBS assigns 0x0508 to a queue that is not accepting jobs,
but that status means the job was canceled; the not-accepting status is 0x0506. When CUPS returns
0x0508 for a print job, formatIppStatusError gives users the wrong explanation and
classifyPrintFailure records it as queue_unavailable.
Code

main/printers/ipp-client.ts[40]

+export const IPP_STATUS_SERVER_ERROR_NOT_ACCEPTING_JOBS = 0x0508;
Relevance

●●● Strong

The constant maps a standards-defined canceled-job code to the wrong user-facing failure category.

PR-#640

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
RFC 8011 assigns 0x0506 to not-accepting-jobs and 0x0508 to job-canceled. The new formatter turns
the latter into a not-accepting message, which the failure classifier maps to queue_unavailable.

main/printers/ipp-client.ts[37-40]
main/printers/ipp-client.ts[221-240]
main/printers/thermal.ts[280-291]
🌐 RFC 8011 lists server-error-not-accepting-jobs as 0x0506 and server-error-job-canceled as 0x0508.

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 not-accepting-jobs constant uses the job-canceled status, causing canceled jobs to receive queue-repair guidance.
## Fix Focus Areas
- main/printers/ipp-client.ts[37-40]
- tests/ipp-client.test.ts[190-218]
## Recommended Fix
Set the not-accepting-jobs constant to 0x0506, add a distinct mapping for 0x0508 if needed, and test both statuses and their resulting classifications.

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


4. A transient fallback refusal stops printing ✓ Resolved
Description
ippRequest immediately returns the TCP request from its ENOENT handler, placing that request
outside the retry handling for ECONNREFUSED. If the CUPS socket is absent and the fallback TCP
listener briefly refuses a connection, detection and USB printing fail after one TCP attempt rather
than using the remaining retries.
Code

main/printers/ipp-client.ts[R295-298]

+      if (code === 'ENOENT' && !useTcpFallback && canFallbackToTcp() && !signal?.aborted) {
+        useTcpFallback = true;
+        return await ippRequestOnce(
+          path,
Relevance

●●● Strong

Fallback refusal bypasses existing retries, creating a concrete transient-failure reliability
regression.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The fallback request is awaited within the catch block, so its rejection cannot reach the following
ECONNREFUSED check. The new fallback test uses an already-listening TCP server and does not exercise
this sequence.

main/printers/ipp-client.ts[281-308]
tests/ipp-client.test.ts[340-363]

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

## Issue description
An ECONNREFUSED from the TCP fallback escapes the retry loop after a missing socket.
## Fix Focus Areas
- main/printers/ipp-client.ts[281-308]
- tests/ipp-client.test.ts[340-363]
## Recommended Fix
On socket ENOENT, select the TCP endpoint for subsequent loop attempts without returning from the catch block. Add a test where the first TCP attempt is refused and a later attempt succeeds.

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


View medium (1)
5. Printer test suite breaks on Windows CI runs ✓ Resolved
Description
testMockCupsServerAndMasDispatch calls unixServer.listen(socketPath) with a normal temp-file
path and has no error listener on that server. On Windows, Node treats a path passed to listen()
as a named pipe, and a plain C:\...\cupsd.sock path is not a valid pipe name. The listen call
therefore emits an unhandled error, and test:printer fails, which is now part of the Windows `npm
test` shard in the nightly cross-platform matrix.
Code

package.json[129]

+    "test:printer": "ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts && ts-node --transpile-only -P tests/tsconfig.json tests/ipp-client.test.ts && npm run test:printer-api && npm run test:print-menu-printer-selection && npm run test:printer-ipc",
Relevance

●●● Strong

The newly wired suite can crash on Windows due to unsupported Unix socket behavior without error
handling.

PR-#1124

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
test:printer now runs tests/ipp-client.test.ts (patch lines 331-342), which binds an HTTP server
to path.join(os.tmpdir(), 'flo-ipp-test-…', 'cupsd.sock') with no Windows guard. The full matrix
runs on windows-latest and calls run-test-shard.cjs, which runs every npm run test:* suite
listed in the test script, test:printer included.

.github/workflows/full-cross-platform-matrix.yml[83-93]
scripts/ci/run-test-shard.cjs[49-78]
package.json[129-129]

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 in tests/ipp-client.test.ts binds an http server to a filesystem UNIX socket path. Windows needs named pipes for this, so the listen fails and nothing handles the error. That test runs as part of `test:printer` in the Windows nightly shard.

## Fix Focus Areas
- tests/ipp-client.test.ts[331-360]

## Recommended Fix
On `process.platform === 'win32'`, skip the UNIX socket parts: use only the TCP server with `setIppEndpointForTesting({ socketPath: null, host: '127.0.0.1', port })`, or use a `\\?\pipe\flo-ipp-test-<pid>` path. Attach `once('error', reject)` handlers to both servers' listen promises so a failed listen rejects instead of crashing the test.

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


Grey Divider

Context sources
⚠️ Tickets: not configured — No jira, linear integration is connected for the linked tickets
✅ Compliance rules (platform): 5 rules
✅ Web pages:
  +12 more
✅ Cross-repo context — repo relationships
  Explored: repo: FreeOpenSourcePOS/flopos.com (sha: a2f87d48) — View relationship
Review mode: Auto: 🧠 Deep: Substantial cross-file transport, protocol, routing, and error-handling logic has many independent defect risks.

Grey Divider

Tip of the day
💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread tests/ipp-client.test.ts Resolved
Comment thread main/printers/ipp-client.ts Resolved
Comment thread main/printers/ipp-client.ts Resolved
Comment thread package.json Resolved
Connect to local macOS CUPS over /private/var/run/cupsd by default (with loopback TCP 127.0.0.1:631 fallback on ENOENT) so sandboxed Mac App Store builds are permitted by application.sb under com.apple.security.print and wake cupsd via launchd socket activation.

Route printViaUSB() through printViaLocalIpp() on MAS darwin, send document-format application/vnd.cups-raw for lp -o raw parity, map IPP 0x0406 missing-queue errors to actionable System Settings > Printers & Scanners guidance (failureClass: not_configured), and add unit/mock-server coverage in tests/ipp-client.test.ts.

Fixes #1347
Use RFC 8011 0x0506 for IPP_STATUS_SERVER_ERROR_NOT_ACCEPTING_JOBS and 0x0508 for IPP_STATUS_SERVER_ERROR_JOB_CANCELED, keep UNIX socket ENOENT fallback inside the ECONNREFUSED retry loop, gate the empty-list USB queue-name mismatch warning on successful detection, guard Windows CI against filesystem socket listen errors, and document macOS CUPS queue verification details.
@khaira777
khaira777 force-pushed the fm/flocafe-1347-mas-cups-ipp-scout branch from 0d31eee to 1298553 Compare October 26, 2026 22:28
@khaira777
khaira777 enabled auto-merge (squash) October 26, 2026 22:37
@khaira777
khaira777 merged commit 9b27bea into main Oct 26, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-1347-mas-cups-ipp-scout branch October 26, 2026 22:45
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.

bug(macos): Mac App Store USB printing via CUPS/IPP (needs device repro)

1 participant