Skip to content

Add integration tests for authServerRef on MCPServer and MCPRemoteProxy#4708

Open
tgrunnagle wants to merge 6 commits intomainfrom
issue_4641_authServerRef-e2e
Open

Add integration tests for authServerRef on MCPServer and MCPRemoteProxy#4708
tgrunnagle wants to merge 6 commits intomainfrom
issue_4641_authServerRef-e2e

Conversation

@tgrunnagle
Copy link
Copy Markdown
Contributor

@tgrunnagle tgrunnagle commented Apr 9, 2026

Summary

The authServerRef CRD and controller logic (#4640) lacks verification that reconciliation works correctly end-to-end -- from resource creation through condition updates to ConfigMap generation. This PR adds envtest-based integration tests that exercise the full operator reconciliation path for both MCPServer and MCPRemoteProxy resources using the new authServerRef field.

Integration tests (envtest) are the right fit here because the tests verify reconciliation-level behavior (conditions, ConfigMap content, phase transitions) rather than runtime behavior requiring real pods.

Closes #4641

Type of change

  • New feature

Test plan

  • Integration tests (task operator-test-integration)
  • Linting (task lint-fix)

Changes

File Change
cmd/thv-operator/test-integration/mcp-server/mcpserver_authserverref_integration_test.go MCPServer integration tests: happy path (condition + ConfigMap), conflict detection (Failed phase + error message), type mismatch (Failed phase + condition), backward compatibility (legacy externalAuthConfigRef)
cmd/thv-operator/test-integration/mcp-server/suite_test.go Register MCPOIDCConfigReconciler (needed for authServerRef tests that use OIDCConfigRef)
cmd/thv-operator/test-integration/mcp-remote-proxy/mcpremoteproxy_authserverref_integration_test.go MCPRemoteProxy integration tests: happy path, combined auth (embedded + AWS STS), conflict detection, type mismatch, backward compatibility
cmd/thv-operator/test-integration/mcp-remote-proxy/suite_test.go Register MCPOIDCConfigReconciler
cmd/thv-operator/test-integration/mcp-remote-proxy/remoteproxy_helpers.go Add WithAuthServerRef and WithOIDCConfigRef builder methods

Special notes for reviewers

  • The MCPRemoteProxy conflict test uses Consistently to verify the proxy never reaches Ready, rather than waiting for Failed phase. This matches actual controller behavior: the MCPRemoteProxy controller returns the conflict error to controller-runtime for requeue rather than setting a terminal Failed phase.
  • The combined auth test (authServerRef with embeddedAuthServer + externalAuthConfigRef with awsSts) is the primary use case motivating RFC-0050 and verifies both embedded_auth_server_config and aws_sts_config keys exist in the RunConfig ConfigMap.
  • WithOIDCConfigRef clears the default inline OIDCConfig since the CRD enforces mutual exclusivity between oidcConfig and oidcConfigRef.

Generated with Claude Code

@github-actions github-actions bot added the size/XL Extra large PR: 1000+ lines changed label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@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.

Large PR Detected

This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.

How to unblock this PR:

Add a section to your PR description with the following format:

## Large PR Justification

[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformation

Alternative:

Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.

See our Contributing Guidelines for more details.


This review will be automatically dismissed once you add the justification section.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 9, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4708      +/-   ##
==========================================
+ Coverage   68.60%   68.68%   +0.08%     
==========================================
  Files         516      517       +1     
  Lines       54490    54817     +327     
==========================================
+ Hits        37381    37653     +272     
- Misses      14219    14270      +51     
- Partials     2890     2894       +4     

☔ 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.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 9, 2026
@tgrunnagle tgrunnagle marked this pull request as ready for review April 9, 2026 18:15
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 9, 2026
@github-actions github-actions bot dismissed their stale review April 9, 2026 18:17

Large PR justification has been provided. Thank you!

@github-actions github-actions bot removed the size/XL Extra large PR: 1000+ lines changed label Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review.

@github-actions github-actions bot added the size/XL Extra large PR: 1000+ lines changed label Apr 9, 2026
Base automatically changed from issue_4640_authServerRef to main April 9, 2026 18:39
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 9, 2026
tgrunnagle and others added 4 commits April 9, 2026 11:40
Implements E2E test suite for issue #4641 covering the authServerRef
field on both MCPServer and MCPRemoteProxy resources:

MCPServer tests:
- Happy path: authServerRef -> Ready phase, ConfigMap has embedded_auth_server_config
- Conflict: authServerRef + externalAuthConfigRef both embeddedAuthServer -> Failed
- Type mismatch: authServerRef to unauthenticated -> Failed with condition message
- Backward compatibility: externalAuthConfigRef only -> Ready phase

MCPRemoteProxy tests:
- Happy path: authServerRef -> Ready phase, ConfigMap has embedded_auth_server_config
- Combined auth: authServerRef (embedded) + externalAuthConfigRef (awsSts) -> Ready
  with both embedded_auth_server_config and aws_sts_config in ConfigMap
- Conflict: both refs to embeddedAuthServer -> Failed
- Type mismatch: authServerRef to unauthenticated -> Failed with condition message
- Backward compatibility: externalAuthConfigRef only -> Ready phase

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add MCPOIDCConfig resources and OIDCConfigRef to all happy path and
  backward compatibility tests (required for embedded auth server)
- Add conflict message assertions to both MCPServer and MCPRemoteProxy
  conflict tests to distinguish correct failures
- Add expectedStatus parameter to condition helper functions so tests
  verify both Status and Message fields
- Fix empty message substring in AuthServerRefValidated assertion to
  check for "is valid" with ConditionTrue status
- Add AuthServerRefValidated condition check to MCPRemoteProxy happy path
- Add ConfigMap verification to backward compatibility tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The conflict E2E tests incorrectly asserted AuthServerRefValidated=False,
but the controller sets it to True (individual ref validation passes in
handleAuthServerRef) before the conflict is detected in runconfig generation.

MCPServer conflict test: check Status.Message for the conflict error instead
of the AuthServerRefValidated condition, since the error is surfaced via
Phase=Failed + Status.Message.

MCPRemoteProxy conflict test: the controller does not set Phase=Failed for
ensureAllResources errors (it requeues instead). Assert the proxy never
reaches Ready and that AuthServerRefValidated=True.
Embedded auth server tests cannot reach Ready/Running phase in the test
cluster because the pods crash-loop with fake OIDC credentials. Instead,
assert that the operator correctly sets AuthServerRefValidated conditions
and generates the expected RunConfig ConfigMap entries, which verifies
the full reconciliation path through config generation.

Also add OIDCConfigRef to conflict tests so the reconciler reaches the
conflict detection step instead of failing earlier on missing OIDC config.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tgrunnagle tgrunnagle force-pushed the issue_4641_authServerRef-e2e branch from d47b6e8 to d040d02 Compare April 9, 2026 18:40
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 9, 2026
@ChrisJBurns
Copy link
Copy Markdown
Collaborator

@tgrunnagle I'd probably opt for putting these in the integration test folder. They are a lot less flaky than the E2E tests and are faster due to not needing to wait for a Kind cluster. For reconciliation they are perfect. The E2E tests I believe are moreso for being able to test the whole reconcilition and request/response flow for MCP servers

Move the authServerRef tests to envtest-based integration suites under
cmd/thv-operator/test-integration/ where they belong. Integration tests
exercise the full reconciliation path (conditions, ConfigMap generation,
conflict detection) without needing a real cluster or running pods.

- Add MCPServer tests to mcp-server/ integration suite
- Add MCPRemoteProxy tests to mcp-remote-proxy/ integration suite
- Register MCPOIDCConfigReconciler in both test suites
- Add WithAuthServerRef/WithOIDCConfigRef builder methods
- Remove E2E test/e2e/thv-operator/authserver/ directory

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tgrunnagle tgrunnagle changed the title Add E2E tests for authServerRef on MCPServer and MCPRemoteProxy Add integration tests for authServerRef on MCPServer and MCPRemoteProxy Apr 9, 2026
@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/XL Extra large PR: 1000+ lines changed size/L Large PR: 600-999 lines changed labels Apr 9, 2026
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.

Overall this is solid test code with good scenario coverage. One suggestion below.

The Eventually on a negative condition (phase != Failed) passed on the
first poll because Phase starts as "" before reconciliation. Since the
test is Ordered and the prior It already waits for the ConfigMap, a
simple Expect suffices.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Apr 9, 2026
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.

I meant to ack, sorry, the inline comments are nits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add E2E tests for authServerRef on MCPServer and MCPRemoteProxy

4 participants