Skip to content

Commit 348f067

Browse files
committed
Add payment E2E tests and documentation
Introduces comprehensive payment E2E test suite, new payment test configs, and detailed documentation (FEATURE_MAP.md, TESTING.md, TEST_SUMMARY.md). Updates CI workflow and package.json scripts to include payment tests and smoke tests for paid configs.
1 parent 5594efc commit 348f067

File tree

11 files changed

+1760
-1
lines changed

11 files changed

+1760
-1
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
- name: Run full E2E tests
3232
run: bun run tests/e2e-test.ts
3333

34+
- name: Run payment E2E tests
35+
run: bun run tests/e2e-payment.ts
36+
3437
- name: Smoke: config loading with Bun
3538
run: |
3639
timeout 10s bun run src/index.ts --config=tests/configs/basic.yaml || true
@@ -39,3 +42,8 @@ jobs:
3942
- name: Smoke: env config with Bun
4043
run: |
4144
timeout 10s env MCP_SERVERS="test:npx:user-review-mcp" bun run src/index.ts || true
45+
46+
- name: Smoke: payment configs
47+
run: |
48+
timeout 10s bun run src/index.ts --config=tests/configs/paid-free-tools.yaml || true
49+
timeout 10s bun run src/index.ts --config=tests/configs/paid-disabled.yaml || true

FEATURE_MAP.md

