#!/usr/bin/env python3 """ Test script for WHOOSH GITEA integration. Verifies that the GiteaService can connect to and interact with the GITEA instance. """ import sys import os import json from pathlib import Path # Add the backend to Python path sys.path.append(str(Path(__file__).parent / "backend")) from app.services.gitea_service import GiteaService def test_gitea_connection(): """Test basic GITEA connection and API access.""" print("๐Ÿ”ง Testing GITEA Integration") print("=" * 50) try: # Initialize GITEA service gitea = GiteaService() print(f"โœ… GITEA Service initialized") print(f" Base URL: {gitea.gitea_base_url}") print(f" API URL: {gitea.gitea_api_base}") print(f" Token available: {'Yes' if gitea.gitea_token else 'No'}") if not gitea.gitea_token: print("โš ๏ธ Warning: No GITEA token found. Limited functionality available.") return False # Test API connectivity by listing user repositories print("\n๐Ÿ“‹ Testing repository listing...") repositories = gitea.list_repositories() print(f"โœ… Found {len(repositories)} repositories") if repositories: print(" Sample repositories:") for repo in repositories[:3]: # Show first 3 print(f" - {repo['full_name']} ({repo['html_url']})") # Test repository validation for existing repo if repositories: sample_repo = repositories[0] owner, repo_name = sample_repo['full_name'].split('/', 1) print(f"\n๐Ÿ” Testing repository validation for {sample_repo['full_name']}...") validation = gitea.validate_repository_access(owner, repo_name) if validation["accessible"]: print("โœ… Repository validation successful") print(f" BZZZ labels configured: {validation['bzzz_labels_configured']}") print(f" BZZZ task count: {validation['bzzz_task_count']}") print(f" BZZZ ready: {validation['bzzz_ready']}") else: print(f"โŒ Repository validation failed: {validation.get('error')}") return True except Exception as e: print(f"โŒ GITEA integration test failed: {e}") return False def test_project_setup_simulation(): """Simulate a project setup without actually creating a repository.""" print("\n๐Ÿš€ Testing Project Setup Simulation") print("=" * 50) try: gitea = GiteaService() # Test project data project_data = { "name": "test-whoosh-project", "description": "Test project for WHOOSH GITEA integration", "owner": "test-user", "private": False } print(f"๐Ÿ“ Project data prepared:") print(f" Name: {project_data['name']}") print(f" Description: {project_data['description']}") print(f" Owner: {project_data['owner']}") print(f" Private: {project_data['private']}") # Test BZZZ label configuration (without creating repo) print("\n๐Ÿท๏ธ Testing BZZZ label configuration...") expected_labels = [ gitea.bzzz_labels["task"], gitea.bzzz_labels["in_progress"], gitea.bzzz_labels["completed"], gitea.bzzz_labels["frontend"], gitea.bzzz_labels["backend"], gitea.bzzz_labels["security"] ] print(f"โœ… BZZZ labels configured:") for label in expected_labels: print(f" - {label}") # Test task type determination print("\n๐Ÿ” Testing task type determination...") test_issues = [ {"title": "Fix login bug", "body": "User authentication is broken", "labels": [{"name": "bug"}]}, {"title": "Add dark mode", "body": "Implement dark theme for UI", "labels": [{"name": "frontend"}, {"name": "enhancement"}]}, {"title": "Security audit", "body": "Review authentication system", "labels": [{"name": "security"}]}, {"title": "API optimization", "body": "Improve backend performance", "labels": [{"name": "backend"}]} ] for issue in test_issues: task_type = gitea._determine_task_type(issue) print(f" Issue: '{issue['title']}' โ†’ Type: {task_type}") print("\nโœ… Project setup simulation completed successfully") return True except Exception as e: print(f"โŒ Project setup simulation failed: {e}") return False def test_bzzz_integration(): """Test BZZZ task coordination features.""" print("\n๐Ÿ Testing BZZZ Integration Features") print("=" * 50) try: gitea = GiteaService() # Test BZZZ task creation data task_data = { "title": "๐Ÿš€ Test BZZZ Task Creation", "description": """# Test Task for BZZZ Coordination This is a test task created by the WHOOSH GITEA integration test. ## Requirements - [ ] Verify task appears in BZZZ agent discovery - [ ] Test task claiming mechanism - [ ] Validate task completion workflow ## Acceptance Criteria - Task is properly labeled with 'bzzz-task' - Task type is correctly determined - Task can be discovered by BZZZ agents --- *Created by WHOOSH GITEA Integration Test* """, "task_type": "testing", "priority": "medium" } print("๐Ÿ“‹ Test BZZZ task data prepared:") print(f" Title: {task_data['title']}") print(f" Type: {task_data['task_type']}") print(f" Priority: {task_data['priority']}") # Check if we have any repositories to test with repositories = gitea.list_repositories() if repositories: sample_repo = repositories[0] owner, repo_name = sample_repo['full_name'].split('/', 1) print(f"\n๐Ÿ” Checking BZZZ tasks in {sample_repo['full_name']}...") bzzz_tasks = gitea.get_bzzz_tasks(owner, repo_name) print(f"โœ… Found {len(bzzz_tasks)} BZZZ tasks") if bzzz_tasks: print(" Sample tasks:") for task in bzzz_tasks[:3]: # Show first 3 print(f" - #{task['number']}: {task['title']} (Type: {task['task_type']})") else: print("โš ๏ธ No repositories available for BZZZ task testing") print("\nโœ… BZZZ integration features verified") return True except Exception as e: print(f"โŒ BZZZ integration test failed: {e}") return False def print_gitea_configuration_info(): """Print GITEA configuration information and setup instructions.""" print("\nโš™๏ธ GITEA Configuration Information") print("=" * 50) print("๐Ÿ”ง GITEA Connection Details:") print(f" Server URL: http://ironwood:3000") print(f" API Endpoint: http://ironwood:3000/api/v1") print(f" External Access: gitea.deepblack.cloud (via Traefik)") print("\n๐Ÿ”‘ Token Configuration:") print(" To enable full functionality, create a GITEA personal access token:") print(" 1. Visit http://ironwood:3000/user/settings/applications") print(" 2. Generate a new token with 'repository' permissions") print(" 3. Save the token to one of these locations:") print(" - /run/secrets/gitea_token (Docker secret - preferred)") print(" - /home/tony/AI/secrets/passwords_and_tokens/gitea-token") print(" - Environment variable: GITEA_TOKEN") print("\n๐Ÿท๏ธ BZZZ Label Configuration:") print(" The following labels will be automatically created:") gitea = GiteaService() for label_key, label_name in gitea.bzzz_labels.items(): print(f" - {label_name}") print("\n๐Ÿ”— Integration Points:") print(" - Repository creation and management") print(" - Issue-based task coordination") print(" - BZZZ agent task discovery") print(" - Project member collaboration") print(" - Automated label and workflow setup") def main(): """Run all GITEA integration tests.""" print("๐Ÿงช WHOOSH GITEA Integration Test Suite") print("=" * 60) print() # Run tests tests = [ ("GITEA Connection", test_gitea_connection), ("Project Setup Simulation", test_project_setup_simulation), ("BZZZ Integration", test_bzzz_integration) ] results = [] for test_name, test_func in tests: print(f"\n๐Ÿงช Running: {test_name}") try: result = test_func() results.append((test_name, result)) except Exception as e: print(f"โŒ Test failed with exception: {e}") results.append((test_name, False)) print() # Print configuration info print_gitea_configuration_info() # Summary print("\n๐Ÿ“Š Test Results Summary") print("=" * 30) passed = 0 for test_name, result in results: status = "โœ… PASS" if result else "โŒ FAIL" print(f"{status} {test_name}") if result: passed += 1 print(f"\nTests passed: {passed}/{len(results)}") if passed == len(results): print("\n๐ŸŽ‰ All tests passed! GITEA integration is ready.") print("\n๐Ÿš€ Next steps:") print(" 1. Ensure GITEA token is configured") print(" 2. Test project creation through WHOOSH UI") print(" 3. Verify BZZZ agents can discover tasks") return True else: print("\nโš ๏ธ Some tests failed. Please check configuration.") return False if __name__ == "__main__": success = main() sys.exit(0 if success else 1)