Refactor raw print delivery#278
Conversation
📝 WalkthroughWalkthroughIntroduces a new ChangesRaw-print Delivery abstraction and backend adapters
Sequence Diagram(s)sequenceDiagram
participant IPC as IPC Handler
participant sendRawPrint
participant withTimeout
participant Delivery as Delivery (TCP/Serial/USB/Winspool)
IPC->>sendRawPrint: sendRawPrint({ data }, delivery)
sendRawPrint->>sendRawPrint: validateRawPrintData → rawPrintBufferFromData
sendRawPrint->>withTimeout: run=(ctx => delivery.send(bytes, ctx)), cleanup, timeoutMs
rect rgba(70, 130, 180, 0.5)
note over withTimeout,Delivery: Normal path
withTimeout->>Delivery: send(bytes, ctx)
Delivery-->>withTimeout: resolved
withTimeout->>Delivery: cleanup()
withTimeout-->>sendRawPrint: resolved
sendRawPrint->>sendRawPrint: log successMessage
sendRawPrint-->>IPC: resolved
end
rect rgba(200, 80, 80, 0.5)
note over withTimeout,Delivery: Timeout path
withTimeout->>withTimeout: timer fires → reject(timeoutMessage)
withTimeout->>Delivery: cleanup()
withTimeout-->>sendRawPrint: rejected
sendRawPrint->>sendRawPrint: log failureMessage, rethrow
sendRawPrint-->>IPC: rejected
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b1dd7e201
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }, | ||
| (err) => { | ||
| if (settled) { | ||
| if (timedOut) void runCleanup().catch(() => {}); |
There was a problem hiding this comment.
Avoid re-entering cleanup after timeout
When a timeout fires during an async operation that cleanup itself aborts, such as USB out.transfer while createUsbDelivery.cleanup() is still awaiting iface.release(), the operation can reject before the first cleanup has finished and this branch starts a second runCleanup() immediately. Because the USB cleanup only flips ifaceClaimed/deviceOpened after release/close completes, this can call release/close concurrently on the same device after a timeout, making retries unreliable; serialize the cleanup promise or make the delivery cleanup idempotent before rerunning it.
Useful? React with 👍 / 👎.
Summary
raw-printmodule for byte validation, Buffer conversion, timeout/cleanup handling, ghost-print cleanup, and raw-print logging.test:raw-printto cover the shared timeout/cleanup state machine and wire it into the Electron test chain.Design decisions (preserve through rebases)
usblpdetach, and release+close cleanup.printConfig.timeoutMsstays mutable and is read when creating the serial delivery — existing tests can still shrink the serial timeout for the ghost-print branch.WCPOS_RAW_PRINT_PRINTERandWCPOS_RAW_PRINT_FILEenv vars — no user-controlled values are interpolated into the PowerShell script.Companion PRs / cross-repo
Test plan
pnpm ts:checkpnpm lint(passes with pre-existing warnings only)pnpm run test:serial-printerpnpm run test:winspool-printerpnpm run test:printer-discoverypnpm run test:raw-printpnpm test🤖 Generated with Claude Code