Lines changed: 379 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,379 @@
1+
# MCP Gateway Feature Map
2+
3+
Complete mapping of all features in the Eliza MCP Gateway for E2E testing.
4+
5+
---
6+
7+
## 🎯 Core Features
8+
9+
### 1. **Configuration Management**
10+
- ✅ YAML config loading (`config.yaml`)
11+
- ✅ JSON config loading (`config.json`)
12+
- ✅ Environment variable config (`MCP_SERVERS`, `MCP_GATEWAY_NAME`, etc.)
13+
- ✅ Config validation (duplicate server names, invalid namespaces)
14+
- ✅ Default value handling
15+
- ❌ Config hot-reloading (not implemented)
16+
17+
**Test Coverage:**
18+
- `tests/e2e-simple.ts`: testConfigurationLoading()
19+
- Configs: `tests/configs/basic.yaml`, `tests/configs/basic.json`
20+
21+
---
22+
23+
### 2. **Server Connection Management**
24+
- ✅ STDIO transport (local command execution)
25+
- ✅ HTTP transport (remote HTTP servers)
26+
- ✅ SSE transport (Server-Sent Events)
27+
- ✅ WebSocket transport (bidirectional)
28+
- ✅ Legacy format support (`command`/`args`)
29+
- ✅ Modern format support (`transport` object)
30+
- ✅ Parallel server initialization
31+
- ✅ Connection health checks
32+
- ✅ Graceful degradation (failed servers don't crash gateway)
33+
- ✅ Server retry logic (configurable attempts/delay)
34+
35+
**Test Coverage:**
36+
- `tests/e2e-simple.ts`: testBasicStartup()
37+
- `tests/e2e-test.ts`: Full transport validation
38+
- Configs: `tests/configs/multi-server.yaml`, `examples/mixed-transports.yaml`
39+
40+
---
41+
42+
### 3. **Namespace Management**
43+
- ✅ Namespace prefixing (`docs:tool-name`)
44+
- ✅ Conflict resolution (duplicate tool names)
45+
- ✅ Resource URI namespacing
46+
- ✅ Prompt namespacing
47+
- ✅ Namespace validation (regex: `/^[a-zA-Z][a-zA-Z0-9_-]*$/`)
48+
- ✅ Optional namespaces (servers without namespace)
49+
50+
**Test Coverage:**
51+
- `tests/e2e-simple.ts`: testNamespaceHandling()
52+
- Configs: `tests/configs/namespaced.yaml`
53+
54+
---
55+
56+
### 4. **Tool Aggregation & Routing**
57+
- ✅ Tool discovery (`ListTools`)
58+
- ✅ Tool execution (`CallTool`)
59+
- ✅ Original name preservation
60+
- ✅ Namespaced name mapping
61+
- ✅ Server routing (find correct server for tool)
62+
- ✅ Input schema forwarding
63+
- ✅ Tool description enrichment
64+
- ✅ Error propagation from downstream servers
65+
66+
**Test Coverage:**
67+
- `tests/e2e-test.ts`: Tool listing and execution tests
68+
- Currently tested implicitly
69+
70+
---
71+
72+
### 5. **Resource Aggregation & Routing**
73+
- ✅ Resource discovery (`ListResources`)
74+
- ✅ Resource reading (`ReadResource`)
75+
- ✅ URI namespacing (query parameter or prefix)
76+
- ✅ MIME type forwarding
77+
- ✅ Resource description enrichment
78+
79+
**Test Coverage:**
80+
- Currently minimal - needs dedicated tests
81+
82+
---
83+
84+
### 6. **Prompt Aggregation & Routing**
85+
- ✅ Prompt discovery (`ListPrompts`)
86+
- ✅ Prompt execution (`GetPrompt`)
87+
- ✅ Argument forwarding
88+
- ✅ Prompt description enrichment
89+
90+
**Test Coverage:**
91+
- Currently minimal - needs dedicated tests
92+
93+
---
94+
95+
### 7. **Health Monitoring**
96+
- ✅ Configurable health check interval
97+
- ✅ Server status tracking (connecting/connected/disconnected/error)
98+
- ✅ Automatic registry refresh on health check
99+
- ✅ Connection statistics
100+
- ✅ Last health check timestamp
101+
- ✅ Error tracking per server
102+
103+
**Test Coverage:**
104+
- Currently minimal - needs time-based tests
105+
106+
---
107+
108+
### 8. **Error Handling**
109+
- ✅ Invalid config rejection
110+
- ✅ Server connection failures (graceful)
111+
- ✅ Tool not found errors
112+
- ✅ Server disconnection handling
113+
- ✅ MCP protocol errors
114+
- ✅ Timeout handling
115+
- ✅ Transport validation errors
116+
117+
**Test Coverage:**
118+
- `tests/e2e-simple.ts`: testErrorHandling()
119+
- Configs: `tests/configs/invalid.yaml`, `tests/configs/failing-server.yaml`
120+
121+
---
122+
123+
### 9. **Payment Gating** ⭐ NEW
124+
- ✅ Payment config loading
125+
- ✅ x402 payment verification
126+
- ✅ API key authentication
127+
- ✅ Tiered pricing (premium/basic/free)
128+
- ✅ Per-tool pricing
129+
- ✅ Server-wide default pricing
130+
- ✅ Free tool designation
131+
- ✅ 402 Payment Required responses
132+
- ✅ Payment facilitator integration
133+
- ✅ USDC multi-network support
134+
- ✅ Amount conversion (dollars → atomic units)
135+
- ✅ API key caching
136+
- ✅ Payment statistics
137+
138+
**Test Coverage:**
139+
- ❌ No tests yet - NEEDS IMPLEMENTATION
140+
141+
---
142+
143+
### 10. **Registry Management**
144+
- ✅ Tool registry (Map-based storage)
145+
- ✅ Resource registry
146+
- ✅ Prompt registry
147+
- ✅ Registry refresh
148+
- ✅ Capability discovery
149+
- ✅ Statistics tracking (tools/resources/prompts by server)
150+
- ✅ Conflict detection and resolution
151+
152+
**Test Coverage:**
153+
- Tested implicitly through tool/resource/prompt tests
154+
155+
---
156+
157+
### 11. **Logging & Observability**
158+
- ✅ Configurable log levels (error/warn/info/debug)
159+
- ✅ Structured logging format (`[INFO]`, `[ERROR]`, etc.)
160+
- ✅ Startup logs
161+
- ✅ Connection status logs
162+
- ✅ Tool execution logs
163+
- ✅ Payment verification logs (NEW)
164+
- ✅ Health check logs
165+
- ✅ Error logging with context
166+
167+
**Test Coverage:**
168+
- Validated through output parsing in tests
169+
170+
---
171+
172+
### 12. **Process Management**
173+
- ✅ Graceful shutdown (SIGINT/SIGTERM)
174+
- ✅ Cleanup on exit
175+
- ✅ Server connection cleanup
176+
- ✅ Health check interval cleanup
177+
- ✅ Uncaught exception handling
178+
- ✅ Unhandled rejection handling
179+
180+
**Test Coverage:**
181+
- Tested via process timeout/kill in test runner
182+
183+
---
184+
185+
## 📊 Feature Coverage Matrix
186+
187+
| Feature | Implementation | Unit Tests | E2E Tests | Integration Tests |
188+
|---------|---------------|------------|-----------|-------------------|
189+
| YAML Config |||||
190+
| JSON Config |||||
191+
| Env Config |||||
192+
| STDIO Transport |||||
193+
| HTTP Transport ||| ⚠️ | ⚠️ |
194+
| SSE Transport ||| ⚠️ ||
195+
| WebSocket Transport ||| ⚠️ ||
196+
| Namespace Prefixing |||||
197+
| Conflict Resolution ||| ⚠️ | ⚠️ |
198+
| Tool Aggregation ||| ⚠️ | ⚠️ |
199+
| Resource Aggregation |||||
200+
| Prompt Aggregation |||||
201+
| Health Checks |||||
202+
| Error Handling |||||
203+
| **Payment - x402** |||||
204+
| **Payment - API Keys** |||||
205+
| **Payment - Tiered Pricing** |||||
206+
| **Payment - Free Tools** |||||
207+
| **Payment - 402 Responses** |||||
208+
| Graceful Shutdown ||| ⚠️ | ⚠️ |
209+
| Logging ||| ⚠️ | ⚠️ |
210+
211+
Legend:
212+
- ✅ = Fully implemented/tested
213+
- ⚠️ = Partially implemented/tested
214+
- ❌ = Not implemented/tested
215+
216+
---
217+
218+
## 🎯 Test Scenarios Needed
219+
220+
### **Payment Feature Tests** (Priority: HIGH)
221+
222+
#### Test Suite: `tests/e2e-payment.ts`
223+
224+
1. **Payment Config Loading**
225+
- ✅ Load paid config YAML
226+
- ✅ Load paid config JSON
227+
- ✅ Validate payment recipient address
228+
- ✅ Validate API key format
229+
- ✅ Validate network selection
230+
231+
2. **Free Tool Access**
232+
- Test tool marked as `free: true`
233+
- No payment required
234+
- No API key required
235+
236+
3. **API Key Authentication**
237+
- Test valid API key (premium tier)
238+
- Test valid API key (basic tier)
239+
- Test invalid API key (rejected)
240+
- Test missing API key (402 error)
241+
- Test tier-based pricing
242+
- Test free tier access
243+
244+
4. **x402 Payment Verification**
245+
- Mock facilitator responses
246+
- Test valid payment header
247+
- Test invalid payment header
248+
- Test payment amount validation
249+
- Test network compatibility
250+
- Test USDC contract addressing
251+
252+
5. **Tiered Pricing**
253+
- Premium tier gets free access
254+
- Basic tier gets discount
255+
- No tier pays full price
256+
- Per-tool pricing override
257+
258+
6. **Default Pricing**
259+
- Server-wide default pricing
260+
- Tool-specific override
261+
- Multiple pricing strategies
262+
263+
7. **402 Error Responses**
264+
- Correct payment requirements structure
265+
- x402Version = 1
266+
- Valid payment scheme
267+
- Correct USDC address for network
268+
- Atomic units conversion
269+
270+
8. **Edge Cases**
271+
- Payment disabled (backward compatibility)
272+
- Tool without pricing config (free by default)
273+
- Mixed free and paid tools
274+
- Multiple API key tiers
275+
276+
---
277+
278+
### **Transport Tests** (Priority: MEDIUM)
279+
280+
#### Test Suite: `tests/e2e-transports.ts`
281+
282+
1. HTTP Transport
283+
2. SSE Transport
284+
3. WebSocket Transport
285+
4. Mixed transports in one gateway
286+
287+
---
288+
289+
### **Resource Tests** (Priority: MEDIUM)
290+
291+
#### Test Suite: `tests/e2e-resources.ts`
292+
293+
1. Resource listing
294+
2. Resource reading
295+
3. Resource namespacing
296+
4. Resource conflict resolution
297+
298+
---
299+
300+
### **Prompt Tests** (Priority: MEDIUM)
301+
302+
#### Test Suite: `tests/e2e-prompts.ts`
303+
304+
1. Prompt listing
305+
2. Prompt execution
306+
3. Prompt argument forwarding
307+
4. Prompt namespacing
308+
309+
---
310+
311+
### **Health Check Tests** (Priority: LOW)
312+
313+
#### Test Suite: `tests/e2e-health.ts`
314+
315+
1. Initial health check
316+
2. Periodic health checks
317+
3. Server reconnection on failure
318+
4. Registry refresh on health check
319+
320+
---
321+
322+
## 📁 Test Config Files Needed
323+
324+
### Payment Configs
325+
- `tests/configs/paid-free-tools.yaml` - Mix of free and paid tools
326+
- `tests/configs/paid-api-key-only.yaml` - API key authentication only
327+
- `tests/configs/paid-x402-only.yaml` - x402 payment only
328+
- `tests/configs/paid-tiered.yaml` - Multiple pricing tiers
329+
- `tests/configs/paid-default-pricing.yaml` - Server-wide defaults
330+
331+
### Mock Servers
332+
- `tests/mocks/mock-paid-server.ts` - Mock MCP server with payment
333+
- `tests/mocks/mock-facilitator.ts` - Mock x402 facilitator
334+
335+
---
336+
337+
## 🚀 Testing Strategy
338+
339+
### Phase 1: Payment Feature Tests (CURRENT)
340+
1. Create mock facilitator for x402 verification
341+
2. Create test configs for all payment scenarios
342+
3. Implement `tests/e2e-payment.ts`
343+
4. Add payment tests to CI workflow
344+
345+
### Phase 2: Transport Tests
346+
1. Create HTTP/SSE/WebSocket mock servers
347+
2. Test all transport types
348+
3. Test transport failure modes
349+
350+
### Phase 3: Resource & Prompt Tests
351+
1. Test full resource lifecycle
352+
2. Test full prompt lifecycle
353+
3. Test conflict resolution
354+
355+
### Phase 4: Advanced Tests
356+
1. Health check timing tests
357+
2. Stress tests (many servers/tools)
358+
3. Performance benchmarks
359+
360+
---
361+
362+
## 📊 Success Metrics
363+
364+
- **Code Coverage**: Target 80%+ for core features
365+
- **E2E Coverage**: All features have at least 1 E2E test
366+
- **Payment Tests**: 100% coverage of payment flows
367+
- **CI/CD**: All tests pass on every commit
368+
- **Documentation**: Every feature documented and tested
369+
370+
---
371+
372+
## 🎯 Next Steps
373+
374+
1. ✅ Create this feature map
375+
2. ⏳ Implement `tests/e2e-payment.ts`
376+
3. ⏳ Create payment test configs
377+
4. ⏳ Add mock facilitator
378+
5. ⏳ Update CI workflow
379+
6. ⏳ Implement remaining test suites

0 commit comments

Comments
 (0)