#!/usr/bin/env node
const { spawn } = require('child_process');
async function finalAnomalyTest() {
console.log('🎯 FINAL ANOMALY TEST');
console.log('=' .repeat(30));
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
UMBRELLA_API_BASE_URL: 'https://api-front.umbrellacost.io/api/v1'
}
});
const responses = [];
server.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const response = JSON.parse(line);
responses.push(response);
} catch (e) {}
}
});
await new Promise(resolve => setTimeout(resolve, 2000));
// Auth FIRST
server.stdin.write(JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: 'authenticate_user',
arguments: {
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
}
}
}) + '\n');
console.log('🔐 Authentication sent, waiting...');
await new Promise(resolve => setTimeout(resolve, 6000));
// Then anomaly request
server.stdin.write(JSON.stringify({
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: 'api___anomaly_detection',
arguments: {
isFull: "true",
endDate: "2025-08-27",
startDate: "2025-08-18",
cloud_context: "aws"
}
}
}) + '\n');
console.log('🔍 Anomaly request sent, processing...');
let found = false;
for (let i = 0; i < 60 && !found; i++) {
await new Promise(resolve => setTimeout(resolve, 1000));
const response = responses.find(r => r.id === 2);
if (response && response.result?.content?.[0]?.text) {
found = true;
const text = response.result.content[0].text;
console.log(`✅ Got response! (${text.length} chars)`);
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
const data = JSON.parse(jsonMatch[1]);
if (data.anomalies) {
const totalImpact = data.anomalies.reduce((sum, a) => sum + parseFloat(a.totalCostImpact || 0), 0);
console.log(`\n🎉 SUCCESS!`);
console.log(`📊 Anomalies: ${data.anomalies.length}`);
console.log(`💰 Total Impact: $${totalImpact.toFixed(2)}`);
if (totalImpact > 900) console.log('🎯 MATCHES EXPECTED $962!');
}
}
break;
}
if (i % 15 === 0) console.log(`⏳ ${i}s...`);
}
server.kill();
}
finalAnomalyTest().catch(console.error);