From 30f4d101d75b84c50cfd33d99153e9fd384535be Mon Sep 17 00:00:00 2001 From: rUv Date: Wed, 6 Aug 2025 02:39:48 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20Checkpoint:=20Edit=20/workspaces?= =?UTF-8?q?/claude-code-flow/benchmark/validate=5Fcli.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmark/.claude/checkpoints/1754447977.json | 1 + benchmark/.claude/checkpoints/1754447978.json | 1 + benchmark/validate_cli.py | 222 ++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 benchmark/.claude/checkpoints/1754447977.json create mode 100644 benchmark/.claude/checkpoints/1754447978.json create mode 100644 benchmark/validate_cli.py diff --git a/benchmark/.claude/checkpoints/1754447977.json b/benchmark/.claude/checkpoints/1754447977.json new file mode 100644 index 0000000000..43b857e249 --- /dev/null +++ b/benchmark/.claude/checkpoints/1754447977.json @@ -0,0 +1 @@ +{"branch": "checkpoint/pre-edit-20250806-023937", "file": "/workspaces/claude-code-flow/benchmark/src/swarm_benchmark/optimization/engine.py", "timestamp": "2025-08-06T02:39:37Z", "type": "pre-edit", "original_branch": "alpha-88"} diff --git a/benchmark/.claude/checkpoints/1754447978.json b/benchmark/.claude/checkpoints/1754447978.json new file mode 100644 index 0000000000..7896316032 --- /dev/null +++ b/benchmark/.claude/checkpoints/1754447978.json @@ -0,0 +1 @@ +{"tag": "checkpoint-20250806-023938", "file": "/workspaces/claude-code-flow/benchmark/src/swarm_benchmark/optimization/engine.py", "timestamp": "2025-08-06T02:39:38Z", "type": "post-edit", "branch": "alpha-88", "diff_summary": " .claude-flow/metrics/system-metrics.json | 120 +++++++++++++++++++++ benchmark/.claude-flow/metrics/performance.json | 2 +- benchmark/.claude-flow/metrics/task-metrics.json | 6 +- benchmark/.claude/checkpoints/1754447973.json | 1 + benchmark/.claude/checkpoints/1754447975.json | 1 + .../optimized_benchmark_engine.cpython-312.pyc | Bin 15770 -> 15428 bytes .../src/swarm_benchmark/optimization/engine.py | 11 +- claude-flow-wiki | 0 8 files changed, 135 insertions(+), 6 deletions(-) "} diff --git a/benchmark/validate_cli.py b/benchmark/validate_cli.py new file mode 100644 index 0000000000..33dbbb82b6 --- /dev/null +++ b/benchmark/validate_cli.py @@ -0,0 +1,222 @@ +#!/usr/bin/env python3 +"""Validate CLI is working correctly.""" + +import subprocess +import sys +import json +import time +from pathlib import Path + + +def run_command(cmd, timeout=10): + """Run a command and return result.""" + try: + print(f" Running: {' '.join(cmd)}") + result = subprocess.run( + cmd, + capture_output=True, + text=True, + timeout=timeout, + cwd=Path(__file__).parent + ) + return result + except subprocess.TimeoutExpired: + print(f" ā° Command timed out after {timeout}s") + return None + except FileNotFoundError: + print(f" āŒ Command not found: {cmd[0]}") + return None + + +def validate_cli(): + """Validate CLI is working correctly.""" + print("šŸ” Validating CLI functionality...") + print("=" * 50) + + failed_tests = [] + + # Test cases: [command, expected_in_output, should_succeed] + test_cases = [ + # Basic help and version + (["swarm-benchmark", "--version"], "", True), + (["swarm-benchmark", "--help"], "Claude Flow Advanced Swarm Benchmarking Tool", True), + + # Global options in help + (["swarm-benchmark", "--help"], "--real / --mock", True), + (["swarm-benchmark", "--help"], "--claude-flow-path", True), + (["swarm-benchmark", "--help"], "--timeout", True), + (["swarm-benchmark", "--help"], "--stream / --no-stream", True), + + # Command help tests + (["swarm-benchmark", "run", "--help"], "Run a swarm benchmark", True), + (["swarm-benchmark", "list", "--help"], "List recent benchmark runs", True), + (["swarm-benchmark", "show", "--help"], "Show details for a specific benchmark", True), + (["swarm-benchmark", "clean", "--help"], "Clean up benchmark results", True), + (["swarm-benchmark", "serve", "--help"], "Start the benchmark web interface", True), + + # Real command group + (["swarm-benchmark", "real", "--help"], "Real claude-flow command execution", True), + (["swarm-benchmark", "real", "swarm", "--help"], "Run real claude-flow swarm benchmarks", True), + + # Strategy and mode options + (["swarm-benchmark", "run", "--help"], "--strategy", True), + (["swarm-benchmark", "run", "--help"], "--mode", True), + (["swarm-benchmark", "real", "swarm", "--help"], "--strategy", True), + (["swarm-benchmark", "real", "swarm", "--help"], "--mode", True), + + # Invalid commands should fail gracefully + (["swarm-benchmark", "nonexistent"], "No such command", False), + ] + + print(f"šŸ“‹ Running {len(test_cases)} validation tests...\n") + + for i, (cmd, expected_output, should_succeed) in enumerate(test_cases, 1): + print(f"Test {i:2}/{len(test_cases)}: {' '.join(cmd[:3])}{'...' if len(cmd) > 3 else ''}") + + result = run_command(cmd) + + if result is None: + failed_tests.append(f"Test {i}: Command failed to run") + continue + + # Check if command succeeded as expected + if should_succeed and result.returncode != 0: + failed_tests.append(f"Test {i}: Expected success but got exit code {result.returncode}") + print(f" āŒ Expected success but failed with code {result.returncode}") + if result.stderr: + print(f" Error: {result.stderr.strip()}") + continue + + if not should_succeed and result.returncode == 0: + failed_tests.append(f"Test {i}: Expected failure but command succeeded") + print(f" āŒ Expected failure but command succeeded") + continue + + # Check expected output if provided + if expected_output: + output = result.stdout + result.stderr + if expected_output not in output: + failed_tests.append(f"Test {i}: Expected '{expected_output}' not found in output") + print(f" āŒ Expected '{expected_output}' not found") + continue + + print(f" āœ… Passed") + + print("\n" + "=" * 50) + + if failed_tests: + print(f"āŒ {len(failed_tests)} test(s) failed:") + for failure in failed_tests: + print(f" • {failure}") + return False + else: + print(f"šŸŽ‰ All {len(test_cases)} tests passed!") + return True + + +def validate_installation(): + """Validate that the CLI tool is properly installed.""" + print("šŸ“¦ Validating installation...") + print("=" * 50) + + # Check if swarm-benchmark command is available + result = run_command(["which", "swarm-benchmark"]) + if result and result.returncode == 0: + cli_path = result.stdout.strip() + print(f"āœ… CLI found at: {cli_path}") + else: + print("āš ļø CLI not found in PATH, trying direct execution...") + + # Try running from local setup + project_root = Path(__file__).parent + setup_py = project_root / "setup.py" + + if setup_py.exists(): + print("šŸ“¦ Installing in development mode...") + install_result = run_command([ + sys.executable, "-m", "pip", "install", "-e", "." + ], timeout=60) + + if install_result and install_result.returncode == 0: + print("āœ… Development installation successful") + else: + print("āŒ Development installation failed") + return False + else: + print("āŒ No setup.py found for installation") + return False + + return True + + +def run_integration_test(): + """Run a simple integration test.""" + print("\nšŸ”§ Running integration test...") + print("=" * 50) + + # Try to run a simple benchmark command (should not crash) + test_cmd = [ + "swarm-benchmark", + "--verbose", + "--mock", + "list", + "--format", "json", + "--limit", "1" + ] + + result = run_command(test_cmd, timeout=30) + + if result is None: + print("āŒ Integration test failed - command timeout") + return False + + if result.returncode != 0: + print(f"āŒ Integration test failed with exit code {result.returncode}") + if result.stderr: + print(f"Error output: {result.stderr}") + return False + + print("āœ… Integration test passed") + return True + + +def main(): + """Main validation function.""" + print("šŸš€ Claude Flow Swarm Benchmark CLI Validation") + print("=" * 50) + print(f"Python: {sys.version}") + print(f"Working directory: {Path.cwd()}") + print() + + success = True + + # Step 1: Validate installation + if not validate_installation(): + print("\nāŒ Installation validation failed") + success = False + + # Step 2: Validate CLI commands + if not validate_cli(): + print("\nāŒ CLI validation failed") + success = False + + # Step 3: Run integration test + if not run_integration_test(): + print("\nāŒ Integration test failed") + success = False + + print("\n" + "=" * 50) + + if success: + print("šŸŽ‰ ALL VALIDATIONS PASSED!") + print("The CLI is working correctly and ready for use.") + return 0 + else: + print("āŒ SOME VALIDATIONS FAILED!") + print("Please check the errors above and fix the issues.") + return 1 + + +if __name__ == "__main__": + exit_code = main() + sys.exit(exit_code) \ No newline at end of file