- 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
496 lines
22 KiB
Python
Executable File
496 lines
22 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
AITBC CLI Level 4 Commands Test Script (CORRECTED)
|
|
|
|
Tests specialized operations and niche use cases based on ACTUAL command structure:
|
|
- Swarm intelligence operations (6 commands)
|
|
- Autonomous optimization (4 commands)
|
|
- Bitcoin exchange operations (5 commands)
|
|
- Analytics and monitoring (6 commands)
|
|
- System administration (12 commands)
|
|
|
|
Level 4 Commands: Specialized operations for expert users (CORRECTED VERSION)
|
|
"""
|
|
|
|
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 Level4CommandTesterCorrected:
|
|
"""Corrected test suite for AITBC CLI Level 4 commands (using actual command structure)"""
|
|
|
|
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 (CORRECTED)"""
|
|
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_leave_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_leave_help(self):
|
|
"""Test swarm leave help"""
|
|
result = self.runner.invoke(cli, ['swarm', 'leave', '--help'])
|
|
success = result.exit_code == 0 and 'leave' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} swarm leave: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def test_optimize_commands(self):
|
|
"""Test autonomous optimization commands (CORRECTED)"""
|
|
optimize_tests = [
|
|
lambda: self._test_optimize_predict_help(),
|
|
lambda: self._test_optimize_disable_help(),
|
|
lambda: self._test_optimize_self_opt_help(),
|
|
lambda: self._test_optimize_tune_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_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_self_opt_help(self):
|
|
"""Test optimize self-opt help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'self-opt', '--help'])
|
|
success = result.exit_code == 0 and 'self-opt' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize self-opt: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_optimize_tune_help(self):
|
|
"""Test optimize tune help"""
|
|
result = self.runner.invoke(cli, ['optimize', 'tune', '--help'])
|
|
success = result.exit_code == 0 and 'tune' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} optimize tune: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def test_exchange_commands(self):
|
|
"""Test Bitcoin exchange operations commands (CORRECTED)"""
|
|
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_rates_help(),
|
|
lambda: self._test_exchange_wallet_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_rates_help(self):
|
|
"""Test exchange rates help"""
|
|
result = self.runner.invoke(cli, ['exchange', 'rates', '--help'])
|
|
success = result.exit_code == 0 and 'rates' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} exchange rates: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_exchange_wallet_help(self):
|
|
"""Test exchange wallet help"""
|
|
result = self.runner.invoke(cli, ['exchange', 'wallet', '--help'])
|
|
success = result.exit_code == 0 and 'wallet' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} exchange wallet: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def test_analytics_commands(self):
|
|
"""Test analytics and monitoring commands (CORRECTED)"""
|
|
analytics_tests = [
|
|
lambda: self._test_analytics_dashboard_help(),
|
|
lambda: self._test_analytics_monitor_help(),
|
|
lambda: self._test_analytics_alerts_help(),
|
|
lambda: self._test_analytics_optimize_help(),
|
|
lambda: self._test_analytics_predict_help(),
|
|
lambda: self._test_analytics_summary_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_optimize_help(self):
|
|
"""Test analytics optimize help"""
|
|
result = self.runner.invoke(cli, ['analytics', 'optimize', '--help'])
|
|
success = result.exit_code == 0 and 'optimize' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} analytics optimize: {'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_admin_commands(self):
|
|
"""Test system administration commands (CORRECTED)"""
|
|
admin_tests = [
|
|
lambda: self._test_admin_activate_miner_help(),
|
|
lambda: self._test_admin_analytics_help(),
|
|
lambda: self._test_admin_audit_log_help(),
|
|
lambda: self._test_admin_deactivate_miner_help(),
|
|
lambda: self._test_admin_delete_job_help(),
|
|
lambda: self._test_admin_execute_help(),
|
|
lambda: self._test_admin_job_details_help(),
|
|
lambda: self._test_admin_jobs_help(),
|
|
lambda: self._test_admin_logs_help(),
|
|
lambda: self._test_admin_maintenance_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_activate_miner_help(self):
|
|
"""Test admin activate-miner help"""
|
|
result = self.runner.invoke(cli, ['admin', 'activate-miner', '--help'])
|
|
success = result.exit_code == 0 and 'activate-miner' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin activate-miner: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_analytics_help(self):
|
|
"""Test admin analytics help"""
|
|
result = self.runner.invoke(cli, ['admin', 'analytics', '--help'])
|
|
success = result.exit_code == 0 and 'analytics' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin analytics: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_audit_log_help(self):
|
|
"""Test admin audit-log help"""
|
|
result = self.runner.invoke(cli, ['admin', 'audit-log', '--help'])
|
|
success = result.exit_code == 0 and 'audit-log' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin audit-log: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_deactivate_miner_help(self):
|
|
"""Test admin deactivate-miner help"""
|
|
result = self.runner.invoke(cli, ['admin', 'deactivate-miner', '--help'])
|
|
success = result.exit_code == 0 and 'deactivate-miner' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin deactivate-miner: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_delete_job_help(self):
|
|
"""Test admin delete-job help"""
|
|
result = self.runner.invoke(cli, ['admin', 'delete-job', '--help'])
|
|
success = result.exit_code == 0 and 'delete-job' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin delete-job: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_execute_help(self):
|
|
"""Test admin execute help"""
|
|
result = self.runner.invoke(cli, ['admin', 'execute', '--help'])
|
|
success = result.exit_code == 0 and 'execute' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin execute: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_job_details_help(self):
|
|
"""Test admin job-details help"""
|
|
result = self.runner.invoke(cli, ['admin', 'job-details', '--help'])
|
|
success = result.exit_code == 0 and 'job-details' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin job-details: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def _test_admin_jobs_help(self):
|
|
"""Test admin jobs help"""
|
|
result = self.runner.invoke(cli, ['admin', 'jobs', '--help'])
|
|
success = result.exit_code == 0 and 'jobs' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin jobs: {'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_maintenance_help(self):
|
|
"""Test admin maintenance help"""
|
|
result = self.runner.invoke(cli, ['admin', 'maintenance', '--help'])
|
|
success = result.exit_code == 0 and 'maintenance' in result.output.lower()
|
|
print(f" {'✅' if success else '❌'} admin maintenance: {'Working' if success else 'Failed'}")
|
|
return success
|
|
|
|
def run_all_tests(self):
|
|
"""Run all Level 4 command tests (corrected version)"""
|
|
print("🚀 Starting AITBC CLI Level 4 Commands Test Suite (CORRECTED)")
|
|
print("Testing specialized operations using ACTUAL command structure")
|
|
print("=" * 60)
|
|
|
|
# Setup test environment
|
|
config_dir = Path(tempfile.mkdtemp(prefix="aitbc_level4_corrected_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 (CORRECTED)")
|
|
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 = Level4CommandTesterCorrected()
|
|
success = tester.run_all_tests()
|
|
|
|
# Exit with appropriate code
|
|
sys.exit(0 if success else 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|