test_basic.py
1 #!/usr/bin/env python3 2 """ 3 Basic smoke tests for Terminal-Bench Integration 4 5 Tests basic functionality without requiring LLM calls or external dependencies. 6 """ 7 import sys 8 import os 9 10 # Add the package to path 11 sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'praisonai-agents')) 12 13 def test_imports(): 14 """Test that all required modules can be imported.""" 15 try: 16 from praisonaiagents import Agent 17 print("✅ Agent imported successfully") 18 19 from praisonaiagents.tools import execute_command 20 print("✅ execute_command tool imported successfully") 21 22 from praisonaiagents.approval import get_approval_registry, AutoApproveBackend 23 print("✅ Approval system imported successfully") 24 25 return True 26 27 except ImportError as e: 28 print(f"❌ Import failed: {e}") 29 return False 30 31 def test_agent_creation(): 32 """Test that Agent can be created without issues.""" 33 try: 34 from praisonaiagents import Agent 35 36 # Create agent without calling LLM 37 agent = Agent( 38 name='test-agent', 39 instructions='Test agent for terminal tasks' 40 ) 41 42 assert agent.name == 'test-agent' 43 print("✅ Agent creation successful") 44 return True 45 46 except Exception as e: 47 print(f"❌ Agent creation failed: {e}") 48 return False 49 50 def test_approval_system(): 51 """Test approval system configuration.""" 52 try: 53 from praisonaiagents.approval import get_approval_registry, AutoApproveBackend 54 55 registry = get_approval_registry() 56 registry.set_backend(AutoApproveBackend()) 57 58 print("✅ Approval system configuration successful") 59 return True 60 61 except Exception as e: 62 print(f"❌ Approval system test failed: {e}") 63 return False 64 65 def test_external_agent_import(): 66 """Test that our external agent can be imported.""" 67 try: 68 # Mock Harbor imports for testing 69 import sys 70 from unittest.mock import MagicMock 71 72 sys.modules['harbor'] = MagicMock() 73 sys.modules['harbor.agents'] = MagicMock() 74 sys.modules['harbor.agents.base'] = MagicMock() 75 sys.modules['harbor.environments'] = MagicMock() 76 sys.modules['harbor.environments.base'] = MagicMock() 77 sys.modules['harbor.models'] = MagicMock() 78 sys.modules['harbor.models.agent'] = MagicMock() 79 sys.modules['harbor.models.agent.context'] = MagicMock() 80 81 # Now try to import our agent 82 import praisonai_external_agent 83 print("✅ External agent import successful") 84 return True 85 86 except Exception as e: 87 print(f"❌ External agent import failed: {e}") 88 return False 89 90 def test_multi_agent_import(): 91 """Test that multi-agent example can be imported.""" 92 try: 93 import sys 94 from unittest.mock import MagicMock 95 96 # Mock Harbor for testing 97 sys.modules['harbor'] = MagicMock() 98 sys.modules['harbor.agents'] = MagicMock() 99 sys.modules['harbor.agents.base'] = MagicMock() 100 sys.modules['harbor.environments'] = MagicMock() 101 sys.modules['harbor.environments.base'] = MagicMock() 102 sys.modules['harbor.models'] = MagicMock() 103 sys.modules['harbor.models.agent'] = MagicMock() 104 sys.modules['harbor.models.agent.context'] = MagicMock() 105 106 import multi_agent_example 107 print("✅ Multi-agent example import successful") 108 return True 109 110 except Exception as e: 111 print(f"❌ Multi-agent example import failed: {e}") 112 return False 113 114 def test_wrapper_agent_import(): 115 """Test that wrapper agent can be imported.""" 116 try: 117 import sys 118 from unittest.mock import MagicMock 119 120 # Mock Harbor for testing 121 sys.modules['harbor'] = MagicMock() 122 sys.modules['harbor.agents'] = MagicMock() 123 sys.modules['harbor.agents.base'] = MagicMock() 124 sys.modules['harbor.environments'] = MagicMock() 125 sys.modules['harbor.environments.base'] = MagicMock() 126 sys.modules['harbor.models'] = MagicMock() 127 sys.modules['harbor.models.agent'] = MagicMock() 128 sys.modules['harbor.models.agent.context'] = MagicMock() 129 130 import praisonai_wrapper_agent 131 print("✅ Wrapper agent import successful (CLI-based approach)") 132 return True 133 134 except Exception as e: 135 print(f"❌ Wrapper agent import failed: {e}") 136 return False 137 138 if __name__ == "__main__": 139 print("PraisonAI Terminal-Bench Integration - Basic Tests") 140 print("=" * 55) 141 142 tests = [ 143 ("Basic Imports", test_imports), 144 ("Agent Creation", test_agent_creation), 145 ("Approval System", test_approval_system), 146 ("External Agent Import", test_external_agent_import), 147 ("Multi-Agent Import", test_multi_agent_import), 148 ("Wrapper Agent Import", test_wrapper_agent_import), 149 ] 150 151 passed = 0 152 total = len(tests) 153 154 for test_name, test_func in tests: 155 print(f"\n🧪 Testing {test_name}...") 156 try: 157 if test_func(): 158 passed += 1 159 except Exception as e: 160 print(f"❌ Test {test_name} crashed: {e}") 161 162 print("\n" + "=" * 55) 163 print(f"Results: {passed}/{total} tests passed") 164 165 if passed == total: 166 print("🎉 ALL BASIC TESTS PASSED!") 167 print("The Terminal-Bench integration components are properly structured.") 168 else: 169 print("❌ Some tests failed - check output above") 170 sys.exit(1)