-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun-single-test.js
More file actions
114 lines (95 loc) · 3.06 KB
/
run-single-test.js
File metadata and controls
114 lines (95 loc) · 3.06 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
/**
* Simple test script to test the validateSSP method
*/
import { spawn } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
// Get directory paths
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Start MCP server and test validateSSP
async function runTest() {
console.log('🧪 Testing validateSSP method...');
// Start the server process
console.log('📡 Starting server...');
const serverProcess = spawn('node', ['src/index.js'], {
cwd: __dirname,
stdio: ['pipe', 'pipe', 'pipe']
});
// Process server output
let serverReady = false;
serverProcess.stdout.on('data', (data) => {
console.log(`[Server output]: ${data.toString().trim()}`);
});
serverProcess.stderr.on('data', (data) => {
const output = data.toString().trim();
console.log(`[Server log]: ${output}`);
if (output.includes('ready for input')) {
serverReady = true;
}
});
// Wait for server to be ready
let waitCount = 0;
while (!serverReady && waitCount < 50) {
await new Promise(r => setTimeout(r, 100));
waitCount++;
}
if (!serverReady) {
console.error('Server did not start properly');
serverProcess.kill();
process.exit(1);
}
console.log('🚀 Server ready, sending request...');
try {
// Send validateSSP request
const request = {
jsonrpc: '2.0',
method: 'validateSSP',
params: { sspId: 'sample-ssp' },
id: 1
};
console.log(`➡️ Sending: ${JSON.stringify(request)}`);
serverProcess.stdin.write(JSON.stringify(request) + '\n');
// Wait for response
const response = await new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error('Timeout waiting for server response'));
}, 5000);
serverProcess.stdout.on('data', (data) => {
try {
const responseText = data.toString().trim();
console.log(`⬅️ Received: ${responseText}`);
const response = JSON.parse(responseText);
if (response.id === 1) {
clearTimeout(timeout);
resolve(response);
}
} catch (error) {
// Ignore parsing errors
}
});
});
// Validate response
if (response.error) {
console.error(`❌ Error: ${response.error.message}`);
} else {
const result = response.result;
console.log(`✅ Success: Validation result received`);
console.log(` Implementation percentage: ${result.implementationPercentage}%`);
console.log(` Total controls: ${result.totalControls}`);
console.log(` Implementation by status:`, result.implementationByStatus);
}
console.log('\n🎉 Test completed!');
} catch (error) {
console.error(`❌ Test Failed: ${error.message}`);
} finally {
// Clean up
console.log('🧹 Shutting down server...');
serverProcess.kill();
}
}
// Run the test
runTest().catch(err => {
console.error('Test error:', err);
process.exit(1);
});