Skip to content

Conversation

@jonathannorris
Copy link
Member

@jonathannorris jonathannorris commented Aug 13, 2025

This PR introduces comprehensive end-to-end testing infrastructure for the MCP worker using Vitest and Cloudflare Workers testing pool.

Changes

  • ✅ Added E2E test suite covering:
    • MCP protocol compliance and handshake
    • Tool discovery and listing
    • Worker startup and basic functionality
    • Authentication requirements
  • 🛠️ Set up Vitest with Cloudflare Workers testing pool
  • 📦 Resolved dependency conflicts by pinning @types/[email protected] to maintain build compatibility
  • 🔧 Added test-specific worker entry point to mock MCP SDK during tests

Testing

  • yarn test:worker - Run the new E2E tests
  • yarn build - Verified TypeScript compilation works correctly

Files Added

  • Test suites: mcpProtocol.test.ts, tools.test.ts, startup.test.ts, minimal.test.ts
  • Test helpers: Auth mocking, fixtures, and MCP client utilities
  • Test configuration: vitest.config.ts, wrangler.test.toml

All tests passing ✅

@jonathannorris jonathannorris requested a review from a team as a code owner August 13, 2025 01:54
@jonathannorris jonathannorris requested a review from Copilot August 13, 2025 01:54

This comment was marked as outdated.

This comment was marked as outdated.

Comment on lines 78 to 86
export function createMockEnv(overrides: Partial<Env> = {}): Env {
return {
NODE_ENV: 'test',
API_BASE_URL: 'https://api-test.devcycle.com',
AUTH0_DOMAIN: 'test-auth.devcycle.com',
AUTH0_AUDIENCE: 'https://api-test.devcycle.com/',
AUTH0_SCOPE: 'openid profile email offline_access',
AUTH0_CLIENT_ID: 'test-client-id',
AUTH0_CLIENT_SECRET: 'test-client-secret',
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't these be in the fixtures?

[key: string]: any;
}, options?: DynamicDispatchOptions): Fetcher;
}
declare module 'cloudflare:test' {
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate definition from mcp-worker/test-types.d.ts?

Copy link
Member Author

Choose a reason for hiding this comment

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

this file is auto-generated from wrangler, so not sure. Will run the type gen again and see.

@jonathannorris jonathannorris force-pushed the test-mcp-worker-e2e-cherry-pick branch from dbb33d7 to 5545341 Compare August 14, 2025 15:36
@jonathannorris jonathannorris requested a review from Copilot August 14, 2025 15:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces comprehensive end-to-end testing infrastructure for the MCP worker using Vitest and Cloudflare Workers testing pool.

  • Sets up E2E test suite covering MCP protocol compliance, tool discovery, and worker startup functionality
  • Configures Vitest with Cloudflare Workers testing pool for realistic worker environment testing
  • Creates test-specific worker entry point to avoid AJV compatibility issues during testing

Reviewed Changes

Copilot reviewed 14 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
package.json Updates test scripts to include worker tests and pins @types/estree version
mcp-worker/vitest.config.ts Configures Vitest with Cloudflare Workers testing pool
mcp-worker/wrangler.test.toml Test environment configuration for the worker
mcp-worker/tsconfig.json Updates TypeScript config to include test files and types
mcp-worker/package.json Adds Vitest and testing dependencies
mcp-worker/src/test-index.ts Mock worker entry point for testing
mcp-worker/test/setup.ts Global test setup file
mcp-worker/test/helpers/* Test utilities for MCP client, fixtures, and auth mocking
mcp-worker/test/e2e/*.test.ts E2E test suites for protocol compliance and functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


// Create a simple base64-encoded mock JWT (not cryptographically valid)
const header = btoa(JSON.stringify({ typ: 'JWT', alg: 'HS256' }))
const encodedPayload = btoa(JSON.stringify(payload))
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

The mock JWT creation uses btoa() which is not available in the Cloudflare Workers runtime. Consider using a base64 encoding method compatible with the Workers environment.

Suggested change
const encodedPayload = btoa(JSON.stringify(payload))
const header = base64Encode(JSON.stringify({ typ: 'JWT', alg: 'HS256' }))
const encodedPayload = base64Encode(JSON.stringify(payload))

Copilot uses AI. Check for mistakes.
const mockJWT = createMockJWT(jwtClaims)

// Parse the claims from the mock JWT
const payload = JSON.parse(atob(mockJWT.split('.')[1]))
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

The atob() function is not available in the Cloudflare Workers runtime. Use a base64 decoding method compatible with the Workers environment instead.

Suggested change
const payload = JSON.parse(atob(mockJWT.split('.')[1]))
const payload = JSON.parse(base64Decode(mockJWT.split('.')[1]))

Copilot uses AI. Check for mistakes.
'createDevCycleVariation',
'updateDevCycleVariation',
]

Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

The expectedToolNames array is defined but not used in the actual tests. This creates a maintenance burden as it may become outdated. Consider using this list in the test assertions or remove it if not needed.

Suggested change
*
*/

Copilot uses AI. Check for mistakes.
@jonathannorris
Copy link
Member Author

These tests need a bunch of working, going to make them draft again

@jonathannorris jonathannorris marked this pull request as draft August 14, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants