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

@@ -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