-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-tools.js
More file actions
executable file
Β·174 lines (148 loc) Β· 4.82 KB
/
test-tools.js
File metadata and controls
executable file
Β·174 lines (148 loc) Β· 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env node
// Test MCP tools functionality
import { spawn } from 'child_process';
const colors = {
reset: '\x1b[0m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
cyan: '\x1b[36m'
};
function log(message, color = colors.reset) {
console.log(`${color}${message}${colors.reset}`);
}
async function testTool(toolName, args) {
log(`π§ Testing tool: ${toolName}`, colors.blue);
return new Promise((resolve) => {
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
let responseReceived = false;
let stdout = '';
let stderr = '';
server.stdout.on('data', (data) => {
const output = data.toString();
stdout += output;
try {
const lines = output.split('\n').filter(line => line.trim());
for (const line of lines) {
if (line.trim()) {
const response = JSON.parse(line);
if (response.id === 2 && response.result) {
log(`β
${toolName} responded successfully`, colors.green);
if (response.result.content && response.result.content[0]) {
const content = response.result.content[0].text;
const preview = content.substring(0, 100);
log(`Response: ${preview}${content.length > 100 ? '...' : ''}`, colors.cyan);
}
responseReceived = true;
server.kill('SIGTERM');
return;
} else if (response.id === 2 && response.error) {
log(`β ${toolName} returned error: ${response.error.message}`, colors.red);
responseReceived = true;
server.kill('SIGTERM');
resolve(false);
return;
}
}
}
} catch (e) {
// Not JSON, might be startup message
if (output.includes('Codex MCP Server is running')) {
log('Server started, sending tool request...', colors.blue);
// Send tool request
const request = {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: toolName,
arguments: args
}
};
server.stdin.write(JSON.stringify(request) + '\n');
}
}
});
server.stderr.on('data', (data) => {
stderr += data.toString();
});
server.on('close', (code) => {
if (responseReceived) {
resolve(true);
} else {
log(`β ${toolName} test failed`, colors.red);
log(`Exit code: ${code}`, colors.red);
if (stderr) {
log('Stderr:', colors.red);
console.log(stderr.substring(0, 500));
}
resolve(false);
}
});
server.on('error', (error) => {
log(`β Server error: ${error.message}`, colors.red);
resolve(false);
});
// Timeout after 30 seconds
setTimeout(() => {
if (!responseReceived) {
log(`β ${toolName} test timeout`, colors.red);
server.kill('SIGKILL');
resolve(false);
}
}, 30000);
});
}
async function runToolTests() {
log('π§ͺ Testing Codex MCP Tools', colors.cyan);
log('===========================', colors.cyan);
const tests = [
{
name: 'consult_codex',
args: { prompt: 'What is 2 + 2? Give a brief answer.' }
},
{
name: 'start_conversation',
args: { topic: 'Test conversation', instructions: 'Be helpful and concise' }
}
];
const results = [];
for (const test of tests) {
try {
const result = await testTool(test.name, test.args);
results.push({ name: test.name, passed: result });
} catch (error) {
log(`β Test error: ${error.message}`, colors.red);
results.push({ name: test.name, passed: false });
}
// Brief pause between tests
await new Promise(resolve => setTimeout(resolve, 1000));
}
// Summary
log('\nπ Tool Test Results', colors.cyan);
log('===================', colors.cyan);
const passed = results.filter(r => r.passed).length;
const total = results.length;
results.forEach(result => {
const status = result.passed ? 'β
PASS' : 'β FAIL';
const color = result.passed ? colors.green : colors.red;
log(`${status} ${result.name}`, color);
});
log(`\nOverall: ${passed}/${total} tools tested successfully`, passed === total ? colors.green : colors.red);
if (passed === total) {
log('\nπ All tools are working correctly!', colors.green);
} else {
log('\nβ οΈ Some tools failed. Check Codex CLI configuration.', colors.yellow);
}
return passed === total;
}
// Run tests
runToolTests().then(success => {
process.exit(success ? 0 : 1);
}).catch(error => {
console.error('Test runner error:', error);
process.exit(1);
});