fix: save binary fetch responses to a file instead of corrupting them as text#62
Conversation
… as text Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 28 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe fetch command adds ChangesFetch response output
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant FetchCommand
participant Fetch402
participant FileSystem
User->>FetchCommand: Run fetch with optional --output
FetchCommand->>Fetch402: Pass request and outputPath
Fetch402->>Fetch402: Read bytes and classify response
Fetch402->>FileSystem: Write binary or forced output
FileSystem-->>Fetch402: Return output path and size
Fetch402-->>FetchCommand: Return content or file metadata
FetchCommand-->>User: Render fetch result
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/test/fetch-binary.test.ts`:
- Around line 75-76: Update the test case for the clean UTF-8 inline response to
stub a response without any Content-Type header, ensuring it exercises the
contentType === null path rather than application/octet-stream. Preserve the
existing valid UTF-8 body and inline-return assertions.
In `@src/tools/lightning/fetch.ts`:
- Around line 141-145: Update the response-saving flow around writeFileSync in
fetch so write failures are caught instead of propagated directly. When payment
credentials exist, throw a DetailedError that includes
paidRecoveryDetails(payment); preserve the existing write behavior and error
handling for responses without credentials.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d9eca5b6-63fe-4d9e-b1b3-e0b692c071a8
📒 Files selected for processing (3)
src/commands/fetch.tssrc/test/fetch-binary.test.tssrc/tools/lightning/fetch.ts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fixes #61
fetchread every successful response body withresponse.text(), which lossily UTF-8-decodes binary bodies (every invalid byte sequence becomes U+FFFD) and then returned the mangled string as JSONcontent. A paid WAV response arrived as ~50% replacement characters with no way to recover the original bytes - and no error, since the payment succeeded and the status was 200.Changes
arrayBuffer()) and decide text vs binary:text/*, JSON/XML, form-urlencoded) is returned inline ascontent, as beforeaudio/wav->.wav, unknown ->.bin), and the output carriesoutputPath,contentTypeandsizeBytesinstead ofcontent-o, --output <path>flag: saves any response body (text included) verbatim to the given path and returns the path, so an agent expecting a large output never round-trips it through stdoutpaymentobject in all casesA file was chosen over base64-in-JSON: the consumer almost always needs the binary as a file anyway (play it, upload it, feed it to ffmpeg), and base64 would add a manual decode step plus ~1.3x payload inflation.
Verification
src/test/fetch-binary.test.ts(binary saved byte-for-byte,.binfallback, declared-text stays inline, valid-UTF-8-without-content-type stays inline,-oforces a file); full suite passeshttps://voice.forgemesh.io/v1/tts/basethrough the l402.space bridge: the response is now saved as a playable.wavwhose size matches its RIFF header🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
-o, --output <path>to save fetched responses to a chosen file.Bug Fixes