Skip to content

tests: Add E2E Tests for MCP Worker - #488

Draft
jonathannorris wants to merge 10 commits into
mainfrom
test-mcp-worker-e2e-cherry-pick
Draft

tests: Add E2E Tests for MCP Worker#488
jonathannorris wants to merge 10 commits into
mainfrom
test-mcp-worker-e2e-cherry-pick

Conversation

@jonathannorris

@jonathannorrisjonathannorris commented Aug 13, 2025

Copy link
Copy Markdown
Member

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/estree@1.0.5 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 ownerAugust 13, 2025 01:54

This comment was marked as outdated.

This comment was marked as outdated.

Comment threadmcp-worker/test/helpers/auth.ts 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
MemberAuthor

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
jonathannorrisforce-pushed the test-mcp-worker-e2e-cherry-pick branch from dbb33d7 to 5545341CompareAugust 14, 2025 15:36

CopilotAI left a comment

Copy link
Copy Markdown

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
FileDescription
package.jsonUpdates test scripts to include worker tests and pins @types/estree version
mcp-worker/vitest.config.tsConfigures Vitest with Cloudflare Workers testing pool
mcp-worker/wrangler.test.tomlTest environment configuration for the worker
mcp-worker/tsconfig.jsonUpdates TypeScript config to include test files and types
mcp-worker/package.jsonAdds Vitest and testing dependencies
mcp-worker/src/test-index.tsMock worker entry point for testing
mcp-worker/test/setup.tsGlobal test setup file
mcp-worker/test/helpers/*Test utilities for MCP client, fixtures, and auth mocking
mcp-worker/test/e2e/*.test.tsE2E 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))

CopilotAIAug 14, 2025

Copy link

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
constencodedPayload=btoa(JSON.stringify(payload))
constheader=base64Encode(JSON.stringify({typ: 'JWT',alg: 'HS256'}))
constencodedPayload=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]))

CopilotAIAug 14, 2025

Copy link

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
constpayload=JSON.parse(atob(mockJWT.split('.')[1]))
constpayload=JSON.parse(base64Decode(mockJWT.split('.')[1]))

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

CopilotAIAug 14, 2025

Copy link

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
Copy Markdown
MemberAuthor

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jonathannorris@JamieSinn@kaushalkapasi