docs: update CLI command syntax across workflow documentation
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Waiting to run
CLI Tests / test-cli (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Documentation Validation / validate-docs (push) Has been cancelled

- Updated marketplace commands: `marketplace --action` → `market` subcommands
- Updated wallet commands: direct flags → `wallet` subcommands
- Updated AI commands: `ai-submit`, `ai-status` → `ai submit`, `ai status`
- Updated blockchain commands: `chain` → `blockchain info`
- Standardized command structure across all workflow files
- Affected files: MULTI_NODE_MASTER_INDEX.md, TEST_MASTER_INDEX.md, multi-node-blockchain-marketplace
This commit is contained in:
aitbc
2026-04-08 12:10:21 +02:00
parent ef4a1c0e87
commit 40ddf89b9c
251 changed files with 3555 additions and 61407 deletions

View File

@@ -12,13 +12,13 @@ def run_cli_test():
# Set up environment
cli_dir = Path(__file__).parent.parent
venv_python = "/opt/aitbc/venv/bin/python"
cli_bin = "/opt/aitbc/aitbc-cli"
# Test 1: CLI help command
print("\n1. Testing CLI help command...")
try:
result = subprocess.run(
[venv_python, "aitbc_cli.py", "--help"],
[cli_bin, "--help"],
capture_output=True,
text=True,
timeout=10,
@@ -38,7 +38,7 @@ def run_cli_test():
print("\n2. Testing CLI list command...")
try:
result = subprocess.run(
[venv_python, "aitbc_cli.py", "list"],
[cli_bin, "wallet", "list"],
capture_output=True,
text=True,
timeout=10,
@@ -58,7 +58,7 @@ def run_cli_test():
print("\n3. Testing CLI blockchain command...")
try:
result = subprocess.run(
[venv_python, "aitbc_cli.py", "chain"],
[cli_bin, "blockchain", "info"],
capture_output=True,
text=True,
timeout=10,
@@ -78,7 +78,7 @@ def run_cli_test():
print("\n4. Testing CLI invalid command handling...")
try:
result = subprocess.run(
[venv_python, "aitbc_cli.py", "invalid-command"],
[cli_bin, "invalid-command"],
capture_output=True,
text=True,
timeout=10,

View File

@@ -1,146 +1,98 @@
#!/usr/bin/env python3
"""Basic CLI tests for AITBC CLI functionality."""
"""Basic CLI tests for the unified AITBC command hierarchy."""
import pytest
import importlib.util
import json
import subprocess
import sys
import os
from pathlib import Path
# Add CLI to path for imports
sys.path.insert(0, str(Path(__file__).parent.parent))
CLI_DIR = Path(__file__).resolve().parent.parent
PROJECT_ROOT = CLI_DIR.parent
CLI_FILE = CLI_DIR / "aitbc_cli.py"
UNIFIED_FILE = CLI_DIR / "unified_cli.py"
CLI_BIN = PROJECT_ROOT / "aitbc-cli"
def run_cli(*args):
return subprocess.run(
[str(CLI_BIN), *args],
capture_output=True,
text=True,
timeout=15,
cwd=str(PROJECT_ROOT),
)
class TestCLIImports:
"""Test CLI module imports."""
"""Test direct file-based CLI module imports."""
def test_cli_main_import(self):
"""Test that main CLI module can be imported."""
try:
from aitbc_cli import main
assert main is not None
print("✅ CLI main import successful")
except ImportError as e:
pytest.fail(f"❌ CLI main import failed: {e}")
def test_cli_commands_import(self):
"""Test that CLI command modules can be imported."""
try:
from commands.wallet import create_wallet, list_wallets
from commands.blockchain import get_blockchain_info
assert create_wallet is not None
assert list_wallets is not None
assert get_blockchain_info is not None
print("✅ CLI commands import successful")
except ImportError as e:
pytest.fail(f"❌ CLI commands import failed: {e}")
spec = importlib.util.spec_from_file_location("aitbc_cli_file", CLI_FILE)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
assert callable(module.main)
def test_unified_cli_import(self):
spec = importlib.util.spec_from_file_location("unified_cli_file", UNIFIED_FILE)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
assert callable(module.run_cli)
class TestCLIBasicFunctionality:
"""Test basic CLI functionality."""
"""Test the visible command tree and core commands."""
def test_cli_help_output(self):
"""Test that CLI help command works."""
try:
result = subprocess.run(
[sys.executable, "aitbc_cli.py", "--help"],
capture_output=True,
text=True,
timeout=10,
cwd=str(Path(__file__).parent.parent)
)
assert result.returncode == 0
assert "AITBC CLI" in result.stdout
assert "usage:" in result.stdout
print("✅ CLI help output working")
except subprocess.TimeoutExpired:
pytest.fail("❌ CLI help command timed out")
except Exception as e:
pytest.fail(f"❌ CLI help command failed: {e}")
def test_cli_list_command(self):
"""Test that CLI list command works."""
try:
result = subprocess.run(
[sys.executable, "aitbc_cli.py", "list"],
capture_output=True,
text=True,
timeout=10,
cwd=str(Path(__file__).parent.parent)
)
# Command should succeed even if no wallets exist
assert result.returncode == 0
print("✅ CLI list command working")
except subprocess.TimeoutExpired:
pytest.fail("❌ CLI list command timed out")
except Exception as e:
pytest.fail(f"❌ CLI list command failed: {e}")
result = run_cli("--help")
assert result.returncode == 0
assert "AITBC CLI" in result.stdout
assert "wallet" in result.stdout
assert "blockchain" in result.stdout
assert "ai" in result.stdout
assert "market" in result.stdout
def test_cli_version_output(self):
result = run_cli("--version")
assert result.returncode == 0
assert "2.1.0" in result.stdout
def test_nested_wallet_list_command(self):
result = run_cli("wallet", "list")
assert result.returncode == 0
def test_legacy_wallet_list_alias(self):
result = run_cli("list")
assert result.returncode == 0
def test_json_output_flag(self):
result = run_cli("--output", "json", "wallet", "list")
assert result.returncode == 0
json.loads(result.stdout or "[]")
class TestCLIErrorHandling:
"""Test CLI error handling."""
def test_cli_invalid_command(self):
"""Test that CLI handles invalid commands gracefully."""
try:
result = subprocess.run(
[sys.executable, "aitbc_cli.py", "invalid-command"],
capture_output=True,
text=True,
timeout=10,
cwd=str(Path(__file__).parent.parent)
)
# Should fail gracefully
assert result.returncode != 0
print("✅ CLI invalid command handling working")
except subprocess.TimeoutExpired:
pytest.fail("❌ CLI invalid command test timed out")
except Exception as e:
pytest.fail(f"❌ CLI invalid command test failed: {e}")
result = run_cli("invalid-command")
assert result.returncode != 0
def test_wallet_balance_requires_target(self):
result = run_cli("wallet", "balance")
assert result.returncode != 0
assert "Error: Wallet name is required" in result.stdout
class TestCLIConfiguration:
"""Test CLI configuration and setup."""
def test_cli_file_exists(self):
"""Test that main CLI file exists."""
cli_file = Path(__file__).parent.parent / "aitbc_cli.py"
assert cli_file.exists(), f"❌ CLI file not found: {cli_file}"
print(f"✅ CLI file exists: {cli_file}")
def test_cli_file_executable(self):
"""Test that CLI file is executable."""
cli_file = Path(__file__).parent.parent / "aitbc_cli.py"
assert cli_file.is_file(), f"❌ CLI file is not a file: {cli_file}"
# Check if file has content
with open(cli_file, 'r') as f:
content = f.read()
assert len(content) > 1000, f"❌ CLI file appears empty or too small"
assert "def main" in content, f"❌ CLI file missing main function"
print(f"✅ CLI file is valid: {len(content)} characters")
"""Test CLI file presence and launcher availability."""
def test_cli_files_exist(self):
assert CLI_FILE.exists()
assert UNIFIED_FILE.exists()
assert CLI_BIN.exists()
if __name__ == "__main__":
# Run basic tests when executed directly
print("🧪 Running basic CLI tests...")
test_class = TestCLIImports()
test_class.test_cli_main_import()
test_class.test_cli_commands_import()
test_class = TestCLIBasicFunctionality()
test_class.test_cli_help_output()
test_class.test_cli_list_command()
test_class = TestCLIErrorHandling()
test_class.test_cli_invalid_command()
test_class = TestCLIConfiguration()
test_class.test_cli_file_exists()
test_class.test_cli_file_executable()
print("✅ All basic CLI tests passed!")
def test_cli_file_contains_main(self):
content = CLI_FILE.read_text()
assert len(content) > 1000
assert "def main" in content

View File

@@ -1,362 +1,187 @@
#!/usr/bin/env python3
"""
Comprehensive CLI tests for AITBC CLI
"""
"""Comprehensive tests for the unified AITBC CLI hierarchy."""
import pytest
import subprocess
import json
import time
import os
import sys
from unittest.mock import patch, MagicMock
from pathlib import Path
PROJECT_ROOT = Path("/opt/aitbc")
CLI_BIN = PROJECT_ROOT / "aitbc-cli"
def run_cli(*args):
return subprocess.run(
[str(CLI_BIN), *args],
capture_output=True,
text=True,
cwd=str(PROJECT_ROOT),
timeout=20,
)
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
class TestSimulateCommand:
"""Test simulate command functionality"""
"""Test the nested simulate command family."""
def test_simulate_help(self):
"""Test simulate command help"""
result = subprocess.run(
[sys.executable, 'cli/aitbc_cli/commands/simulate.py', '--help'],
capture_output=True, text=True, cwd='/opt/aitbc'
)
result = run_cli("simulate", "--help")
assert result.returncode == 0
assert 'Simulate blockchain scenarios' in result.stdout
assert 'blockchain' in result.stdout
assert 'wallets' in result.stdout
assert 'price' in result.stdout
assert 'network' in result.stdout
assert 'ai-jobs' in result.stdout
assert "blockchain" in result.stdout
assert "wallets" in result.stdout
assert "price" in result.stdout
assert "network" in result.stdout
assert "ai-jobs" in result.stdout
def test_simulate_blockchain_basic(self):
"""Test basic blockchain simulation"""
result = subprocess.run(
[sys.executable, 'cli/aitbc_cli/commands/simulate.py', 'blockchain',
'--blocks', '2', '--transactions', '3', '--delay', '0'],
capture_output=True, text=True, cwd='/opt/aitbc'
)
result = run_cli("simulate", "blockchain", "--blocks", "2", "--transactions", "3", "--delay", "0")
assert result.returncode == 0
assert 'Block 1:' in result.stdout
assert 'Block 2:' in result.stdout
assert 'Simulation Summary:' in result.stdout
assert 'Total Blocks: 2' in result.stdout
assert 'Total Transactions: 6' in result.stdout
def test_simulate_wallets_basic(self):
"""Test wallet simulation"""
result = subprocess.run(
[sys.executable, 'cli/aitbc_cli/commands/simulate.py', 'wallets',
'--wallets', '3', '--balance', '100.0', '--transactions', '5'],
capture_output=True, text=True, cwd='/opt/aitbc'
)
assert result.returncode == 0
assert 'Created wallet sim_wallet_1:' in result.stdout
assert 'Created wallet sim_wallet_2:' in result.stdout
assert 'Created wallet sim_wallet_3:' in result.stdout
assert 'Final Wallet Balances:' in result.stdout
def test_simulate_price_basic(self):
"""Test price simulation"""
result = subprocess.run(
[sys.executable, 'cli/aitbc_cli/commands/simulate.py', 'price',
'--price', '100.0', '--volatility', '0.1', '--timesteps', '5', '--delay', '0'],
capture_output=True, text=True, cwd='/opt/aitbc'
)
assert result.returncode == 0
assert 'Step 1:' in result.stdout
assert 'Price Statistics:' in result.stdout
assert 'Starting Price: 100.0000 AIT' in result.stdout
def test_simulate_network_basic(self):
"""Test network simulation"""
result = subprocess.run(
[sys.executable, 'cli/aitbc_cli/commands/simulate.py', 'network',
'--nodes', '2', '--network-delay', '0', '--failure-rate', '0.0'],
capture_output=True, text=True, cwd='/opt/aitbc'
)
assert result.returncode == 0
assert 'Network Topology:' in result.stdout
assert 'node_1' in result.stdout
assert 'node_2' in result.stdout
assert 'Final Network Status:' in result.stdout
def test_simulate_ai_jobs_basic(self):
"""Test AI jobs simulation"""
result = subprocess.run(
[sys.executable, 'cli/aitbc_cli/commands/simulate.py', 'ai-jobs',
'--jobs', '3', '--models', 'text-generation', '--duration-range', '30-60'],
capture_output=True, text=True, cwd='/opt/aitbc'
)
assert result.returncode == 0
assert 'Submitted job job_001:' in result.stdout
assert 'Job Statistics:' in result.stdout
assert 'Total Jobs: 3' in result.stdout
assert "Block 1:" in result.stdout
assert "Total Blocks: 2" in result.stdout
class TestBlockchainCommand:
"""Test blockchain command functionality"""
"""Test nested blockchain commands and legacy chain alias."""
def test_blockchain_help(self):
"""Test blockchain command help"""
result = subprocess.run(
['./aitbc-cli', 'chain', '--help'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("blockchain", "info", "--help")
assert result.returncode == 0
assert '--rpc-url' in result.stdout
def test_blockchain_basic(self):
"""Test basic blockchain command"""
result = subprocess.run(
['./aitbc-cli', 'chain'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
# Command should either succeed or fail gracefully
assert result.returncode in [0, 1, 2]
assert "--rpc-url" in result.stdout
def test_chain_alias_help(self):
result = run_cli("chain", "--help")
assert result.returncode == 0
assert "blockchain info" in result.stdout
assert "--rpc-url" in result.stdout
class TestMarketplaceCommand:
"""Test marketplace command functionality"""
def test_marketplace_help(self):
"""Test marketplace command help"""
result = subprocess.run(
['./aitbc-cli', 'marketplace', '--help'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
"""Test marketplace grouping and legacy rewrite."""
def test_market_help(self):
result = run_cli("market", "--help")
assert result.returncode == 0
assert '--action' in result.stdout
assert 'list' in result.stdout
assert 'create' in result.stdout
assert 'search' in result.stdout
assert 'my-listings' in result.stdout
def test_marketplace_list(self):
"""Test marketplace list action"""
result = subprocess.run(
['./aitbc-cli', 'marketplace', '--action', 'list'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
# Command should either succeed or fail gracefully
assert result.returncode in [0, 1, 2]
assert "list" in result.stdout
assert "create" in result.stdout
assert "search" in result.stdout
assert "my-listings" in result.stdout
def test_marketplace_legacy_alias(self):
result = run_cli("marketplace", "--action", "list")
assert result.returncode == 0
assert "Marketplace list:" in result.stdout
class TestAIOperationsCommand:
"""Test AI operations command functionality"""
def test_ai_ops_help(self):
"""Test ai-ops command help"""
result = subprocess.run(
['./aitbc-cli', 'ai-ops', '--help'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
"""Test the unified ai command family and legacy ai-ops rewrite."""
def test_ai_help(self):
result = run_cli("ai", "--help")
assert result.returncode == 0
assert '--action' in result.stdout
assert 'submit' in result.stdout
assert 'status' in result.stdout
assert 'results' in result.stdout
def test_ai_ops_status(self):
"""Test ai-ops status action"""
result = subprocess.run(
['./aitbc-cli', 'ai-ops', '--action', 'status'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
# Command should either succeed or fail gracefully
assert result.returncode in [0, 1, 2]
assert "submit" in result.stdout
assert "status" in result.stdout
assert "results" in result.stdout
def test_ai_ops_legacy_status(self):
result = run_cli("ai-ops", "--action", "status")
assert result.returncode == 0
assert "AI status:" in result.stdout
class TestResourceCommand:
"""Test resource command functionality"""
"""Test resource subcommands."""
def test_resource_help(self):
"""Test resource command help"""
result = subprocess.run(
['./aitbc-cli', 'resource', '--help'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("resource", "--help")
assert result.returncode == 0
assert '--action' in result.stdout
assert 'status' in result.stdout
assert 'allocate' in result.stdout
assert "status" in result.stdout
assert "allocate" in result.stdout
def test_resource_status(self):
"""Test resource status action"""
result = subprocess.run(
['./aitbc-cli', 'resource', '--action', 'status'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
# Command should either succeed or fail gracefully
assert result.returncode in [0, 1, 2]
result = run_cli("resource", "status")
assert result.returncode == 0
assert "Resource status:" in result.stdout
class TestIntegrationScenarios:
"""Test integration scenarios"""
"""Test representative end-to-end command patterns."""
def test_cli_version(self):
"""Test CLI version command"""
result = subprocess.run(
['./aitbc-cli', '--version'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("--version")
assert result.returncode == 0
assert '0.2.2' in result.stdout
assert "2.1.0" in result.stdout
def test_cli_help_comprehensive(self):
"""Test comprehensive CLI help"""
result = subprocess.run(
['./aitbc-cli', '--help'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("--help")
assert result.returncode == 0
# Check for major command groups
assert 'create' in result.stdout
assert 'send' in result.stdout
assert 'list' in result.stdout
assert 'balance' in result.stdout
assert 'transactions' in result.stdout
assert 'chain' in result.stdout
assert 'network' in result.stdout
assert 'analytics' in result.stdout
assert 'marketplace' in result.stdout
assert 'ai-ops' in result.stdout
assert 'mining' in result.stdout
assert 'agent' in result.stdout
assert 'openclaw' in result.stdout
assert 'workflow' in result.stdout
assert 'resource' in result.stdout
def test_wallet_operations(self):
"""Test wallet operations"""
# Test wallet list
result = subprocess.run(
['./aitbc-cli', 'list'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
assert result.returncode in [0, 1, 2]
# Test wallet balance
result = subprocess.run(
['./aitbc-cli', 'balance'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
assert result.returncode in [0, 1, 2]
def test_blockchain_operations(self):
"""Test blockchain operations"""
# Test chain command
result = subprocess.run(
['./aitbc-cli', 'chain'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
assert result.returncode in [0, 1, 2]
# Test network command
result = subprocess.run(
['./aitbc-cli', 'network'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
assert result.returncode in [0, 1, 2]
def test_ai_operations(self):
"""Test AI operations"""
# Test ai-submit command
result = subprocess.run(
['./aitbc-cli', 'ai-submit', '--wallet', 'test', '--type', 'test',
'--prompt', 'test', '--payment', '10'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
assert result.returncode in [0, 1, 2]
for command in ["wallet", "blockchain", "network", "market", "ai", "mining", "agent", "openclaw", "workflow", "resource", "simulate"]:
assert command in result.stdout
def test_wallet_alias_and_nested_forms(self):
nested = run_cli("wallet", "list")
alias = run_cli("list")
assert nested.returncode == 0
assert alias.returncode == 0
def test_network_default_and_nested_forms(self):
default = run_cli("network")
nested = run_cli("network", "status")
assert default.returncode == 0
assert nested.returncode == 0
assert "Network status:" in default.stdout
assert "Network status:" in nested.stdout
def test_ai_submit_legacy_alias(self):
result = run_cli("ai-submit", "--wallet", "test", "--type", "test", "--prompt", "hello", "--payment", "1")
assert result.returncode == 0
assert "AI submit:" in result.stdout
class TestErrorHandling:
"""Test error handling scenarios"""
"""Test error handling scenarios."""
def test_invalid_command(self):
"""Test invalid command handling"""
result = subprocess.run(
['./aitbc-cli', 'invalid-command'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("invalid-command")
assert result.returncode != 0
def test_missing_required_args(self):
"""Test missing required arguments"""
result = subprocess.run(
['./aitbc-cli', 'send'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("wallet", "send")
assert result.returncode != 0
def test_invalid_option_values(self):
"""Test invalid option values"""
result = subprocess.run(
['./aitbc-cli', '--output', 'invalid'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("--output", "invalid")
assert result.returncode != 0
class TestPerformance:
"""Test performance characteristics"""
"""Test performance characteristics."""
def test_help_response_time(self):
"""Test help command response time"""
start_time = time.time()
result = subprocess.run(
['./aitbc-cli', '--help'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("--help")
end_time = time.time()
assert result.returncode == 0
assert (end_time - start_time) < 5.0 # Should respond within 5 seconds
assert (end_time - start_time) < 5.0
def test_command_startup_time(self):
"""Test command startup time"""
start_time = time.time()
result = subprocess.run(
['./aitbc-cli', 'list'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
result = run_cli("wallet", "list")
end_time = time.time()
assert result.returncode in [0, 1, 2]
assert (end_time - start_time) < 10.0 # Should complete within 10 seconds
assert result.returncode == 0
assert (end_time - start_time) < 10.0
class TestConfiguration:
"""Test configuration scenarios"""
"""Test global flags across the new command tree."""
def test_different_output_formats(self):
"""Test different output formats"""
formats = ['table', 'json', 'yaml']
for fmt in formats:
result = subprocess.run(
['./aitbc-cli', '--output', fmt, 'list'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
assert result.returncode in [0, 1, 2]
for fmt in ["table", "json", "yaml"]:
result = run_cli("--output", fmt, "wallet", "list")
assert result.returncode == 0
def test_verbose_mode(self):
"""Test verbose mode"""
result = subprocess.run(
['./aitbc-cli', '--verbose', 'list'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
assert result.returncode in [0, 1, 2]
result = run_cli("--verbose", "wallet", "list")
assert result.returncode == 0
def test_debug_mode(self):
"""Test debug mode"""
result = subprocess.run(
['./aitbc-cli', '--debug', 'list'],
capture_output=True, text=True, cwd='/opt/aitbc', env=os.environ.copy()
)
assert result.returncode in [0, 1, 2]
if __name__ == '__main__':
pytest.main([__file__, '-v'])
result = run_cli("--debug", "wallet", "list")
assert result.returncode == 0