|
|
import sys |
|
|
import os |
|
|
import subprocess |
|
|
from unittest.mock import MagicMock |
|
|
|
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
|
|
|
|
|
|
|
subprocess.run = MagicMock(return_value=MagicMock(returncode=0, stdout="Mock Output")) |
|
|
subprocess.Popen = MagicMock() |
|
|
|
|
|
from agent.cua_agent import ComputerUsingAgent |
|
|
from agent.x11_computer import X11Computer |
|
|
|
|
|
|
|
|
def mock_current_state(self): |
|
|
print("Mocking current state...") |
|
|
return MagicMock(screenshot=b"fake_screenshot", url="Mock Window") |
|
|
|
|
|
def mock_hover_at(self, x, y): |
|
|
print(f"Mock hover at {x}, {y}") |
|
|
return MagicMock() |
|
|
|
|
|
def mock_open_web_browser(self): |
|
|
print("Mock opening web browser") |
|
|
return MagicMock() |
|
|
|
|
|
X11Computer.current_state = mock_current_state |
|
|
X11Computer.hover_at = mock_hover_at |
|
|
X11Computer.open_web_browser = mock_open_web_browser |
|
|
|
|
|
def test_agent(): |
|
|
print("Initializing Agent...") |
|
|
agent = ComputerUsingAgent() |
|
|
|
|
|
print("Testing Gemini Integration with Computer Interface...") |
|
|
|
|
|
task = "Open Firefox and hover at 100, 100" |
|
|
print(f"Task: {task}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from agent.cua_agent import GeminiClient |
|
|
GeminiClient.generate_actions = MagicMock(return_value=[ |
|
|
{"action": "launch", "app": "firefox"}, |
|
|
{"action": "mousemove", "x": 100, "y": 100}, |
|
|
{"action": "done", "message": "Test complete"} |
|
|
]) |
|
|
|
|
|
result = agent.execute_task(task) |
|
|
|
|
|
print("\nResult:") |
|
|
print(f"Success: {result['success']}") |
|
|
print(f"Message: {result['message']}") |
|
|
print("Steps Executed:") |
|
|
for step in result['steps_executed']: |
|
|
print(f" - {step}") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
test_agent() |
|
|
|