feat(cloudflare): add vitest-pool-workers integration tests#678
Open
feat(cloudflare): add vitest-pool-workers integration tests#678
Conversation
55ef231 to
e153270
Compare
Set up @cloudflare/vitest-pool-workers for testing mcp-cloudflare routes with real Cloudflare bindings via Miniflare. Tests are organized into separate modules per route group: - static.integration.test.ts - robots.txt, llms.txt, SSE deprecation - mcp-discovery.integration.test.ts - /.mcp discovery endpoints - api-metadata.integration.test.ts - /api/metadata auth - api-search.integration.test.ts - /api/search validation and AI binding - api-auth.integration.test.ts - /api/auth/* status, logout - chat-oauth.integration.test.ts - OAuth callback error handling - api-chat.integration.test.ts - /api/chat auth Key configuration: - wrangler.test.jsonc with observability disabled for OTel compatibility - vitest.integration.config.ts using vitest-pool-workers - tsconfig.test.json with cloudflare:test module types Co-Authored-By: Claude Code <noreply@anthropic.com>
Tests the MCP endpoint behavior through OAuthProvider without Sentry wrapper: - Unauthenticated requests return 401 - Invalid Bearer tokens return 401 - OAuth discovery endpoint returns proper metadata - Dynamic client registration works at /oauth/register Uses OAuthProvider directly to avoid vitest-pool-workers compatibility issues with @sentry/cloudflare dependencies. Co-Authored-By: Claude Code <noreply@anthropic.com>
Replace the two-config approach (MSW for Node.js, workers pool for workerd) with a unified vitest-pool-workers config using fetchMock from cloudflare:test. Changes: - Create payloads.ts in mcp-server-mocks for MSW-free fixture exports - Add fetch-mock-setup.ts with comprehensive Sentry API mocking - Consolidate vitest.config.ts to use workers pool for all tests - Remove vitest.integration.config.ts (no longer needed) - Rename integration tests to standard .test.ts naming - Extract inline payload constants to JSON fixture files Key fix: fetchMock requires explicit Content-Type headers in reply() for the API client to properly parse JSON responses. Note: mcp-handler.test.ts excluded from workers pool due to CJS dependency (ajv) incompatibility with workerd runtime. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Refactor mcp-handler.test.ts to properly test the MCP handler without mocking agents/mcp. Tests now exercise the real handler with fetchMock for Sentry API mocking only. Key changes: - Add ajv-stub.ts to bypass CJS require() issues in workerd - Configure vitest with resolve.alias and ssr.noExternal for ajv - Add jsonSchemaValidator option to buildServer() for edge runtimes - Use CfWorkerJsonSchemaValidator in mcp-handler for workerd compat - Parse SSE responses in tests (MCP handler returns SSE format) - Fix Accept header and initialize params for MCP protocol 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Delete mcp-endpoint.test.ts as it tested third-party library behavior (@cloudflare/workers-oauth-provider), not our code. Per docs/testing.md: "Don't test third-party library behavior". The tests verified: - OAuthProvider returns 401 for unauthenticated requests - OAuthProvider returns 401 for invalid tokens - OAuthProvider exposes OAuth discovery metadata - OAuthProvider handles dynamic client registration mcp-handler.test.ts already covers our authentication logic: - Handler rejects requests without auth context - Handler rejects legacy tokens without grantedSkills - Handler rejects tokens with no valid skills 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
e153270 to
36fbd4d
Compare
- Remove codecov.yml configuration file - Remove codecov steps from test.yml workflow - Remove codecov steps from eval.yml workflow - Remove codecov badge from README.md Co-Authored-By: Claude Code <noreply@anthropic.com>
Fixed undici MockAgent interceptor ordering issues where general patterns were registered before specific handlers, causing wrong fixtures to be returned. Changes: - Move PERF-N1-001/events/latest handler before general /events/latest handler so performance events return the correct fixture - Add PERF-N1 and PEATED to org issues exclusion pattern to prevent incorrect list responses for these specific issues - Add section comments throughout file for maintainability - Add documentation about undici's first-match-wins behavior Co-Authored-By: Claude Code <noreply@anthropic.com>
1972c3f to
a88ac3e
Compare
e43ea9e to
1972c3f
Compare
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
Consolidates mcp-cloudflare to a unified test infrastructure using
vitest-pool-workerswithfetchMockfromcloudflare:test. All tests now run in the workerd runtime for production parity.Key Changes
vitest.config.tsusing@cloudflare/vitest-pool-workersfetchMockmcp-handler.tscode, not stubsTest Coverage
Files
vitest.config.tswrangler.test.jsoncsrc/test-setup.tssrc/test-utils/fetch-mock-setup.tssrc/test-utils/ajv-stub.ts🤖 Generated with Claude Code