fix: send multipart content_type before the file part on asset upload#13
Conversation
public-api streams the multipart upload and requires content_type (and the other metadata fields) to arrive before the file part, or it rejects with 422 "content_type is required and must be sent before the file field". The SDK appended `file` first, so every asset upload against public-api failed. Append the metadata fields (content_type, file_path, expected_hash, tags) first and `file` last. The stub server now enforces the same ordering, so the existing upload tests guard against a regression. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 57 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: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Warning
|
| Layer / File(s) | Summary |
|---|---|
Multipart ordering and validation src/low/transport.ts, test/support/stub-server.ts, src/low/transport.test.ts |
postAssets appends metadata before file; the stub returns 422 invalid_body when content_type is missing or follows file; the test verifies a successful upload and one recorded request. |
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
fix/multipart-order-and-notfound
✨ Simplify code
- Create PR with simplified code
- Commit simplified code in branch
fix/multipart-order-and-notfound
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 @coderabbitai help to get the list of available commands.
public-api returns entity-specific 404 error codes (job_not_found, asset_not_found) even though the spec documents the generic not_found, so a missing job/asset surfaced as a bare ApiError instead of the typed NotFound the SDK promises. Map both to NotFound. (Server/spec reconciliation of the code set is a separate follow-up.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@test/support/stub-server.ts`:
- Around line 390-393: Update the multipart ordering validation around the body
field searches to inspect only parsed multipart Content-Disposition field names,
not arbitrary body content. Extract the ordered headers with a multipart parser
or equivalent and enforce that the file field precedes content_type only when
those actual fields are present, preserving the existing malformed-request
rejection behavior.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 16107771-8b44-4141-91da-185565a94985
📒 Files selected for processing (3)
src/low/transport.test.tssrc/low/transport.tstest/support/stub-server.ts
Asset upload against public-api failed with:
public-api streams the multipart upload and needs
content_type(and the other metadata fields) to arrive before thefilepart so it can route the file stream without buffering.postAssetsappendedfilefirst.Fix: append the metadata fields (
content_type,file_path,expected_hash,tags) first andfilelast. The stub server now rejects afile-before-content_typebody (mirroring public-api), so the existingpostAssetstests guard against a regression.vitest112/112,tsc/oxfmt/hygiene clean.🤖 Generated with Claude Code