-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathtest-projects-validation.js
More file actions
232 lines (197 loc) · 7.45 KB
/
Copy pathtest-projects-validation.js
File metadata and controls
232 lines (197 loc) · 7.45 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env node
/**
* Projects validation and error handling test
* Tests validation logic and error cases
*/
const { spawn } = require('child_process');
const path = require('path');
// Configuration from the mandatory protocol
const config = {
vikunja: {
command: 'node',
args: [path.join(__dirname, 'dist', 'index.js')],
env: {
'VIKUNJA_URL': 'https://vikunja.erinjeremy.com/api/v1',
'VIKUNJA_API_TOKEN': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImplcmVteUBlcmluamVyZW15LmNvbSIsImVtYWlsUmVtaW5kZXJzRW5hYmxlZCI6dHJ1ZSwiZXhwIjoxNzY1Mjk4Nzg0LCJpZCI6MSwiaXNMb2NhbFVzZXIiOnRydWUsImxvbmciOnRydWUsIm5hbWUiOiIiLCJ0eXBlIjoxLCJ1c2VybmFtZSI6ImplcmVteSJ9.k9Csiffu2uf3XgkROvub_ZZBFLYVDrA18-c60i1r04E'
}
}
};
class ProjectsValidationTester {
constructor() {
this.server = null;
this.messageId = 1;
this.testResults = [];
}
async startServer() {
console.log('🚀 Starting Vikunja MCP Server for validation testing...');
this.server = spawn(config.vikunja.command, config.vikunja.args, {
env: { ...process.env, ...config.vikunja.env },
stdio: ['pipe', 'pipe', 'pipe']
});
this.server.on('error', (error) => {
console.error('❌ Server error:', error);
});
this.server.stderr.on('data', (data) => {
// Suppress logs for cleaner test output
});
await this.sleep(1000);
console.log('✅ Server started successfully');
}
async sendRequest(method, params = {}) {
const request = {
jsonrpc: '2.0',
method,
params,
id: this.messageId++
};
return new Promise((resolve, reject) => {
let responseData = '';
const timeout = setTimeout(() => {
reject(new Error(`Request timeout for ${method}`));
}, 10000);
this.server.stdout.on('data', (data) => {
responseData += data.toString();
const lines = responseData.split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const response = JSON.parse(line);
if (response.id === request.id) {
clearTimeout(timeout);
resolve(response);
return;
}
} catch (e) {
// Not valid JSON yet, continue collecting
}
}
});
this.server.stdin.write(JSON.stringify(request) + '\n');
});
}
async initializeServer() {
const response = await this.sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: { roots: { listChanged: true } },
clientInfo: {
name: 'projects-validation-test',
version: '1.0.0'
}
});
return response.result && response.result.serverInfo;
}
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async testValidation(testName, requestArgs, expectedError) {
console.log(`\n🧪 Testing: ${testName}`);
console.log(`📤 Request args:`, requestArgs);
try {
const response = await this.sendRequest('tools/call', {
name: 'vikunja_projects',
arguments: requestArgs
});
console.log(`📥 Response structure:`, response.error ? 'ERROR' : 'SUCCESS');
if (response.error) {
console.log(`📥 Error response:`, response.error);
} else if (response.result && response.result.content) {
try {
const content = JSON.parse(response.result.content[0].text);
console.log(`📥 Success response:`, content.success ? 'SUCCESS' : 'ERROR');
if (!content.success) {
console.log(`📥 Error in content:`, content);
// This might be the actual error case
const actualError = content.message || 'Unknown error';
if (expectedError && actualError.includes(expectedError)) {
console.log(`✅ PASS: Got expected error: "${actualError}"`);
this.testResults.push({ test: testName, status: 'PASS', error: actualError });
return true;
} else {
console.log(`❌ FAIL: Expected error containing "${expectedError}", got: "${actualError}"`);
this.testResults.push({ test: testName, status: 'FAIL', expected: expectedError, actual: actualError });
return false;
}
}
} catch (parseError) {
console.log(`📥 Content parse error:`, parseError.message);
}
}
if (response.error) {
const actualError = response.error.message;
if (expectedError && actualError.includes(expectedError)) {
console.log(`✅ PASS: Got expected error: "${actualError}"`);
this.testResults.push({ test: testName, status: 'PASS', error: actualError });
return true;
} else {
console.log(`❌ FAIL: Expected error containing "${expectedError}", got: "${actualError}"`);
this.testResults.push({ test: testName, status: 'FAIL', expected: expectedError, actual: actualError });
return false;
}
} else {
console.log(`❌ FAIL: Expected error but got success response`);
this.testResults.push({ test: testName, status: 'FAIL', expected: expectedError, actual: 'SUCCESS' });
return false;
}
} catch (error) {
console.log(`📥 Caught exception:`, error.message);
if (expectedError && error.message.includes(expectedError)) {
console.log(`✅ PASS: Got expected error: "${error.message}"`);
this.testResults.push({ test: testName, status: 'PASS', error: error.message });
return true;
} else {
console.log(`❌ FAIL: Expected error containing "${expectedError}", got: "${error.message}"`);
this.testResults.push({ test: testName, status: 'FAIL', expected: expectedError, actual: error.message });
return false;
}
}
}
async runValidationTests() {
try {
await this.startServer();
const initSuccess = await this.initializeServer();
if (!initSuccess) {
throw new Error('Server initialization failed');
}
console.log('\n🎯 Starting Projects validation tests...\n');
let passedTests = 0;
let totalTests = 0;
// Test just one validation case to debug
totalTests++;
if (await this.testValidation(
'Create project without title',
{ subcommand: 'create' },
'title is required'
)) passedTests++;
console.log('\n📋 Validation Test Results Summary:');
console.log(`✅ Passed: ${passedTests}/${totalTests} tests`);
console.log(`❌ Failed: ${totalTests - passedTests}/${totalTests} tests`);
if (this.testResults.some(r => r.status === 'FAIL')) {
console.log('\n❌ Failed Tests:');
this.testResults
.filter(r => r.status === 'FAIL')
.forEach(r => {
console.log(` - ${r.test}: Expected "${r.expected}", got "${r.actual}"`);
});
}
console.log('\n🎉 Projects validation testing completed!');
return passedTests === totalTests;
} catch (error) {
console.error('\n💥 Validation test failed:', error.message);
return false;
} finally {
if (this.server) {
this.server.kill();
await this.sleep(500);
}
}
}
}
// Run the tests
async function main() {
const tester = new ProjectsValidationTester();
const success = await tester.runValidationTests();
process.exit(success ? 0 : 1);
}
if (require.main === module) {
main().catch(console.error);
}
module.exports = { ProjectsValidationTester };