fix(serve): preserve response status through wrap_full_page middleware#213
Merged
fix(serve): preserve response status through wrap_full_page middleware#213
Conversation
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>
📐 Rivet artifact deltaNo artifact changes in this PR. Code-only changes (renderer, CLI wiring, tests) don't touch the artifact graph. |
There was a problem hiding this comment.
⚠️ 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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
/review-pr |
1 similar comment
Contributor
Author
|
/review-pr |
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
wrap_full_pagemiddleware inrivet-cli/src/serve/mod.rsso 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 fromviews::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() = statusafter building the wrapped response.Likely cascade-fixes (Playwright triage)
serve-variant.spec.ts:67(fix: remove duplicate cargo-audit hook, dogfood commit traceability #9 — unknown-variant 400-style error page)serve-variant.spec.ts:25(docs: add phase 2.5 features and CLI tests #4 — variant selection navigation)filter-sort.spec.ts:225(docs: unidirectional external repo imports design + plan #10 —?q=push-url; the middleware was also potentially clobbering response headers, verify post-fix)Test plan
cargo build --release -p rivet-cli— cleancargo clippy -p rivet-cli— cleancargo test --release -p rivet-cli --test serve_integration— 37/37 passcargo run --release -- serve --port 3099 &curl -i 'http://localhost:3099/artifacts?variant=does-not-exist' | head -3→ expectHTTP/1.1 400(was 200)curl -i 'http://localhost:3099/artifacts' | head -3→ stillHTTP/1.1 200serve-variant.spec.tscases :25 and :67 expected green post-fix.🤖 Generated with Claude Code