Skip to content

fix(serve): preserve response status through wrap_full_page middleware#213

Merged
avrabe merged 1 commit intomainfrom
fix/serve-middleware-status
Apr 25, 2026
Merged

fix(serve): preserve response status through wrap_full_page middleware#213
avrabe merged 1 commit intomainfrom
fix/serve-middleware-status

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented Apr 25, 2026

Summary

Fix wrap_full_page middleware in rivet-cli/src/serve/mod.rs so it preserves the inner handler's HTTP status when re-wrapping the response body in the page layout.

The middleware consumed the response body and rebuilt the response via layout::page_layout_with_variant(...).into_response(), which defaults to 200. As a result, every non-200 status (notably the 400 from views::variant_error_response) silently became a 200 with an error-looking page — wrong HTTP semantics for callers, broken error-handling assertions in tests.

Patch is minimal: capture response.status() before draining the body, then re-apply via *wrapped.status_mut() = status after building the wrapped response.

Likely cascade-fixes (Playwright triage)

Test plan

  • cargo build --release -p rivet-cli — clean
  • cargo clippy -p rivet-cli — clean
  • cargo test --release -p rivet-cli --test serve_integration — 37/37 pass
  • Local curl smoke (run by reviewer or CI):
    • cargo run --release -- serve --port 3099 &
    • curl -i 'http://localhost:3099/artifacts?variant=does-not-exist' | head -3 → expect HTTP/1.1 400 (was 200)
    • curl -i 'http://localhost:3099/artifacts' | head -3 → still HTTP/1.1 200
  • CI — Playwright serve-variant.spec.ts cases :25 and :67 expected green post-fix.

🤖 Generated with Claude Code

The wrap_full_page middleware (rivet-cli/src/serve/mod.rs) consumed the
inner response body without preserving the status code, then rebuilt
the response via .into_response() which defaults to 200. This silently
turned every non-200 status (notably the 400 from variant_error_response)
into a 200 with an error-looking layout — broke error-handling tests
and gave callers wrong HTTP semantics.

Capture response.status() before consuming the body, then re-apply via
*wrapped.status_mut() = status after building the layout response.

Likely cascade-fixes Playwright tests:
- serve-variant.spec.ts:67 (unknown variant 400-style error page)
- serve-variant.spec.ts:25 (variant selection navigation)
- filter-sort.spec.ts:225 (?q= push-url) — middleware was potentially
  also stripping HX-Push-Url; verify post-fix.

Implements: REQ-007
Verifies: REQ-007

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

📐 Rivet artifact delta

No artifact changes in this PR. Code-only changes (renderer, CLI wiring, tests) don't touch the artifact graph.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rivet Criterion Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 36e04cf Previous: c7d5664 Ratio
link_graph_build/10000 35223858 ns/iter (± 3004868) 27390081 ns/iter (± 279307) 1.29
traceability_matrix/1000 61149 ns/iter (± 868) 43287 ns/iter (± 135) 1.41
query/10000 119636 ns/iter (± 992) 91697 ns/iter (± 323) 1.30

This comment was automatically generated by workflow using github-action-benchmark.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@avrabe avrabe merged commit 8fa6686 into main Apr 25, 2026
21 of 25 checks passed
@avrabe avrabe deleted the fix/serve-middleware-status branch April 25, 2026 22:10
@avrabe
Copy link
Copy Markdown
Contributor Author

avrabe commented Apr 26, 2026

/review-pr

1 similar comment
@avrabe
Copy link
Copy Markdown
Contributor Author

avrabe commented Apr 27, 2026

/review-pr

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