Skip to content

Fix deterministic E2E proxy SSE endpoint rewrite tests#4093

Merged
aponcedeleonch merged 1 commit intomainfrom
fix/e2e-proxy-sse-test-failures
Mar 11, 2026
Merged

Fix deterministic E2E proxy SSE endpoint rewrite tests#4093
aponcedeleonch merged 1 commit intomainfrom
fix/e2e-proxy-sse-test-failures

Conversation

@JAORMX
Copy link
Copy Markdown
Collaborator

@JAORMX JAORMX commented Mar 11, 2026

Summary

The SSE endpoint rewrite E2E tests (proxy && sse && endpoint-rewrite) fail 100% of the time. They were orphaned from CI until the matrix rebalance (#4074), then had stale flags fixed (#4080), but have never actually passed. This PR fixes four root causes identified through local reproduction and log inspection.

  • GenerateMCPServerURL omits /sse for remote SSE URLs with no path, so waitForInitializeSuccess sends GET / instead of GET /sse — the mock server returns 404, init retries for 5 min, and the test's 60s timeout expires
  • getSSERewriteConfig reads X-Forwarded-* headers from the outbound request, which has auto-injected values from SetXForwarded(), converting relative endpoint URLs (/sse?sessionId=...) into absolute URLs with the proxy's own host — breaking test 3's assertion
  • Test 3's mock server has no else clause for non-/sse paths (Go defaults to 200 OK), inconsistent with tests 1 and 2
  • Test 4 (OSV + --endpoint-prefix) fails because the proxy doesn't strip the prefix from incoming requests (Strip endpointPrefix from request paths in transparent proxy #3372); skipped with a reference to the tracking issue

Type of change

  • Bug fix

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)

Changes

File Change
pkg/transport/url.go Default to /sse path for remote SSE URLs with empty path
pkg/transport/url_test.go Update 2 expected values to include /sse
pkg/transport/proxy/transparent/sse_response_processor.go Add inbound request context helpers; read forwarded headers from inbound request instead of outbound
pkg/transport/proxy/transparent/transparent_proxy.go Stash inbound request in outbound context during Rewrite
pkg/transport/proxy/transparent/transparent_test.go Update TestGetSSERewriteConfig to pass inbound request via context
test/e2e/sse_endpoint_rewrite_test.go Add 404 fallback to test 3 mock; skip test 4 with #3372 reference

Special notes for reviewers

The core issue with Bug 3 is subtle: httputil.ReverseProxy.Rewrite calls pr.SetXForwarded() which writes X-Forwarded-Host, X-Forwarded-Proto, etc. onto pr.Out. Then in ModifyResponse, resp.Request is pr.Out — so getSSERewriteConfig was reading the proxy's own auto-injected headers rather than the client's original headers. The fix stashes pr.In (the original inbound request) in the outbound request's context so the response processor can read the real client headers.

Test 4 is skipped rather than fixed because the underlying issue (#3372 — endpoint prefix stripping for incoming requests) requires a separate design decision.

Generated with Claude Code

These SSE endpoint rewrite tests were orphaned from CI until the matrix
rebalance (#4074), then had stale flags fixed (#4080), but have never
actually passed. Four root causes are addressed:

1. GenerateMCPServerURL omits /sse for remote SSE URLs with empty path,
   causing waitForInitializeSuccess to GET / instead of /sse (404).
2. getSSERewriteConfig reads X-Forwarded-* from the outbound request
   which has auto-injected headers from SetXForwarded(), converting
   relative endpoint URLs into absolute ones with the proxy's own host.
3. Test 3 mock server lacks a 404 fallback for non-/sse paths.
4. Test 4 (OSV + endpoint-prefix) fails due to #3372; skip it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Mar 11, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.52%. Comparing base (fc85ac2) to head (9674519).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4093      +/-   ##
==========================================
- Coverage   68.52%   68.52%   -0.01%     
==========================================
  Files         447      447              
  Lines       45679    45691      +12     
==========================================
+ Hits        31300    31308       +8     
- Misses      11963    11966       +3     
- Partials     2416     2417       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

there are still some flaky tests but the one that was failing is not anymore

@aponcedeleonch aponcedeleonch merged commit d7f5dae into main Mar 11, 2026
94 of 97 checks passed
@aponcedeleonch aponcedeleonch deleted the fix/e2e-proxy-sse-test-failures branch March 11, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants