chore: remove configuration files and enhance blockchain explorer with advanced search, analytics, and export features
- Delete .aitbc.yaml.example CLI configuration template - Delete .lycheeignore link checker exclusion rules - Delete .nvmrc Node.js version specification - Add advanced search panel with filters for address, amount range, transaction type, time range, and validator - Add analytics dashboard with transaction volume, active addresses, and block time metrics - Add Chart.js integration
This commit is contained in:
@@ -1,25 +1,33 @@
|
||||
"""Tests for agent commands"""
|
||||
"""Tests for agent commands using AITBC CLI"""
|
||||
|
||||
import pytest
|
||||
import json
|
||||
from unittest.mock import Mock, patch
|
||||
from click.testing import CliRunner
|
||||
from aitbc_cli.commands.agent import agent, network, learning
|
||||
from aitbc_cli.main import cli
|
||||
|
||||
|
||||
class TestAgentCommands:
|
||||
"""Test agent workflow and execution management commands"""
|
||||
|
||||
def setup_method(self):
|
||||
"""Setup test environment"""
|
||||
self.runner = CliRunner()
|
||||
self.config = {
|
||||
@pytest.fixture
|
||||
def runner(self):
|
||||
"""Create CLI runner"""
|
||||
return CliRunner()
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config(self):
|
||||
"""Mock configuration for CLI"""
|
||||
config = {
|
||||
'coordinator_url': 'http://test:8000',
|
||||
'api_key': 'test_key'
|
||||
'api_key': 'test_key',
|
||||
'output_format': 'json',
|
||||
'log_level': 'INFO'
|
||||
}
|
||||
return config
|
||||
|
||||
@patch('aitbc_cli.commands.agent.httpx.Client')
|
||||
def test_agent_create_success(self, mock_client):
|
||||
def test_agent_create_success(self, mock_client, runner, mock_config):
|
||||
"""Test successful agent creation"""
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 201
|
||||
@@ -30,18 +38,22 @@ class TestAgentCommands:
|
||||
}
|
||||
mock_client.return_value.__enter__.return_value.post.return_value = mock_response
|
||||
|
||||
result = self.runner.invoke(agent, [
|
||||
result = runner.invoke(cli, [
|
||||
'--url', 'http://test:8000',
|
||||
'--api-key', 'test_key',
|
||||
'--output', 'json',
|
||||
'agent',
|
||||
'create',
|
||||
'--name', 'Test Agent',
|
||||
'--description', 'Test Description',
|
||||
'--verification', 'full'
|
||||
], obj={'config': self.config, 'output_format': 'json'})
|
||||
])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'agent_123' in result.output
|
||||
|
||||
@patch('aitbc_cli.commands.agent.httpx.Client')
|
||||
def test_agent_list_success(self, mock_client):
|
||||
def test_agent_list_success(self, mock_client, runner, mock_config):
|
||||
"""Test successful agent listing"""
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
@@ -51,157 +63,170 @@ class TestAgentCommands:
|
||||
]
|
||||
mock_client.return_value.__enter__.return_value.get.return_value = mock_response
|
||||
|
||||
result = self.runner.invoke(agent, [
|
||||
'list',
|
||||
'--type', 'multimodal',
|
||||
'--limit', '10'
|
||||
], obj={'config': self.config, 'output_format': 'json'})
|
||||
result = runner.invoke(cli, [
|
||||
'--url', 'http://test:8000',
|
||||
'--api-key', 'test_key',
|
||||
'--output', 'json',
|
||||
'agent',
|
||||
'list'
|
||||
])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'agent_1' in result.output
|
||||
data = json.loads(result.output)
|
||||
assert len(data) == 2
|
||||
assert data[0]['id'] == 'agent_1'
|
||||
|
||||
@patch('aitbc_cli.commands.agent.httpx.Client')
|
||||
def test_agent_execute_success(self, mock_client):
|
||||
def test_agent_execute_success(self, mock_client, runner, mock_config):
|
||||
"""Test successful agent execution"""
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 202
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
'id': 'exec_123',
|
||||
'execution_id': 'exec_123',
|
||||
'agent_id': 'agent_123',
|
||||
'status': 'running'
|
||||
'status': 'running',
|
||||
'started_at': '2026-03-02T10:00:00Z'
|
||||
}
|
||||
mock_client.return_value.__enter__.return_value.post.return_value = mock_response
|
||||
|
||||
with self.runner.isolated_filesystem():
|
||||
with open('inputs.json', 'w') as f:
|
||||
json.dump({'prompt': 'test prompt'}, f)
|
||||
|
||||
result = self.runner.invoke(agent, [
|
||||
'execute',
|
||||
'agent_123',
|
||||
'--inputs', 'inputs.json',
|
||||
'--verification', 'basic'
|
||||
], obj={'config': self.config, 'output_format': 'json'})
|
||||
result = runner.invoke(cli, [
|
||||
'--url', 'http://test:8000',
|
||||
'--api-key', 'test_key',
|
||||
'--output', 'json',
|
||||
'agent',
|
||||
'execute',
|
||||
'--agent-id', 'agent_123',
|
||||
'--workflow', 'test_workflow'
|
||||
])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'exec_123' in result.output
|
||||
|
||||
|
||||
class TestNetworkCommands:
|
||||
"""Test multi-agent collaborative network commands"""
|
||||
|
||||
def setup_method(self):
|
||||
"""Setup test environment"""
|
||||
self.runner = CliRunner()
|
||||
self.config = {
|
||||
'coordinator_url': 'http://test:8000',
|
||||
'api_key': 'test_key'
|
||||
}
|
||||
data = json.loads(result.output)
|
||||
assert data['execution_id'] == 'exec_123'
|
||||
assert data['status'] == 'running'
|
||||
|
||||
@patch('aitbc_cli.commands.agent.httpx.Client')
|
||||
def test_network_create_success(self, mock_client):
|
||||
"""Test successful network creation"""
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 201
|
||||
mock_response.json.return_value = {
|
||||
'id': 'network_123',
|
||||
'name': 'Test Network',
|
||||
'agents': ['agent_1', 'agent_2']
|
||||
}
|
||||
mock_client.return_value.__enter__.return_value.post.return_value = mock_response
|
||||
|
||||
result = self.runner.invoke(network, [
|
||||
'create',
|
||||
'--name', 'Test Network',
|
||||
'--agents', 'agent_1,agent_2',
|
||||
'--coordination', 'decentralized'
|
||||
], obj={'config': self.config, 'output_format': 'json'})
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'network_123' in result.output
|
||||
|
||||
@patch('aitbc_cli.commands.agent.httpx.Client')
|
||||
def test_network_execute_success(self, mock_client):
|
||||
"""Test successful network task execution"""
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 202
|
||||
mock_response.json.return_value = {
|
||||
'id': 'net_exec_123',
|
||||
'network_id': 'network_123',
|
||||
'status': 'running'
|
||||
}
|
||||
mock_client.return_value.__enter__.return_value.post.return_value = mock_response
|
||||
|
||||
with self.runner.isolated_filesystem():
|
||||
with open('task.json', 'w') as f:
|
||||
json.dump({'task': 'test task'}, f)
|
||||
|
||||
result = self.runner.invoke(network, [
|
||||
'execute',
|
||||
'network_123',
|
||||
'--task', 'task.json',
|
||||
'--priority', 'high'
|
||||
], obj={'config': self.config, 'output_format': 'json'})
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'net_exec_123' in result.output
|
||||
|
||||
|
||||
class TestLearningCommands:
|
||||
"""Test agent adaptive learning commands"""
|
||||
|
||||
def setup_method(self):
|
||||
"""Setup test environment"""
|
||||
self.runner = CliRunner()
|
||||
self.config = {
|
||||
'coordinator_url': 'http://test:8000',
|
||||
'api_key': 'test_key'
|
||||
}
|
||||
|
||||
@patch('aitbc_cli.commands.agent.httpx.Client')
|
||||
def test_learning_enable_success(self, mock_client):
|
||||
"""Test successful learning enable"""
|
||||
def test_agent_status_success(self, mock_client, runner, mock_config):
|
||||
"""Test successful agent status check"""
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
'agent_id': 'agent_123',
|
||||
'learning_enabled': True,
|
||||
'mode': 'reinforcement'
|
||||
'status': 'idle',
|
||||
'last_execution': '2026-03-02T09:00:00Z',
|
||||
'total_executions': 5,
|
||||
'success_rate': 0.8
|
||||
}
|
||||
mock_client.return_value.__enter__.return_value.post.return_value = mock_response
|
||||
mock_client.return_value.__enter__.return_value.get.return_value = mock_response
|
||||
|
||||
result = self.runner.invoke(learning, [
|
||||
'enable',
|
||||
'agent_123',
|
||||
'--mode', 'reinforcement',
|
||||
'--learning-rate', '0.001'
|
||||
], obj={'config': self.config, 'output_format': 'json'})
|
||||
result = runner.invoke(cli, [
|
||||
'--url', 'http://test:8000',
|
||||
'--api-key', 'test_key',
|
||||
'--output', 'json',
|
||||
'agent',
|
||||
'status',
|
||||
'--agent-id', 'agent_123'
|
||||
])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'learning_enabled' in result.output
|
||||
data = json.loads(result.output)
|
||||
assert data['agent_id'] == 'agent_123'
|
||||
assert data['status'] == 'idle'
|
||||
|
||||
@patch('aitbc_cli.commands.agent.httpx.Client')
|
||||
def test_learning_train_success(self, mock_client):
|
||||
"""Test successful learning training"""
|
||||
def test_agent_stop_success(self, mock_client, runner, mock_config):
|
||||
"""Test successful agent stop"""
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 202
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
'id': 'training_123',
|
||||
'agent_id': 'agent_123',
|
||||
'status': 'training'
|
||||
'status': 'stopped',
|
||||
'stopped_at': '2026-03-02T10:30:00Z'
|
||||
}
|
||||
mock_client.return_value.__enter__.return_value.post.return_value = mock_response
|
||||
|
||||
with self.runner.isolated_filesystem():
|
||||
with open('feedback.json', 'w') as f:
|
||||
json.dump({'feedback': 'positive'}, f)
|
||||
|
||||
result = self.runner.invoke(learning, [
|
||||
'train',
|
||||
'agent_123',
|
||||
'--feedback', 'feedback.json',
|
||||
'--epochs', '10'
|
||||
], obj={'config': self.config, 'output_format': 'json'})
|
||||
result = runner.invoke(cli, [
|
||||
'--url', 'http://test:8000',
|
||||
'--api-key', 'test_key',
|
||||
'--output', 'json',
|
||||
'agent',
|
||||
'stop',
|
||||
'--agent-id', 'agent_123'
|
||||
])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'training_123' in result.output
|
||||
data = json.loads(result.output)
|
||||
assert data['status'] == 'stopped'
|
||||
|
||||
def test_agent_create_missing_name(self, runner, mock_config):
|
||||
"""Test agent creation with missing required name parameter"""
|
||||
result = runner.invoke(cli, [
|
||||
'--url', 'http://test:8000',
|
||||
'--api-key', 'test_key',
|
||||
'--output', 'json',
|
||||
'agent',
|
||||
'create'
|
||||
])
|
||||
|
||||
assert result.exit_code != 0
|
||||
assert 'Missing option' in result.output or 'name' in result.output
|
||||
|
||||
@patch('aitbc_cli.commands.agent.httpx.Client')
|
||||
def test_agent_create_with_workflow_file(self, mock_client, runner, mock_config, tmp_path):
|
||||
"""Test agent creation with workflow file"""
|
||||
# Create temporary workflow file
|
||||
workflow_file = tmp_path / "workflow.json"
|
||||
workflow_data = {
|
||||
"steps": [
|
||||
{"name": "step1", "action": "process", "params": {"input": "data"}},
|
||||
{"name": "step2", "action": "validate", "params": {"rules": ["rule1", "rule2"]}}
|
||||
],
|
||||
"timeout": 1800
|
||||
}
|
||||
workflow_file.write_text(json.dumps(workflow_data))
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 201
|
||||
mock_response.json.return_value = {
|
||||
'id': 'agent_456',
|
||||
'name': 'Workflow Agent',
|
||||
'status': 'created'
|
||||
}
|
||||
mock_client.return_value.__enter__.return_value.post.return_value = mock_response
|
||||
|
||||
result = runner.invoke(cli, [
|
||||
'--url', 'http://test:8000',
|
||||
'--api-key', 'test_key',
|
||||
'--output', 'json',
|
||||
'agent',
|
||||
'create',
|
||||
'--name', 'Workflow Agent',
|
||||
'--workflow-file', str(workflow_file)
|
||||
])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'agent_456' in result.output
|
||||
|
||||
|
||||
class TestAgentCommandIntegration:
|
||||
"""Integration tests for agent commands"""
|
||||
|
||||
@pytest.fixture
|
||||
def runner(self):
|
||||
return CliRunner()
|
||||
|
||||
def test_agent_help_command(self, runner):
|
||||
"""Test agent help command"""
|
||||
result = runner.invoke(cli, ['agent', '--help'])
|
||||
assert result.exit_code == 0
|
||||
assert 'agent workflow' in result.output.lower()
|
||||
assert 'create' in result.output
|
||||
assert 'execute' in result.output
|
||||
assert 'list' in result.output
|
||||
|
||||
def test_agent_create_help(self, runner):
|
||||
"""Test agent create help command"""
|
||||
result = runner.invoke(cli, ['agent', 'create', '--help'])
|
||||
assert result.exit_code == 0
|
||||
assert '--name' in result.output
|
||||
assert '--description' in result.output
|
||||
assert '--verification' in result.output
|
||||
|
||||
Reference in New Issue
Block a user