#!/usr/bin/env node
const { spawn } = require('child_process');
async function comprehensiveAzureTest() {
console.log('π§ͺ COMPREHENSIVE AZURE ACCOUNT TEST');
console.log('=' .repeat(80));
console.log('Testing all Azure accounts through MCP protocol');
console.log('');
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 = {};
let requestId = 0;
server.stdout.on('data', (data) => {
console.log('π€ RAW STDOUT:', data.toString().substring(0, 200) + '...');
const lines = data.toString().split('\n').filter(line => line.trim());
for (const line of lines) {
try {
const parsed = JSON.parse(line);
if (parsed.id) responses[parsed.id] = parsed;
} catch (e) {}
}
});
server.stderr.on('data', (data) => {
const msg = data.toString();
if (msg.includes('23105') || msg.includes('AzureAmortized') || msg.includes('AZURE API key')) {
console.log('π§ AZURE LOG:', msg.trim());
}
});
await new Promise(resolve => setTimeout(resolve, 2000));
console.log('π Step 1: Authentication...\n');
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, 8000));
const authResponse = responses[requestId];
if (authResponse && authResponse.result) {
console.log('β
Authentication successful');
} else {
console.log('β Authentication failed');
server.kill();
return;
}
console.log('\nπ Step 2: Azure AzureAmortized Test (23105)...\n');
const azureTestId = ++requestId;
server.stdin.write(JSON.stringify({
jsonrpc: "2.0",
id: azureTestId,
method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-07-01',
endDate: '2025-08-26',
periodGranLevel: 'day',
costType: ['cost', 'discount'],
cloud_context: 'azure',
groupBy: 'service'
}
}
}) + '\n');
// Wait longer for Azure response
await new Promise(resolve => setTimeout(resolve, 15000));
const azureResponse = responses[azureTestId];
console.log('\nπ AZURE TEST RESULTS:');
console.log('=' .repeat(60));
if (!azureResponse) {
console.log('β CRITICAL: No response received for Azure request');
console.log(' π§ This indicates a server-side issue');
// Try a simpler request to test if it's a timeout or data issue
console.log('\nπ Fallback Test: Trying shorter date range...');
const fallbackTestId = ++requestId;
server.stdin.write(JSON.stringify({
jsonrpc: "2.0",
id: fallbackTestId,
method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-07-01',
endDate: '2025-07-05',
periodGranLevel: 'day',
costType: ['cost', 'discount'],
cloud_context: 'azure',
groupBy: 'none'
}
}
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 10000));
const fallbackResponse = responses[fallbackTestId];
if (fallbackResponse) {
console.log('β
Fallback test worked - issue is with large data set');
} else {
console.log('β Fallback test also failed - fundamental Azure routing issue');
}
} else if (azureResponse.error) {
console.log(`β CRITICAL: Azure request returned error`);
console.log(` Error: ${azureResponse.error.message || azureResponse.error}`);
} else if (azureResponse.result?.content?.[0]?.text) {
const text = azureResponse.result.content[0].text;
console.log('β
Azure response received');
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
if (Array.isArray(data) && data.length > 0) {
const accounts = new Set();
const services = new Set();
let totalCost = 0;
data.forEach(item => {
if (item.account_id) accounts.add(item.account_id);
if (item.service_name) services.add(item.service_name);
if (item.total_cost) totalCost += parseFloat(item.total_cost);
});
console.log(`π SUCCESS: ${data.length} records, $${totalCost.toFixed(2)} total`);
console.log(` Accounts: ${Array.from(accounts).join(', ')}`);
console.log(` Services: ${Array.from(services).slice(0, 5).join(', ')}`);
// Check if we got the expected AzureAmortized account data
if (Array.from(accounts).includes('AzureA-7ba44c')) {
console.log('β
PERFECT: Correct AzureAmortized account data received!');
console.log(' β
Cloud context routing is working for Azure');
console.log(' β
Account 23105 (AzureAmortized) is properly connected');
} else {
console.log(`β οΈ MISMATCH: Expected AzureA-7ba44c, got ${Array.from(accounts).join(', ')}`);
}
} else {
console.log('β οΈ Empty data array - account might not have data for this period');
}
} catch (e) {
console.log(`β JSON parsing error: ${e.message}`);
}
} else {
console.log('β οΈ No JSON found - might be error message');
console.log(`Response preview: ${text.substring(0, 200)}...`);
}
} else {
console.log('β Invalid response format');
console.log('Response structure:', JSON.stringify(azureResponse, null, 2));
}
server.kill();
console.log('\nπ― AZURE COMPREHENSIVE TEST VERDICT:');
if (azureResponse && azureResponse.result?.content?.[0]?.text) {
const text = azureResponse.result.content[0].text;
const hasJson = text.includes('```json');
if (hasJson) {
console.log('β
AZURE IS WORKING: Account 23105 routing successful');
console.log(' β
Priority selection fix worked');
console.log(' β
AzureAmortized account properly connected');
} else {
console.log('β οΈ AZURE PARTIAL: Routing works but data issue');
console.log(' β
Priority selection fix worked');
console.log(' β οΈ Data retrieval needs investigation');
}
} else {
console.log('β AZURE BROKEN: Fundamental routing issue');
console.log(' β Priority selection may not be working');
console.log(' π¨ Requires further debugging');
}
console.log('\nπ Comprehensive Azure test complete!');
}
comprehensiveAzureTest().catch(console.error);