- Remove standalone explorer-web app (README, HTML, package files) - Add /web endpoint to blockchain-explorer for web interface access - Update .gitignore to exclude application backup archives (*.tar.gz, *.zip) - Add backup documentation files to .gitignore (BACKUP_INDEX.md, README.md) - Consolidate explorer functionality into main blockchain-explorer application
504 lines
22 KiB
Python
Executable File
504 lines
22 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
AITBC CLI Level 4 Commands Test Script
|
|
|
|
Tests specialized operations and niche use cases:
|
|
- Swarm intelligence operations (6 commands)
|
|
- Autonomous optimization (7 commands)
|
|
- Bitcoin exchange operations (5 commands)
|
|
- Analytics and monitoring (6 commands)
|
|
- System administration (8 commands)
|
|
|
|
Level 4 Commands: Specialized operations for expert users
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import json
|
|
import tempfile
|
|
import shutil
|
|
from pathlib import Path
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
# Add CLI to path
|
|
sys.path.insert(0, '/home/oib/windsurf/aitbc/cli')
|
|
|
|
from click.testing import CliRunner
|
|
from aitbc_cli.main import cli
|
|
from aitbc_cli.config import Config
|
|
|
|
# Import test utilities
|
|
try:
|
|
from utils.test_helpers import TestEnvironment, mock_api_responses
|
|
from utils.command_tester import CommandTester
|
|
except ImportError:
|
|
# Fallback if utils not in path
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from utils.test_helpers import TestEnvironment, mock_api_responses
|
|
from utils.command_tester import CommandTester
|
|
|
|
|
|
class Level4CommandTester:
|
|
"""Test suite for AITBC CLI Level 4 commands (specialized operations)"""
|
|
|
|
def __init__(self):
|
|
self.runner = CliRunner()
|
|
self.test_results = {
|
|
'passed': 0,
|
|
'failed': 0,
|
|
'skipped': 0,
|
|
'tests': []
|
|
}
|
|
self.temp_dir = None
|
|
|
|
def cleanup(self):
|
|
"""Cleanup test environment"""
|
|
if self.temp_dir and os.path.exists(self.temp_dir):
|
|
shutil.rmtree(self.temp_dir)
|
|
print(f"🧹 Cleaned up test environment")
|
|
|
|
def run_test(self, test_name, test_func):
|
|
"""Run a single test and track results"""
|
|
print(f"\n🧪 Running: {test_name}")
|
|
try:
|
|
result = test_func()
|
|
if result:
|
|
print(f"✅ PASSED: {test_name}")
|
|
self.test_results['passed'] += 1
|
|
self.test_results['tests'].append({'name': test_name, 'status': 'PASSED'})
|
|
else:
|
|
print(f"❌ FAILED: {test_name}")
|
|
self.test_results['failed'] += 1
|
|
self.test_results['tests'].append({'name': test_name, 'status': 'FAILED'})
|
|
except Exception as e:
|
|
print(f"💥 ERROR: {test_name} - {str(e)}")
|
|
self.test_results['failed'] += 1
|
|
self.test_results['tests'].append({'name': test_name, 'status': 'ERROR', 'error': str(e)})
|
|
|
|
def test_swarm_commands(self):
|
|
"""Test swarm intelligence operations commands"""
|
|
swarm_tests = [
|
|
lambda: self._test_swarm_join_help(),
|
|
lambda: self._test_swarm_coordinate_help(),
|
|
lambda: self._test_swarm_consensus_help(),
|
|
lambda: self._test_swarm_status_help(),
|
|
lambda: self._test_swarm_list_help(),
|
|
lambda: self._test_swarm_optimize_help()
|
|
]
|
|
|
|
results = []
|
|
for test in swarm_tests:
|
|
try:
|
|
result = test()
|
|
results.append(result)
|
|
except Exception as e:
|
|
print(f" ❌ Swarm test error: {str(e)}")
|
|
results.append(False)
|
|
|
|
success_count = sum(results)
|
|
print(f" Swarm commands: {success_count}/{len(results)} passed")
|
|
return success_count >= len(results) * 0.7 # 70% pass rate
|
|
|
|
def _test_swarm_join_help(self):
|
|
"""Test swarm join help"""
|
|
result = self.runner.invoke(cli, ['swarm', 'join', '--help'])
|
|
success = result.exit_code == 0 and 'join' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} swarm join: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_swarm_coordinate_help(self):
|
|
"""Test swarm coordinate help"""
|
|
result = self.runner.invoke(cli, ['swarm', 'coordinate', '--help'])
|
|
success = result.exit_code == 0 and 'coordinate' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} swarm coordinate: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_swarm_consensus_help(self):
|
|
"""Test swarm consensus help"""
|
|
result = self.runner.invoke(cli, ['swarm', 'consensus', '--help'])
|
|
success = result.exit_code == 0 and 'consensus' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} swarm consensus: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_swarm_status_help(self):
|
|
"""Test swarm status help"""
|
|
result = self.runner.invoke(cli, ['swarm', 'status', '--help'])
|
|
success = result.exit_code == 0 and 'status' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} swarm status: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_swarm_list_help(self):
|
|
"""Test swarm list help"""
|
|
result = self.runner.invoke(cli, ['swarm', 'list', '--help'])
|
|
success = result.exit_code == 0 and 'list' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} swarm list: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_swarm_optimize_help(self):
|
|
"""Test swarm optimize help"""
|
|
result = self.runner.invoke(cli, ['swarm', 'optimize', '--help'])
|
|
success = result.exit_code == 0 and 'optimize' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} swarm optimize: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def test_optimize_commands(self):
|
|
"""Test autonomous optimization commands"""
|
|
optimize_tests = [
|
|
lambda: self._test_optimize_predict_help(),
|
|
lambda: self._test_optimize_performance_help(),
|
|
lambda: self._test_optimize_resources_help(),
|
|
lambda: self._test_optimize_network_help(),
|
|
lambda: self._test_optimize_disable_help(),
|
|
lambda: self._test_optimize_enable_help(),
|
|
lambda: self._test_optimize_status_help()
|
|
]
|
|
|
|
results = []
|
|
for test in optimize_tests:
|
|
try:
|
|
result = test()
|
|
results.append(result)
|
|
except Exception as e:
|
|
print(f" ❌ Optimize test error: {str(e)}")
|
|
results.append(False)
|
|
|
|
success_count = sum(results)
|
|
print(f" Optimize commands: {success_count}/{len(results)} passed")
|
|
return success_count >= len(results) * 0.7 # 70% pass rate
|
|
|
|
def _test_optimize_predict_help(self):
|
|
"""Test optimize predict help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'predict', '--help'])
|
|
success = result.exit_code == 0 and 'predict' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize predict: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_optimize_performance_help(self):
|
|
"""Test optimize performance help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'predict', 'performance', '--help'])
|
|
success = result.exit_code == 0 and 'performance' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize performance: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_optimize_resources_help(self):
|
|
"""Test optimize resources help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'predict', 'resources', '--help'])
|
|
success = result.exit_code == 0 and 'resources' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize resources: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_optimize_network_help(self):
|
|
"""Test optimize network help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'predict', 'network', '--help'])
|
|
success = result.exit_code == 0 and 'network' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize network: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_optimize_disable_help(self):
|
|
"""Test optimize disable help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'disable', '--help'])
|
|
success = result.exit_code == 0 and 'disable' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize disable: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_optimize_enable_help(self):
|
|
"""Test optimize enable help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'enable', '--help'])
|
|
success = result.exit_code == 0 and 'enable' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize enable: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_optimize_status_help(self):
|
|
"""Test optimize status help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'status', '--help'])
|
|
success = result.exit_code == 0 and 'status' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize status: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def test_exchange_commands(self):
|
|
"""Test Bitcoin exchange operations commands"""
|
|
exchange_tests = [
|
|
lambda: self._test_exchange_create_payment_help(),
|
|
lambda: self._test_exchange_payment_status_help(),
|
|
lambda: self._test_exchange_market_stats_help(),
|
|
lambda: self._test_exchange_rate_help(),
|
|
lambda: self._test_exchange_history_help()
|
|
]
|
|
|
|
results = []
|
|
for test in exchange_tests:
|
|
try:
|
|
result = test()
|
|
results.append(result)
|
|
except Exception as e:
|
|
print(f" ❌ Exchange test error: {str(e)}")
|
|
results.append(False)
|
|
|
|
success_count = sum(results)
|
|
print(f" Exchange commands: {success_count}/{len(results)} passed")
|
|
return success_count >= len(results) * 0.7 # 70% pass rate
|
|
|
|
def _test_exchange_create_payment_help(self):
|
|
"""Test exchange create-payment help"""
|
|
result = self.runner.invoke(cli, ['exchange', 'create-payment', '--help'])
|
|
success = result.exit_code == 0 and 'create-payment' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} exchange create-payment: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_exchange_payment_status_help(self):
|
|
"""Test exchange payment-status help"""
|
|
result = self.runner.invoke(cli, ['exchange', 'payment-status', '--help'])
|
|
success = result.exit_code == 0 and 'payment-status' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} exchange payment-status: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_exchange_market_stats_help(self):
|
|
"""Test exchange market-stats help"""
|
|
result = self.runner.invoke(cli, ['exchange', 'market-stats', '--help'])
|
|
success = result.exit_code == 0 and 'market-stats' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} exchange market-stats: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_exchange_rate_help(self):
|
|
"""Test exchange rate help"""
|
|
result = self.runner.invoke(cli, ['exchange', 'rate', '--help'])
|
|
success = result.exit_code == 0 and 'rate' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} exchange rate: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_exchange_history_help(self):
|
|
"""Test exchange history help"""
|
|
result = self.runner.invoke(cli, ['exchange', 'history', '--help'])
|
|
success = result.exit_code == 0 and 'history' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} exchange history: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def test_analytics_commands(self):
|
|
"""Test analytics and monitoring commands"""
|
|
analytics_tests = [
|
|
lambda: self._test_analytics_dashboard_help(),
|
|
lambda: self._test_analytics_monitor_help(),
|
|
lambda: self._test_analytics_alerts_help(),
|
|
lambda: self._test_analytics_predict_help(),
|
|
lambda: self._test_analytics_summary_help(),
|
|
lambda: self._test_analytics_trends_help()
|
|
]
|
|
|
|
results = []
|
|
for test in analytics_tests:
|
|
try:
|
|
result = test()
|
|
results.append(result)
|
|
except Exception as e:
|
|
print(f" ❌ Analytics test error: {str(e)}")
|
|
results.append(False)
|
|
|
|
success_count = sum(results)
|
|
print(f" Analytics commands: {success_count}/{len(results)} passed")
|
|
return success_count >= len(results) * 0.7 # 70% pass rate
|
|
|
|
def _test_analytics_dashboard_help(self):
|
|
"""Test analytics dashboard help"""
|
|
result = self.runner.invoke(cli, ['analytics', 'dashboard', '--help'])
|
|
success = result.exit_code == 0 and 'dashboard' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} analytics dashboard: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_analytics_monitor_help(self):
|
|
"""Test analytics monitor help"""
|
|
result = self.runner.invoke(cli, ['analytics', 'monitor', '--help'])
|
|
success = result.exit_code == 0 and 'monitor' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} analytics monitor: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_analytics_alerts_help(self):
|
|
"""Test analytics alerts help"""
|
|
result = self.runner.invoke(cli, ['analytics', 'alerts', '--help'])
|
|
success = result.exit_code == 0 and 'alerts' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} analytics alerts: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_analytics_predict_help(self):
|
|
"""Test analytics predict help"""
|
|
result = self.runner.invoke(cli, ['analytics', 'predict', '--help'])
|
|
success = result.exit_code == 0 and 'predict' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} analytics predict: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_analytics_summary_help(self):
|
|
"""Test analytics summary help"""
|
|
result = self.runner.invoke(cli, ['analytics', 'summary', '--help'])
|
|
success = result.exit_code == 0 and 'summary' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} analytics summary: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_analytics_trends_help(self):
|
|
"""Test analytics trends help"""
|
|
result = self.runner.invoke(cli, ['analytics', 'trends', '--help'])
|
|
success = result.exit_code == 0 and 'trends' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} analytics trends: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def test_admin_commands(self):
|
|
"""Test system administration commands"""
|
|
admin_tests = [
|
|
lambda: self._test_admin_backup_help(),
|
|
lambda: self._test_admin_restore_help(),
|
|
lambda: self._test_admin_logs_help(),
|
|
lambda: self._test_admin_status_help(),
|
|
lambda: self._test_admin_update_help(),
|
|
lambda: self._test_admin_users_help(),
|
|
lambda: self._test_admin_config_help(),
|
|
lambda: self._test_admin_monitor_help()
|
|
]
|
|
|
|
results = []
|
|
for test in admin_tests:
|
|
try:
|
|
result = test()
|
|
results.append(result)
|
|
except Exception as e:
|
|
print(f" ❌ Admin test error: {str(e)}")
|
|
results.append(False)
|
|
|
|
success_count = sum(results)
|
|
print(f" Admin commands: {success_count}/{len(results)} passed")
|
|
return success_count >= len(results) * 0.7 # 70% pass rate
|
|
|
|
def _test_admin_backup_help(self):
|
|
"""Test admin backup help"""
|
|
result = self.runner.invoke(cli, ['admin', 'backup', '--help'])
|
|
success = result.exit_code == 0 and 'backup' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin backup: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_restore_help(self):
|
|
"""Test admin restore help"""
|
|
result = self.runner.invoke(cli, ['admin', 'restore', '--help'])
|
|
success = result.exit_code == 0 and 'restore' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin restore: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_logs_help(self):
|
|
"""Test admin logs help"""
|
|
result = self.runner.invoke(cli, ['admin', 'logs', '--help'])
|
|
success = result.exit_code == 0 and 'logs' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin logs: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_status_help(self):
|
|
"""Test admin status help"""
|
|
result = self.runner.invoke(cli, ['admin', 'status', '--help'])
|
|
success = result.exit_code == 0 and 'status' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin status: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_update_help(self):
|
|
"""Test admin update help"""
|
|
result = self.runner.invoke(cli, ['admin', 'update', '--help'])
|
|
success = result.exit_code == 0 and 'update' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin update: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_users_help(self):
|
|
"""Test admin users help"""
|
|
result = self.runner.invoke(cli, ['admin', 'users', '--help'])
|
|
success = result.exit_code == 0 and 'users' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin users: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_config_help(self):
|
|
"""Test admin config help"""
|
|
result = self.runner.invoke(cli, ['admin', 'config', '--help'])
|
|
success = result.exit_code == 0 and 'config' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin config: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_monitor_help(self):
|
|
"""Test admin monitor help"""
|
|
result = self.runner.invoke(cli, ['admin', 'monitor', '--help'])
|
|
success = result.exit_code == 0 and 'monitor' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin monitor: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def run_all_tests(self):
|
|
"""Run all Level 4 command tests"""
|
|
print("🚀 Starting AITBC CLI Level 4 Commands Test Suite")
|
|
print("Testing specialized operations for expert users")
|
|
print("=" * 60)
|
|
|
|
# Setup test environment
|
|
config_dir = Path(tempfile.mkdtemp(prefix="aitbc_level4_test_"))
|
|
self.temp_dir = str(config_dir)
|
|
print(f"📁 Test environment: {self.temp_dir}")
|
|
|
|
try:
|
|
# Run test categories
|
|
test_categories = [
|
|
("Swarm Commands", self.test_swarm_commands),
|
|
("Optimize Commands", self.test_optimize_commands),
|
|
("Exchange Commands", self.test_exchange_commands),
|
|
("Analytics Commands", self.test_analytics_commands),
|
|
("Admin Commands", self.test_admin_commands)
|
|
]
|
|
|
|
for category_name, test_func in test_categories:
|
|
print(f"\n📂 Testing {category_name}")
|
|
print("-" * 40)
|
|
self.run_test(category_name, test_func)
|
|
|
|
finally:
|
|
# Cleanup
|
|
self.cleanup()
|
|
|
|
# Print results
|
|
self.print_results()
|
|
|
|
def print_results(self):
|
|
"""Print test results summary"""
|
|
print("\n" + "=" * 60)
|
|
print("📊 LEVEL 4 TEST RESULTS SUMMARY")
|
|
print("=" * 60)
|
|
|
|
total = self.test_results['passed'] + self.test_results['failed'] + self.test_results['skipped']
|
|
|
|
print(f"Total Test Categories: {total}")
|
|
print(f"✅ Passed: {self.test_results['passed']}")
|
|
print(f"❌ Failed: {self.test_results['failed']}")
|
|
print(f"⏭️ Skipped: {self.test_results['skipped']}")
|
|
|
|
if self.test_results['failed'] > 0:
|
|
print(f"\n❌ Failed Tests:")
|
|
for test in self.test_results['tests']:
|
|
if test['status'] in ['FAILED', 'ERROR']:
|
|
print(f" - {test['name']}")
|
|
if 'error' in test:
|
|
print(f" Error: {test['error']}")
|
|
|
|
success_rate = (self.test_results['passed'] / total * 100) if total > 0 else 0
|
|
print(f"\n🎯 Success Rate: {success_rate:.1f}%")
|
|
|
|
if success_rate >= 90:
|
|
print("🎉 EXCELLENT: Level 4 commands are in great shape!")
|
|
elif success_rate >= 75:
|
|
print("👍 GOOD: Most Level 4 commands are working properly")
|
|
elif success_rate >= 50:
|
|
print("⚠️ FAIR: Some Level 4 commands need attention")
|
|
else:
|
|
print("🚨 POOR: Many Level 4 commands need immediate attention")
|
|
|
|
return self.test_results['failed'] == 0
|
|
|
|
|
|
def main():
|
|
"""Main entry point"""
|
|
tester = Level4CommandTester()
|
|
success = tester.run_all_tests()
|
|
|
|
# Exit with appropriate code
|
|
sys.exit(0 if success else 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|