#!/usr/bin/env node
const { spawn } = require('child_process');
async function testQ13Final() {
console.log('🎯 FINAL Q13 CLOUDWATCH TEST');
console.log('=' .repeat(50));
console.log('Testing exact Q13 parameters after service filtering fix\n');
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'
}
});
let response = null;
let requestId = 0;
server.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const parsed = JSON.parse(line);
if (parsed.id === requestId) {
response = parsed;
}
} catch (e) {}
}
});
server.stderr.on('data', (data) => {
const msg = data.toString();
if (msg.includes('SERVICE-MATCHED') || msg.includes('SERVICE-NOT-FOUND')) {
console.log('🔍', msg.trim());
}
});
await new Promise(resolve => setTimeout(resolve, 2000));
// Authenticate
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: ++requestId, method: "tools/call",
params: {
name: 'authenticate_user',
arguments: { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' }
}
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 5000));
requestId = 0;
console.log('📊 Testing Q13: "what is the last 30 days (per day) amortized cost for Cloudwatch service?"\n');
// Exact Q13 request from goodanswers.txt
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: ++requestId, method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-07-28',
endDate: '2025-08-27',
periodGranLevel: 'day',
costType: ['cost'],
isAmortized: true,
cloud_context: 'aws',
accountId: '932213950603',
service: 'CloudWatch'
}
}
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 10000));
if (response?.result?.content?.[0]?.text) {
const text = response.result.content[0].text;
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
if (Array.isArray(data)) {
const totalCost = data.reduce((sum, item) => sum + parseFloat(item.total_cost || 0), 0);
console.log(`📊 RESULTS:`);
console.log(` Records: ${data.length} daily entries`);
console.log(` Total CloudWatch Cost (30 days): $${totalCost.toFixed(2)}`);
console.log(` Average Daily: $${(totalCost/data.length).toFixed(2)}`);
// Check against goodanswers.txt reference
if (totalCost > 4000 && totalCost < 7000) {
console.log('\n✅ SUCCESS: Service filtering working correctly!');
console.log(' Cost range matches expected CloudWatch-only filtering');
console.log(' This is significantly different from all-service costs (~$160K)');
} else if (totalCost > 100000) {
console.log('\n❌ FAILED: Still showing all services (unfiltered)');
} else {
console.log(`\n🤔 PARTIAL: Unexpected cost range: $${totalCost.toFixed(2)}`);
}
// Show date range to verify
if (data.length > 0) {
const firstDate = data[0].date_timeframe || data[0].timeframe_start || 'Unknown';
const lastDate = data[data.length-1].date_timeframe || data[data.length-1].timeframe_start || 'Unknown';
console.log(` Date range: ${firstDate} to ${lastDate}`);
}
} else {
console.log('❌ Invalid data format (not array)');
}
} catch (e) {
console.log(`❌ JSON parse error: ${e.message}`);
}
} else {
console.log('❌ No JSON found in response');
}
} else {
console.log('❌ No response received');
}
server.kill();
console.log('\n🎯 Q13 test complete!');
}
testQ13Final().catch(console.error);