@ebowwa/claude-code-mcp 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/advanced.test.d.ts +6 -0
- package/dist/__tests__/advanced.test.d.ts.map +1 -0
- package/dist/__tests__/advanced.test.js +354 -0
- package/dist/__tests__/advanced.test.js.map +1 -0
- package/dist/advanced.d.ts +109 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +427 -0
- package/dist/advanced.js.map +1 -0
- package/dist/cli-wrapper.d.ts +202 -0
- package/dist/cli-wrapper.d.ts.map +1 -0
- package/dist/cli-wrapper.js +347 -0
- package/dist/cli-wrapper.js.map +1 -0
- package/dist/cli-wrapper.test.d.ts +12 -0
- package/dist/cli-wrapper.test.d.ts.map +1 -0
- package/dist/cli-wrapper.test.js +354 -0
- package/dist/cli-wrapper.test.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +354 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +561 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.test.d.ts +12 -0
- package/dist/integration.test.d.ts.map +1 -0
- package/dist/integration.test.js +716 -0
- package/dist/integration.test.js.map +1 -0
- package/dist/queue.d.ts +87 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +273 -0
- package/dist/queue.js.map +1 -0
- package/dist/teammates-integration.d.ts +128 -0
- package/dist/teammates-integration.d.ts.map +1 -0
- package/dist/teammates-integration.js +353 -0
- package/dist/teammates-integration.js.map +1 -0
- package/dist/test-config.d.ts +104 -0
- package/dist/test-config.d.ts.map +1 -0
- package/dist/test-config.js +439 -0
- package/dist/test-config.js.map +1 -0
- package/dist/tools.d.ts +97 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +627 -0
- package/dist/tools.js.map +1 -0
- package/package.json +7 -1
- package/ARCHITECTURE.md +0 -1802
- package/DOCUMENTATION.md +0 -747
- package/TESTING.md +0 -318
package/TESTING.md
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
# Testing Guide
|
|
2
|
-
|
|
3
|
-
This document describes how to run and extend tests for the `@mcp/claude-code` MCP server.
|
|
4
|
-
|
|
5
|
-
## Test Structure
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
src/
|
|
9
|
-
├── cli-wrapper.test.ts # Unit tests for CLI wrapper and Doppler integration
|
|
10
|
-
├── integration.test.ts # Integration tests with mock Claude binary
|
|
11
|
-
└── test-config.ts # Shared test utilities and mock helpers
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Running Tests
|
|
15
|
-
|
|
16
|
-
### Run All Tests
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
bun test
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### Run Specific Test Suites
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
# CLI wrapper tests only
|
|
26
|
-
bun run test:cli-wrapper
|
|
27
|
-
|
|
28
|
-
# Integration tests only
|
|
29
|
-
bun run test:integration
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Watch Mode
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
bun run test:watch
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Test Files
|
|
39
|
-
|
|
40
|
-
### cli-wrapper.test.ts
|
|
41
|
-
|
|
42
|
-
Unit tests for the `ClaudeCodeWrapper` class:
|
|
43
|
-
|
|
44
|
-
- **Constructor tests**: Default options, custom options
|
|
45
|
-
- **Spawn tests**: Process spawning with/without Doppler
|
|
46
|
-
- **Kill tests**: Graceful and force termination
|
|
47
|
-
- **isAlive tests**: Process state tracking
|
|
48
|
-
- **Doppler integration**: --resume flag handling, command construction
|
|
49
|
-
- **Error handling**: Spawn failures, kill failures
|
|
50
|
-
- **Edge cases**: Malformed UUIDs, missing environment variables, message escaping
|
|
51
|
-
|
|
52
|
-
**Key test cases:**
|
|
53
|
-
- Doppler workaround for `--resume` flag
|
|
54
|
-
- Rolling API keys with Doppler
|
|
55
|
-
- Special character escaping in messages
|
|
56
|
-
- Process lifecycle management
|
|
57
|
-
|
|
58
|
-
### integration.test.ts
|
|
59
|
-
|
|
60
|
-
Integration tests with a mock Claude binary:
|
|
61
|
-
|
|
62
|
-
- **start_session**: Starting new sessions with project context
|
|
63
|
-
- **resume_session**: Resuming sessions with Doppler wrapper
|
|
64
|
-
- **list_sessions**: Listing and filtering sessions
|
|
65
|
-
- **kill_session**: Terminating running sessions
|
|
66
|
-
- **send_message**: Sending messages to active sessions
|
|
67
|
-
- **sync_context**: Context synchronization between sessions
|
|
68
|
-
- **stream_output**: Output streaming from sessions
|
|
69
|
-
- **wait_for_completion**: Waiting for session completion with timeout
|
|
70
|
-
|
|
71
|
-
**Key test cases:**
|
|
72
|
-
- Full tool call lifecycle
|
|
73
|
-
- Session state management
|
|
74
|
-
- Doppler integration simulation
|
|
75
|
-
- Error handling for invalid inputs
|
|
76
|
-
|
|
77
|
-
### test-config.ts
|
|
78
|
-
|
|
79
|
-
Shared utilities:
|
|
80
|
-
|
|
81
|
-
- `TEST_CONFIG`: Test environment configuration
|
|
82
|
-
- `MOCK_SESSIONS`: Mock session data for tests
|
|
83
|
-
- `DOPPLER_TEST_CONFIGS`: Doppler test configurations
|
|
84
|
-
- `MOCK_API_KEYS`: Mock API key data
|
|
85
|
-
- `setupTestEnvironment()`: Create test directories
|
|
86
|
-
- `cleanupTestEnvironment()`: Remove test artifacts
|
|
87
|
-
- `createMockClaudeBinary()`: Create mock Claude executable
|
|
88
|
-
- `createMockDoppler()`: Create mock doppler CLI
|
|
89
|
-
- `MockMCPServer`: Mock server class for testing
|
|
90
|
-
- `expect`: Assertion helpers
|
|
91
|
-
- `wait`, `retry`, `time`: Async test utilities
|
|
92
|
-
|
|
93
|
-
## Test Patterns
|
|
94
|
-
|
|
95
|
-
### Pattern 1: Testing with Mock Binary
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
import { createMockClaudeBinary } from './test-config';
|
|
99
|
-
|
|
100
|
-
describe('My Feature', () => {
|
|
101
|
-
let mockPath: string;
|
|
102
|
-
|
|
103
|
-
beforeEach(async () => {
|
|
104
|
-
mockPath = await createMockClaudeBinary();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
afterEach(async () => {
|
|
108
|
-
// Cleanup
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should work with mock Claude', async () => {
|
|
112
|
-
const process = Bun.spawn([mockPath, '--version']);
|
|
113
|
-
// Test logic...
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Pattern 2: Testing Doppler Integration
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
describe('Doppler Integration', () => {
|
|
122
|
-
it('should construct correct command', () => {
|
|
123
|
-
const wrapper = new ClaudeCodeWrapper({ useDoppler: true });
|
|
124
|
-
const cmd = wrapper.buildResumeCommand('uuid-123');
|
|
125
|
-
expect(cmd).toContain('--resume');
|
|
126
|
-
expect(cmd).toContain('doppler');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### Pattern 3: Testing MCP Tool Calls
|
|
132
|
-
|
|
133
|
-
```typescript
|
|
134
|
-
describe('MCP Tool', () => {
|
|
135
|
-
let server: MockMCPServer;
|
|
136
|
-
|
|
137
|
-
beforeEach(() => {
|
|
138
|
-
server = new MockMCPServer();
|
|
139
|
-
server.registerTool('my_tool', async function(args: any) {
|
|
140
|
-
// Tool implementation
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should call tool correctly', async () => {
|
|
145
|
-
const result = await server.callTool('my_tool', { param: 'value' });
|
|
146
|
-
expect.success(result);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## Edge Cases Tested
|
|
152
|
-
|
|
153
|
-
### Doppler Flag Handling
|
|
154
|
-
|
|
155
|
-
1. **Valid UUID with --resume**
|
|
156
|
-
- Standard UUID format: `abc-123-def-456`
|
|
157
|
-
- Command construction: `doppler run --command "claude --resume UUID"`
|
|
158
|
-
|
|
159
|
-
2. **Malformed UUIDs**
|
|
160
|
-
- Empty string
|
|
161
|
-
- Non-UUID strings
|
|
162
|
-
- Special characters
|
|
163
|
-
- Should construct command anyway (validation at Claude level)
|
|
164
|
-
|
|
165
|
-
3. **Missing Doppler Configuration**
|
|
166
|
-
- No `DOPPLER_PROJECT` set
|
|
167
|
-
- No `DOPPLER_CONFIG` set
|
|
168
|
-
- Empty `DOPPLER_TOKEN`
|
|
169
|
-
- Should still construct doppler command
|
|
170
|
-
|
|
171
|
-
4. **Message Escaping**
|
|
172
|
-
- Quotes in message: `Fix the "auth" bug` → `Fix the \"auth\" bug`
|
|
173
|
-
- Newlines in message: `Line 1\nLine 2` → `Line 1\\nLine 2`
|
|
174
|
-
- Empty messages
|
|
175
|
-
|
|
176
|
-
### Process Lifecycle
|
|
177
|
-
|
|
178
|
-
1. **Spawn-Kill Cycles**
|
|
179
|
-
- Single spawn/kill
|
|
180
|
-
- Rapid spawn-kill cycles
|
|
181
|
-
- Multiple kills (should be idempotent)
|
|
182
|
-
|
|
183
|
-
2. **State Tracking**
|
|
184
|
-
- Idle → Running → Killed
|
|
185
|
-
- Process ID tracking
|
|
186
|
-
- Alive status checks
|
|
187
|
-
|
|
188
|
-
### Session Management
|
|
189
|
-
|
|
190
|
-
1. **Invalid Session IDs**
|
|
191
|
-
- Non-existent sessions
|
|
192
|
-
- Malformed UUIDs
|
|
193
|
-
- Empty strings
|
|
194
|
-
|
|
195
|
-
2. **Status Filtering**
|
|
196
|
-
- Active sessions only
|
|
197
|
-
- Completed sessions only
|
|
198
|
-
- All sessions
|
|
199
|
-
|
|
200
|
-
3. **Context Sync**
|
|
201
|
-
- Sync all context types
|
|
202
|
-
- Sync specific types (history, files, state)
|
|
203
|
-
- Direct context application
|
|
204
|
-
|
|
205
|
-
## CI/CD Integration
|
|
206
|
-
|
|
207
|
-
### GitHub Actions Example
|
|
208
|
-
|
|
209
|
-
```yaml
|
|
210
|
-
name: Tests
|
|
211
|
-
|
|
212
|
-
on: [push, pull_request]
|
|
213
|
-
|
|
214
|
-
jobs:
|
|
215
|
-
test:
|
|
216
|
-
runs-on: ubuntu-latest
|
|
217
|
-
steps:
|
|
218
|
-
- uses: actions/checkout@v3
|
|
219
|
-
- uses: oven-sh/setup-bun@v1
|
|
220
|
-
with:
|
|
221
|
-
bun-version: latest
|
|
222
|
-
- run: bun install
|
|
223
|
-
- run: bun test
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
## Writing New Tests
|
|
227
|
-
|
|
228
|
-
1. **Choose the right file:**
|
|
229
|
-
- Unit tests for a class → `cli-wrapper.test.ts`
|
|
230
|
-
- Integration tests for tools → `integration.test.ts`
|
|
231
|
-
- Shared utilities → `test-config.ts`
|
|
232
|
-
|
|
233
|
-
2. **Follow the pattern:**
|
|
234
|
-
```typescript
|
|
235
|
-
describe('Feature Name', () => {
|
|
236
|
-
beforeEach(() => {
|
|
237
|
-
// Setup
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
afterEach(() => {
|
|
241
|
-
// Cleanup
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('should do something expected', async () => {
|
|
245
|
-
// Arrange
|
|
246
|
-
const input = { ... };
|
|
247
|
-
|
|
248
|
-
// Act
|
|
249
|
-
const result = await functionUnderTest(input);
|
|
250
|
-
|
|
251
|
-
// Assert
|
|
252
|
-
expect(result).toBe(expected);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
3. **Use the helpers:**
|
|
258
|
-
- `expect.success(result)` - Assert MCP call succeeded
|
|
259
|
-
- `expect.error(result, 'message')` - Assert MCP call failed with message
|
|
260
|
-
- `await setupTestEnvironment()` - Create test directories
|
|
261
|
-
- `await cleanupTestEnvironment()` - Remove test artifacts
|
|
262
|
-
|
|
263
|
-
4. **Test edge cases:**
|
|
264
|
-
- Invalid inputs
|
|
265
|
-
- Missing required fields
|
|
266
|
-
- Empty strings/arrays
|
|
267
|
-
- Malformed data
|
|
268
|
-
- Race conditions
|
|
269
|
-
|
|
270
|
-
## Debugging Tests
|
|
271
|
-
|
|
272
|
-
### Run Tests with Verbose Output
|
|
273
|
-
|
|
274
|
-
```bash
|
|
275
|
-
bun test --verbose
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
### Run Specific Test
|
|
279
|
-
|
|
280
|
-
```bash
|
|
281
|
-
bun test src/cli-wrapper.test.ts -t "should spawn Claude Code without Doppler"
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### Debug with Console Logs
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
it('should do something', () => {
|
|
288
|
-
console.log('Debug info:', someVariable);
|
|
289
|
-
// Test logic...
|
|
290
|
-
});
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
## Coverage
|
|
294
|
-
|
|
295
|
-
To generate coverage reports (when bun test --coverage is available):
|
|
296
|
-
|
|
297
|
-
```bash
|
|
298
|
-
bun run test:coverage
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
## Troubleshooting
|
|
302
|
-
|
|
303
|
-
### "Mock binary not found"
|
|
304
|
-
|
|
305
|
-
- Ensure `createMockClaudeBinary()` is called in `beforeEach`
|
|
306
|
-
- Check that the mock path is correct
|
|
307
|
-
|
|
308
|
-
### "Test timeout"
|
|
309
|
-
|
|
310
|
-
- Increase timeout in test config
|
|
311
|
-
- Check for hanging promises
|
|
312
|
-
- Ensure proper cleanup in `afterEach`
|
|
313
|
-
|
|
314
|
-
### "Doppler tests failing"
|
|
315
|
-
|
|
316
|
-
- Ensure doppler is mocked (not calling real doppler)
|
|
317
|
-
- Check environment variable handling
|
|
318
|
-
- Verify command construction logic
|