#!/usr/bin/env python3 """ Test BZZZ Integration Service Verify integration with existing BZZZ distributed system """ import asyncio import json import sys from datetime import datetime from app.services.bzzz_integration_service import BzzzIntegrationService, AgentRole async def test_bzzz_integration(): """Test BZZZ integration functionality""" print("๐Ÿ”— Testing BZZZ Integration Service") print("=" * 60) # Initialize service service = BzzzIntegrationService() try: # Test initialization print("\n1. Testing Service Initialization...") initialized = await service.initialize() print(f" Initialization result: {'โœ… Success' if initialized else 'โŒ Failed'}") if not initialized: print(" โš ๏ธ Cannot continue without successful initialization") return # Test team status print("\n2. Testing Team Status...") status = await service.get_team_status() print(f" Total team members: {status.get('total_members', 0)}") print(f" Online members: {status.get('online_members', 0)}") print(f" Network health: {status.get('network_health', 0):.2%}") print(f" Active decisions: {status.get('active_decisions', 0)}") # Test team member discovery print("\n3. Testing Team Member Discovery...") print(f" Discovered {len(service.team_members)} team members:") for agent_id, member in service.team_members.items(): print(f" - {agent_id} ({member.role.value}) @ {member.endpoint} [{member.status}]") print(f" Capabilities: {', '.join(member.capabilities)}") # Test decision publishing print("\n4. Testing Decision Publishing...") decision_id = await service.publish_decision( title="Test Decision from WHOOSH", description="This is a test decision published by the WHOOSH integration service to verify P2P connectivity", context={ "test_type": "integration_test", "timestamp": datetime.utcnow().isoformat(), "service": "WHOOSH", "component": "BZZZ Integration" } ) if decision_id: print(f" โœ… Decision published successfully: {decision_id}") # Wait a moment for consensus to develop await asyncio.sleep(2) # Test consensus retrieval print("\n5. Testing Consensus Retrieval...") consensus = await service.get_team_consensus(decision_id) if consensus: print(f" Decision ID: {consensus['decision_id']}") print(f" Total votes: {consensus['total_votes']}") print(f" Approvals: {consensus['approvals']}") print(f" Approval rate: {consensus['approval_rate']:.2%}") print(f" Consensus reached: {'โœ… Yes' if consensus['consensus_reached'] else 'โŒ No'}") else: print(" โš ๏ธ No consensus data available yet") else: print(" โŒ Failed to publish decision") # Test task coordination print("\n6. Testing Task Coordination...") if service.team_members: assignment = await service.coordinate_task_assignment( task_description="Test task coordination from WHOOSH integration service", required_capabilities=["backend", "ai_coordination"], priority="medium" ) if assignment: print(f" โœ… Task assigned to: {assignment['assigned_to']}") print(f" Assignment score: {assignment['assignment_score']:.2f}") print(f" Alternatives: {len(assignment['alternatives'])} other candidates") else: print(" โš ๏ธ No suitable team members found for task") else: print(" โš ๏ธ No team members available for task assignment") # Test recent decisions sync print("\n7. Testing Decision Synchronization...") print(f" Cached decisions: {len(service.active_decisions)}") for decision in list(service.active_decisions.values())[:3]: # Show first 3 print(f" - {decision.title} by {decision.author_role} at {decision.timestamp}") # Network health summary print("\n8. Network Health Summary...") online_count = sum(1 for m in service.team_members.values() if m.status == "online") total_count = len(service.team_members) health_percentage = (online_count / total_count * 100) if total_count > 0 else 0 print(f" ๐ŸŒ Network Status: {online_count}/{total_count} members online ({health_percentage:.1f}%)") # Role distribution role_dist = {} for member in service.team_members.values(): role = member.role.value role_dist[role] = role_dist.get(role, 0) + 1 print(f" ๐Ÿ‘ฅ Role Distribution:") for role, count in role_dist.items(): print(f" - {role.replace('_', ' ').title()}: {count}") print("\nโœ… BZZZ Integration Test Completed Successfully!") except Exception as e: print(f"โŒ Test failed with error: {e}") import traceback traceback.print_exc() finally: # Cleanup await service.cleanup() print("\n๐Ÿงน Service cleanup completed") async def test_specific_endpoints(): """Test connectivity to specific BZZZ endpoints""" print("\n" + "=" * 60) print("๐Ÿ” Testing Specific BZZZ Endpoints") print("=" * 60) endpoints = [ "http://192.168.1.27:8080", # walnut "http://192.168.1.72:8080", # acacia "http://192.168.1.113:8080", # ironwood ] import aiohttp async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10)) as session: for endpoint in endpoints: try: print(f"\n๐Ÿ”— Testing {endpoint}...") # Test basic health async with session.get(f"{endpoint}/api/agent/status") as response: if response.status == 200: data = await response.json() print(f" โœ… Health check: {data.get('status', 'unknown')}") else: print(f" โš ๏ธ Health check failed: HTTP {response.status}") # Test agents list async with session.get(f"{endpoint}/api/agents") as response: if response.status == 200: data = await response.json() agent_count = len(data.get('agents', [])) print(f" โœ… Agents list: {agent_count} agents") else: print(f" โš ๏ธ Agents list failed: HTTP {response.status}") except Exception as e: print(f" โŒ Connection failed: {e}") if __name__ == "__main__": print("๐Ÿš€ Starting BZZZ Integration Tests") print(f"๐Ÿ• Test started at: {datetime.utcnow().isoformat()}") try: # Run main integration test asyncio.run(test_bzzz_integration()) # Run endpoint-specific tests asyncio.run(test_specific_endpoints()) print(f"\n๐Ÿ All tests completed at: {datetime.utcnow().isoformat()}") except KeyboardInterrupt: print("\nโš ๏ธ Tests interrupted by user") sys.exit(1) except Exception as e: print(f"\nโŒ Test suite failed: {e}") sys.exit(1)