#!/usr/bin/env node
// Тест HTTP API AI Ops Hub
import axios from 'axios';
const BASE_URL = 'http://localhost:3333';
async function testHealth() {
console.log('🧪 Тестирование /health...');
try {
const response = await axios.get(`${BASE_URL}/health`);
console.log('✅ Health check:', response.data);
} catch (error) {
console.error('❌ Health check failed:', error.message);
}
}
async function testListTools() {
console.log('\n🧪 Тестирование /tools...');
try {
const response = await axios.get(`${BASE_URL}/tools`);
console.log('✅ Tools list:', response.data);
if (response.data.result && response.data.result.tools) {
console.log(`📋 Найдено инструментов: ${response.data.result.tools.length}`);
response.data.result.tools.forEach((tool, index) => {
console.log(` ${index + 1}. ${tool.name}: ${tool.description}`);
});
}
} catch (error) {
console.error('❌ Tools list failed:', error.message);
}
}
async function testCallTool() {
console.log('\n🧪 Тестирование /call...');
try {
// Тест чтения файла
const response = await axios.post(`${BASE_URL}/call`, {
name: 'file_read',
arguments: {
path: 'test-note.md'
}
});
console.log('✅ File read tool call:', response.data);
} catch (error) {
console.error('❌ Tool call failed:', error.message);
}
}
async function testStatus() {
console.log('\n🧪 Тестирование /status...');
try {
const response = await axios.get(`${BASE_URL}/status`);
console.log('✅ Status:', response.data);
} catch (error) {
console.error('❌ Status failed:', error.message);
}
}
async function testNotFound() {
console.log('\n🧪 Тестирование 404...');
try {
const response = await axios.get(`${BASE_URL}/nonexistent`);
console.log('❌ Unexpected success:', response.data);
} catch (error) {
if (error.response && error.response.status === 404) {
console.log('✅ 404 handled correctly:', error.response.data);
} else {
console.error('❌ Unexpected error:', error.message);
}
}
}
async function runHttpTests() {
console.log('🚀 Запуск HTTP API тестов...\n');
await testHealth();
await testListTools();
await testCallTool();
await testStatus();
await testNotFound();
console.log('\n✨ HTTP API тесты завершены!');
}
runHttpTests().catch(console.error);