#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');
async function testStdioAnomalySimple() {
console.log('🧪 Simple Anomaly Detection Test via stdio...\n');
const serverPath = path.join(__dirname, '../../dist/index.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe']
});
let requestId = 1;
// Helper to send request and wait for response
function sendRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
method: method,
params: params,
id: requestId++
};
console.log(`📤 Request: ${method}`);
server.stdin.write(JSON.stringify(request) + '\n');
let responseBuffer = '';
function handleData(data) {
responseBuffer += data.toString();
let lines = responseBuffer.split('\n');
responseBuffer = lines.pop() || '';
for (const line of lines) {
if (line.trim()) {
try {
const response = JSON.parse(line);
if (response.id === request.id) {
server.stdout.removeListener('data', handleData);
resolve(response);
return;
}
} catch (e) {
// Continue parsing
}
}
}
}
server.stdout.on('data', handleData);
// Timeout after 60 seconds
setTimeout(() => {
server.stdout.removeListener('data', handleData);
resolve({ error: 'timeout_60s' });
}, 60000);
});
}
try {
// Wait for server to start
await new Promise(resolve => setTimeout(resolve, 1000));
console.log('🔧 Step 1: Initialize');
await sendRequest('initialize', { protocolVersion: '1.0', capabilities: {} });
console.log('🔧 Step 2: Authenticate');
const authStart = Date.now();
const authResponse = await sendRequest('tools/call', {
name: 'authenticate_user',
arguments: {
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
}
});
const authTime = Date.now() - authStart;
if (authResponse.result) {
console.log(`✅ Authentication SUCCESS (${authTime}ms)`);
} else if (authResponse.error === 'timeout_60s') {
console.log(`⏰ Authentication TIMEOUT after 60 seconds`);
return;
} else {
console.log(`❌ Authentication FAILED:`, authResponse.error);
return;
}
console.log('\n🔧 Step 3: Test Anomaly Detection (isFull=false)');
const anomalyStart = Date.now();
const anomalyResponse = await sendRequest('tools/call', {
name: 'api__anomaly_detection',
arguments: {
startDate: '2025-09-01',
endDate: '2025-09-24',
isFull: 'false'
}
});
const anomalyTime = Date.now() - anomalyStart;
if (anomalyResponse.result) {
console.log(`✅ Anomaly Detection SUCCESS (${anomalyTime}ms)`);
if (anomalyResponse.result.content && anomalyResponse.result.content[0]) {
const text = anomalyResponse.result.content[0].text;
if (text.includes('❌')) {
console.log('⚠️ Response contains error message:', text.substring(0, 200));
} else {
console.log('📊 Response preview:', text.substring(0, 300) + '...');
}
}
} else if (anomalyResponse.error === 'timeout_60s') {
console.log(`⏰ Anomaly Detection TIMEOUT after 60 seconds`);
} else {
console.log(`❌ Anomaly Detection FAILED:`, anomalyResponse.error);
}
console.log('\n🔧 Step 4: Test Anomaly Detection (isFull=true)');
const anomalyFullStart = Date.now();
const anomalyFullResponse = await sendRequest('tools/call', {
name: 'api__anomaly_detection',
arguments: {
startDate: '2025-09-01',
endDate: '2025-09-24',
isFull: 'true'
}
});
const anomalyFullTime = Date.now() - anomalyFullStart;
if (anomalyFullResponse.result) {
console.log(`✅ Full Anomaly Detection SUCCESS (${anomalyFullTime}ms)`);
if (anomalyFullResponse.result.content && anomalyFullResponse.result.content[0]) {
const text = anomalyFullResponse.result.content[0].text;
if (text.includes('❌')) {
console.log('⚠️ Full response contains error:', text.substring(0, 200));
} else {
console.log('📊 Full response preview:', text.substring(0, 300) + '...');
}
}
} else if (anomalyFullResponse.error === 'timeout_60s') {
console.log(`⏰ Full Anomaly Detection TIMEOUT after 60 seconds`);
console.log('💡 This confirms timeout issues with large datasets');
} else {
console.log(`❌ Full Anomaly Detection FAILED:`, anomalyFullResponse.error);
}
console.log('\n📋 SUMMARY:');
console.log(`- Authentication: ${authTime}ms`);
console.log(`- Anomaly (isFull=false): ${anomalyTime}ms`);
console.log(`- Anomaly (isFull=true): ${anomalyFullTime}ms`);
} catch (error) {
console.log('❌ Test failed:', error.message);
} finally {
server.kill();
}
}
// Show server stderr in background
const serverPath = path.join(__dirname, '../../dist/index.js');
const logServer = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe']
});
logServer.stderr.on('data', (data) => {
console.log('🔍 Server:', data.toString().trim());
});
// Kill log server when main test ends
process.on('exit', () => logServer.kill());
testStdioAnomalySimple().catch(console.error);