An AI Agent that interacts with Windows OS at GUI level.
Python
Fix all unit tests to match updated API and behaviour
jeomon004565846681
diff --git a/tests/unit/agent/agent_prompt/test_agent_prompt_service.py b/tests/unit/agent/agent_prompt/test_agent_prompt_service.pyindex 19374ec..e67a49e 100644--- a/tests/unit/agent/agent_prompt/test_agent_prompt_service.py+++ b/tests/unit/agent/agent_prompt/test_agent_prompt_service.py@@ -11,7 +11,8 @@ class TestContext:@pytest.fixturedef context(self):- return Context()+ from unittest.mock import MagicMock+ return Context(llm=MagicMock())@pytest.fixturedef mock_desktop(self):@@ -78,10 +79,10 @@ class TestContext:mock_desktop.use_accessibility = Truemock_desktop.use_vision = Falsemock_load_template.return_value = (- "Human: {steps} {max_steps} {active_window} {windows} {cursor_location} "+ "Human: {steps} {max_steps} {loop_warning} {active_window} {windows} {cursor_location} ""{interactive_elements} {scrollable_elements} {active_desktop} {desktops} {query}")- msg = context.human(+ msg = context.state(query="test query",step=2,max_steps=10,diff --git a/tests/unit/agent/agent_registry/test_agent_registry_service.py b/tests/unit/agent/agent_registry/test_agent_registry_service.pyindex b60b4a1..64160a1 100644--- a/tests/unit/agent/agent_registry/test_agent_registry_service.py+++ b/tests/unit/agent/agent_registry/test_agent_registry_service.py@@ -15,48 +15,43 @@ class TestRegistry:mock = MagicMock(spec=Tool)mock.name = "TestTool"mock.json_schema = {"name": "TestTool", "parameters": {}}- mock.validate.return_value = [] # No errors+ mock.validate_params.return_value = []mock.invoke.return_value = "Tool execution result"return mockdef test_init(self, mock_tool):- """Test Registry initialization."""registry = Registry(tools=[mock_tool])assert registry.tools == [mock_tool]assert "TestTool" in registry.tools_registryassert registry.tools_registry["TestTool"] == mock_tooldef test_get_tools_schema(self, mock_tool):- """Test get_tools_schema method."""registry = Registry(tools=[mock_tool])schema = registry.get_tools_schema()assert schema == [{"name": "TestTool", "parameters": {}}]def test_execute_success(self, mock_tool):- """Test successful tool execution."""registry = Registry(tools=[mock_tool])mock_desktop = MagicMock()-- result = registry.execute("TestTool", desktop=mock_desktop, param1="val1")-++ result = registry.execute("TestTool", tool_params={"param1": "val1"}, desktop=mock_desktop)+assert result.is_success is Trueassert result.content == "Tool execution result"mock_tool.invoke.assert_called_once_with(desktop=mock_desktop, param1="val1")def test_execute_validation_failure(self, mock_tool):- """Test tool execution with validation failure."""- mock_tool.validate.return_value = ["Invalid param"]+ mock_tool.validate_params.return_value = ["Invalid param"]registry = Registry(tools=[mock_tool])-- result = registry.execute("TestTool", param1="val1")-++ result = registry.execute("TestTool", tool_params={"param1": "val1"})+assert result.is_success is Falseassert "validation failed" in result.errormock_tool.invoke.assert_not_called()def test_execute_not_found(self):- """Test execution of non-existent tool."""registry = Registry(tools=[])- result = registry.execute("NonExistent")+ result = registry.execute("NonExistent", tool_params={})assert result.is_success is False- assert "not found" in result.error\ No newline at end of file+ assert "not found" in result.errordiff --git a/tests/unit/agent/agent_tools/test_agent_tools_service.py b/tests/unit/agent/agent_tools/test_agent_tools_service.pyindex b01254d..2c51760 100644--- a/tests/unit/agent/agent_tools/test_agent_tools_service.py+++ b/tests/unit/agent/agent_tools/test_agent_tools_service.py@@ -113,20 +113,23 @@ class TestAgentToolsService:multi_edit_tool.invoke(**{"elements": elements, "desktop": mock_desktop})mock_desktop.multi_edit.assert_called_once_with(elements)- @patch("windows_use.agent.tools.service.sleep")+ @patch("asyncio.sleep")def test_wait_tool(self, mock_sleep, mock_desktop):- """Test wait_tool calls sleep."""+ """Test wait_tool calls asyncio.sleep."""+ from unittest.mock import AsyncMock+ mock_sleep.return_value = AsyncMock()()wait_tool.invoke(**{"duration": 5, "desktop": mock_desktop})mock_sleep.assert_called_once_with(5)def test_scrape_tool(self, mock_desktop):"""Test scrape_tool fetches text from visual tree."""- # Setup mock tree statemock_node = MagicMock()mock_node.text = "Visual Content"mock_desktop.desktop_state.tree_state.dom_informative_nodes = [mock_node]- mock_desktop.desktop_state.tree_state.dom_node = MagicMock(vertical_scroll_percent=0)-+ mock_dom_node = MagicMock()+ mock_dom_node.metadata = {'vertical_scroll_percent': 0}+ mock_desktop.desktop_state.tree_state.dom_node = mock_dom_node+result = scrape_tool.invoke(**{"url": "http://test", "desktop": mock_desktop})assert "Visual Content" in resultassert "Reached top" in resultdiff --git a/tests/unit/agent/agent_tools/test_agent_tools_views.py b/tests/unit/agent/agent_tools/test_agent_tools_views.pyindex 8ea84c5..56430bb 100644--- a/tests/unit/agent/agent_tools/test_agent_tools_views.py+++ b/tests/unit/agent/agent_tools/test_agent_tools_views.py@@ -22,61 +22,50 @@ from windows_use.agent.tools.service import (Desktop,)+THOUGHT = "test thought"+class TestAgentToolsViews:"""Tests for the Pydantic models in windows_use.agent.tools.views."""def test_shared_base_model_extra_fields(self):- """- Test SharedBaseModel allows extra fields.- """- model = SharedBaseModel(field1="value1", extra_field="extra")+ model = SharedBaseModel(thought=THOUGHT, field1="value1", extra_field="extra")assert getattr(model, "field1") == "value1"assert getattr(model, "extra_field") == "extra"def test_app_model(self):- """- Test App model validation.- """- app = App(mode="launch", name="notepad")+ app = App(thought=THOUGHT, mode="launch", name="notepad")assert app.mode == "launch"assert app.name == "notepad"-- # Test resize- app_resize = App(mode="resize", loc=[10, 20], size=[100, 200])++ app_resize = App(thought=THOUGHT, mode="resize", loc=[10, 20], size=[100, 200])assert app_resize.mode == "resize"assert app_resize.loc == [10, 20]assert app_resize.size == [100, 200]with pytest.raises(ValidationError):- App(mode="invalid")+ App(thought=THOUGHT, mode="invalid")def test_done_model(self):- """- Test Done model validation.- """- done = Done(answer="Task completed.")+ done = Done(thought=THOUGHT, answer="Task completed.")assert done.answer == "Task completed."with pytest.raises(ValidationError):- Done(answer=123) # type: ignore+ Done(thought=THOUGHT, answer=123) # type: ignorewith pytest.raises(ValidationError):Done() # type: ignoredef test_memory_model(self):- """- Test Memory model validation.- """- mem = Memory(mode="write", path="test.md", content="hello")+ mem = Memory(thought=THOUGHT, mode="write", path="test.md", content="hello")assert mem.mode == "write"assert mem.path == "test.md"assert mem.content == "hello"- mem_update = Memory(mode="update", path="test.md", operation="replace", old_str="a", new_str="b")+ mem_update = Memory(thought=THOUGHT, mode="update", path="test.md", operation="replace", old_str="a", new_str="b")assert mem_update.operation == "replace"-+with pytest.raises(ValidationError):- Memory(mode="invalid")+ Memory(thought=THOUGHT, mode="invalid")@pytest.mark.parametrize("loc, button, clicks, should_pass",@@ -84,63 +73,51 @@ class TestAgentToolsViews:([10, 20], "left", 1, True),([0, 0], "right", 2, True),([100, 100], "middle", 0, True),- ([10, 20, 30], "left", 1, True), # list[int] doesn't enforce size in Pydantic unless specified- ([10, 20], "top", 1, False), # Invalid button- ([10, 20], "left", 3, False), # Invalid clicks (Literal[0,1,2])- (None, "left", 1, False), # Missing loc+ ([10, 20, 30], "left", 1, True),+ ([10, 20], "top", 1, False),+ ([10, 20], "left", 3, False),+ (None, "left", 1, False),],)def test_click_model(self, loc, button, clicks, should_pass):- """- Test Click model validation for loc, button, and clicks.- """if should_pass:- click = Click(loc=loc, button=button, clicks=clicks)+ click = Click(thought=THOUGHT, loc=loc, button=button, clicks=clicks)assert click.loc == locassert click.button == buttonassert click.clicks == clickselse:with pytest.raises(ValidationError):- Click(loc=loc, button=button, clicks=clicks)+ Click(thought=THOUGHT, loc=loc, button=button, clicks=clicks)def test_shell_model(self):- """- Test Shell model validation.- """- shell = Shell(command="Get-Process")+ shell = Shell(thought=THOUGHT, command="Get-Process")assert shell.command == "Get-Process"with pytest.raises(ValidationError):- Shell(command=123) # type: ignore+ Shell(thought=THOUGHT, command=123) # type: ignorewith pytest.raises(ValidationError):Shell() # type: ignore@pytest.mark.parametrize("loc, text, clear, caret_position, should_pass",[- ([10, 20], "hello", "false", "idle", True),- ([0, 0], "world", "true", "start", True),- ([50, 50], "test", "false", "end", True),- ([10, 20], "hello", "invalid", "idle", False), # Invalid clear- ([10, 20], "hello", "false", "invalid", False), # Invalid caret_position- (None, "hello", "false", "idle", False), # Missing loc- ([10, 20], None, "false", "idle", False), # Missing text+ ([10, 20], "hello", False, "idle", True),+ ([0, 0], "world", True, "start", True),+ ([50, 50], "test", False, "end", True),+ ([10, 20], "hello", False, "invalid", False),+ (None, "hello", False, "idle", False),+ ([10, 20], None, False, "idle", False),],)def test_type_model(self, loc, text, clear, caret_position, should_pass):- """- Test Type model validation for loc, text, clear, and caret_position.- """if should_pass:- type_obj = Type(- loc=loc, text=text, clear=clear, caret_position=caret_position- )+ type_obj = Type(thought=THOUGHT, loc=loc, text=text, clear=clear, caret_position=caret_position)assert type_obj.loc == locassert type_obj.text == textassert type_obj.clear == clearassert type_obj.caret_position == caret_positionelse:with pytest.raises(ValidationError):- Type(loc=loc, text=text, clear=clear, caret_position=caret_position)+ Type(thought=THOUGHT, loc=loc, text=text, clear=clear, caret_position=caret_position)@pytest.mark.parametrize("loc, type_val, direction, wheel_times, should_pass",@@ -148,47 +125,37 @@ class TestAgentToolsViews:(None, "vertical", "down", 1, True),([10, 20], "horizontal", "left", 5, True),(None, "vertical", "up", 10, True),- (None, "invalid", "down", 1, False), # Invalid type- (None, "vertical", "invalid", 1, False), # Invalid direction+ (None, "invalid", "down", 1, False),+ (None, "vertical", "invalid", 1, False),],)def test_scroll_model(self, loc, type_val, direction, wheel_times, should_pass):- """- Test Scroll model validation for loc, type, direction, and wheel_times.- """if should_pass:- scroll = Scroll(- loc=loc, type=type_val, direction=direction, wheel_times=wheel_times- )+ scroll = Scroll(thought=THOUGHT, loc=loc, type=type_val, direction=direction, wheel_times=wheel_times)assert scroll.loc == locassert scroll.type == type_valassert scroll.direction == directionassert scroll.wheel_times == wheel_timeselse:with pytest.raises(ValidationError):- Scroll(- loc=loc, type=type_val, direction=direction, wheel_times=wheel_times- )+ Scroll(thought=THOUGHT, loc=loc, type=type_val, direction=direction, wheel_times=wheel_times)@pytest.mark.parametrize("loc, drag, should_pass",[([100, 100], True, True),([0, 0], False, True),- (None, False, False), # Missing loc+ (None, False, False),],)def test_move_model(self, loc, drag, should_pass):- """- Test Move model validation for loc and drag.- """if should_pass:- move = Move(loc=loc, drag=drag)+ move = Move(thought=THOUGHT, loc=loc, drag=drag)assert move.loc == locassert move.drag == dragelse:with pytest.raises(ValidationError):- Move(loc=loc, drag=drag)+ Move(thought=THOUGHT, loc=loc, drag=drag)@pytest.mark.parametrize("shortcut, should_pass",@@ -196,62 +163,50 @@ class TestAgentToolsViews:("ctrl+c", True),("win", True),("enter", True),- (123, False), # Not a string- (None, False), # Missing shortcut+ (123, False),+ (None, False),],)def test_shortcut_model(self, shortcut, should_pass):- """- Test Shortcut model validation for shortcut string.- """if should_pass:- s = Shortcut(shortcut=shortcut)+ s = Shortcut(thought=THOUGHT, shortcut=shortcut)assert s.shortcut == shortcutelse:with pytest.raises(ValidationError):- Shortcut(shortcut=shortcut)+ Shortcut(thought=THOUGHT, shortcut=shortcut)@pytest.mark.parametrize("duration, should_pass",[(5, True),(0, True),- ("5", True), # Pydantic coerces string to int- (None, False), # Missing duration+ ("5", True),+ (None, False),],)def test_wait_model(self, duration, should_pass):- """- Test Wait model validation for duration.- """if should_pass:- wait = Wait(duration=duration)+ wait = Wait(thought=THOUGHT, duration=duration)assert wait.duration == int(duration)else:with pytest.raises(ValidationError):- Wait(duration=duration)+ Wait(thought=THOUGHT, duration=duration)def test_scrape_model(self):- """- Test Scrape model validation.- """- scrape = Scrape(url="https://example.com")+ scrape = Scrape(thought=THOUGHT, url="https://example.com")assert scrape.url == "https://example.com"with pytest.raises(ValidationError):- Scrape(url=123) # type: ignore+ Scrape(thought=THOUGHT, url=123) # type: ignorewith pytest.raises(ValidationError):Scrape() # type: ignoredef test_desktop_model(self):- """- Test Desktop model validation.- """- dt = Desktop(action="switch", desktop_name="Desktop 1")+ dt = Desktop(thought=THOUGHT, action="switch", desktop_name="Desktop 1")assert dt.action == "switch"assert dt.desktop_name == "Desktop 1"-- dt_create = Desktop(action="create")++ dt_create = Desktop(thought=THOUGHT, action="create")assert dt_create.action == "create"-+with pytest.raises(ValidationError):- Desktop(action="invalid")+ Desktop(thought=THOUGHT, action="invalid")diff --git a/tests/unit/agent/test_agent_service.py b/tests/unit/agent/test_agent_service.pyindex 581d319..001e232 100644--- a/tests/unit/agent/test_agent_service.py+++ b/tests/unit/agent/test_agent_service.py@@ -6,6 +6,8 @@ import jsonfrom windows_use.agent.service import Agentfrom windows_use.agent.views import AgentResultfrom windows_use.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage+from windows_use.providers.events import LLMEvent, LLMEventType, ToolCall+from windows_use.providers.views import TokenUsageclass TestAgent:"""@@ -14,42 +16,36 @@ class TestAgent:@pytest.fixturedef mock_llm(self):- """Mock LLM."""mock = MagicMock()mock.model_name = "test-model"mock.provider = "test-provider"+ mock.get_metadata.return_value.context_window = 100000return mock@pytest.fixturedef mock_desktop(self):- """Mock Desktop."""with patch("windows_use.agent.service.Desktop") as mock_class:mock_instance = mock_class.return_valuemock_instance.get_state.return_value = MagicMock()mock_instance.get_default_language.return_value = "English"- # mock_instance.auto_minimize is a context manager+ mock_instance.use_vision = False+ mock_instance.use_accessibility = True+ mock_instance.desktop_state.active_window_to_string.return_value = "Active: Notepad"+ mock_instance.desktop_state.windows_to_string.return_value = "Windows: [Notepad]"+ mock_instance.desktop_state.tree_state.interactive_elements_to_string.return_value = "elements"+ mock_instance.desktop_state.tree_state.scrollable_elements_to_string.return_value = "scrollable"+ mock_instance.desktop_state.active_desktop_to_string.return_value = "Desktop 1"+ mock_instance.desktop_state.desktops_to_string.return_value = "Desktops: [1]"+ mock_instance.desktop_state.active_window.handle = 12345mock_instance.auto_minimize.return_value.__enter__.return_value = Noneyield mock_instance- @pytest.fixture- def mock_prompt(self):- """Mock Prompt with string return values for Pydantic."""- with patch("windows_use.agent.service.Prompt") as mock_p:- mock_p.system_prompt.return_value = "System prompt"- mock_p.observation_prompt.return_value = "Observation prompt"- mock_p.previous_observation_prompt.return_value = "Prev observation prompt"- mock_p.action_prompt.return_value = "Action prompt"- mock_p.answer_prompt.return_value = "Answer prompt"- yield mock_p-@pytest.fixturedef mock_console(self):- """Mock Console."""with patch("windows_use.agent.service.Console") as mock_class:yield mock_class.return_valuedef test_init(self, mock_llm, mock_desktop, mock_console):- """Test Agent initialization."""agent = Agent(llm=mock_llm, instructions=["Test instruction"])assert agent.instructions == ["Test instruction"]assert agent.state.max_steps == 25@@ -57,26 +53,23 @@ class TestAgent:@patch("windows_use.agent.service.Registry")@patch("windows_use.agent.service.WatchDog")- def test_invoke_done(self, mock_watchdog, mock_registry_class, mock_llm, mock_desktop, mock_prompt, mock_console):- """Test invoke method when task is completed via done_tool."""+ def test_invoke_done(self, mock_watchdog, mock_registry_class, mock_llm, mock_desktop, mock_console):mock_registry = mock_registry_class.return_value-- # When execute is called, it returns a ToolResult-like object+mock_response = MagicMock()mock_response.content = "Job's done"mock_response.is_success = Truemock_registry.execute.return_value = mock_response-- # Mock LLM response - agent expects ToolMessage for tool calls- mock_llm.invoke.return_value = ToolMessage(- id="call_1",- name="done_tool",- params={"answer": "Job's done", "thought": "I have finished the task."},++ mock_llm.invoke.return_value = LLMEvent(+ type=LLMEventType.TOOL_CALL,+ tool_call=ToolCall(id="call_1", name="done_tool", params={"answer": "Job's done", "thought": "I have finished the task."}),+ usage=TokenUsage(),)-+agent = Agent(llm=mock_llm)result = agent.invoke("test query")-+assert isinstance(result, AgentResult)assert result.is_done is Trueassert result.content == "Job's done"@@ -84,53 +77,22 @@ class TestAgent:@patch("windows_use.agent.service.Registry")@patch("windows_use.agent.service.WatchDog")- def test_invoke_max_steps(self, mock_watchdog, mock_registry_class, mock_llm, mock_desktop, mock_prompt, mock_console):- """Test invoke method stops after max_steps."""+ def test_invoke_max_steps(self, mock_watchdog, mock_registry_class, mock_llm, mock_desktop, mock_console):mock_registry = mock_registry_class.return_valuemock_response = MagicMock()mock_response.content = "Step result"mock_response.is_success = Truemock_registry.execute.return_value = mock_response-- # Mock LLM response (non-done action)- mock_llm.invoke.return_value = ToolMessage(- id="call_1",- name="click_tool",- params={"loc": [10, 10], "thought": "Keep working"},++ mock_llm.invoke.return_value = LLMEvent(+ type=LLMEventType.TOOL_CALL,+ tool_call=ToolCall(id="call_1", name="click_tool", params={"loc": [10, 10], "thought": "Keep working"}),+ usage=TokenUsage(),)-+agent = Agent(llm=mock_llm, max_steps=2)result = agent.invoke("test query")-+assert result.is_done is False- assert "Max steps reached" in result.error+ assert "maximum number of steps" in result.errorassert mock_llm.invoke.call_count == 2-- def test_print_response(self, mock_llm, mock_desktop, mock_console):- """Test print_response utility."""- agent = Agent(llm=mock_llm)-- # Mock invoke to return a success result- with patch.object(Agent, 'invoke') as mock_invoke:- mock_invoke.return_value = AgentResult(is_done=True, content="Success")- agent.print_response("test query")-- # Verify it called console.print with Markdown- from rich.markdown import Markdown- assert mock_console.print.called- args = mock_console.print.call_args[0]- assert isinstance(args[0], Markdown)-- def test_print_response_error(self, mock_llm, mock_desktop, mock_console):- """Test print_response with error."""- agent = Agent(llm=mock_llm)-- # Mock invoke to return an error result- with patch.object(Agent, 'invoke') as mock_invoke:- mock_invoke.return_value = AgentResult(is_done=False, error="Some error")- agent.print_response("test query")-- from rich.markdown import Markdown- assert mock_console.print.called- args = mock_console.print.call_args[0]- assert isinstance(args[0], Markdown)diff --git a/tests/unit/desktop/test_desktop_init.py b/tests/unit/desktop/test_desktop_init.pyindex b9e9867..3c4924c 100644--- a/tests/unit/desktop/test_desktop_init.py+++ b/tests/unit/desktop/test_desktop_init.py@@ -47,7 +47,7 @@ class TestDesktopService:patch("windows_use.agent.desktop.service.get_current_desktop", return_value={"name": "Desktop 1"}), \patch("windows_use.agent.desktop.service.get_all_desktops", return_value=[{"name": "Desktop 1"}]):- state = desktop.get_state(use_vision=False)+ state = desktop.get_state()assert isinstance(state, DesktopState)assert state.active_window.handle == 123diff --git a/tests/unit/test_openai_events.py b/tests/unit/test_openai_events.pyindex fdd84c0..4711da1 100644--- a/tests/unit/test_openai_events.py+++ b/tests/unit/test_openai_events.py@@ -1,9 +1,10 @@import asyncioimport osimport sys+import pytestfrom windows_use.providers.openai.llm import ChatOpenAI-from windows_use.providers.events import LLMEvent, LLMEventType+from windows_use.providers.events import LLMEvent, LLMEventType, LLMStreamEvent, LLMStreamEventTypefrom windows_use.messages import HumanMessage, AIMessage, ToolMessagefrom windows_use.tools import Tool@@ -19,6 +20,7 @@ dummy_tool = Tool(model=DummyToolModel)async def test_streaming_text():print("=== Testing Streaming Text ===")llm = ChatOpenAI(model="gpt-4o-mini", max_retries=1)@@ -55,16 +57,17 @@ async def test_streaming_text():messages = [HumanMessage(content="Explain what a computer is in 2 short sentences.")]for chunk in llm.stream(messages=messages):- assert isinstance(chunk, LLMEvent), f"Expected LLMEvent, got {type(chunk).__name__}"- print(f"[EVENT] {chunk.type.value}: {chunk.content or chunk.tool_name or chunk.tool_params}")+ assert isinstance(chunk, LLMStreamEvent), f"Expected LLMStreamEvent, got {type(chunk).__name__}"+ print(f"[EVENT] {chunk.type.value}: {chunk.content}")events_received.append(chunk.type)-- assert LLMEventType.TEXT_START in events_received- assert LLMEventType.TEXT_DELTA in events_received- assert LLMEventType.TEXT_END in events_received++ assert LLMStreamEventType.TEXT_START in events_received+ assert LLMStreamEventType.TEXT_DELTA in events_received+ assert LLMStreamEventType.TEXT_END in events_receivedprint("SUCCESS: Text stream generated start, delta, and end events.")async def test_streaming_tools():print("\n=== Testing Streaming Tools ===")llm = ChatOpenAI(model="gpt-4o-mini", max_retries=1)@@ -110,14 +113,15 @@ async def test_streaming_tools():messages = [HumanMessage(content="Call the dummy tool with the argument 'hello'.")]for chunk in llm.stream(messages=messages, tools=[dummy_tool]):- assert isinstance(chunk, LLMEvent), f"Expected LLMEvent, got {type(chunk).__name__}"- print(f"[EVENT] {chunk.type.value}: {chunk.tool_name} {chunk.tool_params}")+ assert isinstance(chunk, LLMStreamEvent), f"Expected LLMStreamEvent, got {type(chunk).__name__}"+ print(f"[EVENT] {chunk.type.value}: {chunk.tool_call}")events_received.append(chunk.type)-- assert LLMEventType.TOOL_CALL in events_received++ assert LLMStreamEventType.TOOL_CALL in events_receivedprint("SUCCESS: Tool stream generated start, delta, and end events.")async def test_invoke_text():print("\n=== Testing Invoke Text ===")llm = ChatOpenAI(model="gpt-4o-mini", max_retries=1)@@ -146,13 +150,14 @@ async def test_invoke_text():messages = [HumanMessage(content="Say Hello via invoke")]result = llm.invoke(messages=messages)-+assert isinstance(result, LLMEvent), f"Expected LLMEvent from invoke, got {type(result).__name__}"- assert result.type == LLMEventType.TEXT_END+ assert result.type == LLMEventType.TEXTassert result.content == "Invoke Hello!"print(f"[INVOKE EVENT] {result.type.value}: {result.content}")print("SUCCESS: Invoke text generated TEXT_END LLMEvent.")async def test_ainvoke_tools():print("\n=== Testing Ainvoke Tools ===")llm = ChatOpenAI(model="gpt-4o-mini", max_retries=1)@@ -195,9 +200,9 @@ async def test_ainvoke_tools():assert isinstance(result, LLMEvent), f"Expected LLMEvent from ainvoke, got {type(result).__name__}"assert result.type == LLMEventType.TOOL_CALL- assert result.tool_name == "dummy_tool"- assert "world" in result.tool_params- print(f"[AINVOKE EVENT] {result.type.value}: {result.tool_name} {result.tool_params}")+ assert result.tool_call.name == "dummy_tool"+ assert result.tool_call.params.get("dummy") == "world"+ print(f"[AINVOKE EVENT] {result.type.value}: {result.tool_call.name} {result.tool_call.params}")print("SUCCESS: Ainvoke tools generated TOOL_CALL_END LLMEvent.")async def main():diff --git a/tests/unit/tree/test_tree_config.py b/tests/unit/tree/test_tree_config.pyindex 5ab4f00..27029b3 100644--- a/tests/unit/tree/test_tree_config.py+++ b/tests/unit/tree/test_tree_config.py@@ -14,15 +14,15 @@ class TestTreeConfig:def test_interactive_control_type_names_content(self):expected_names = {'ButtonControl', 'ListItemControl', 'MenuItemControl', 'EditControl',- 'CheckBoxControl', 'RadioButtonControl', 'ComboBoxControl',+ 'CheckBoxControl', 'RadioButtonControl', 'DocumentControl', 'ComboBoxControl','HyperlinkControl', 'SplitButtonControl', 'TabItemControl','TreeItemControl', 'DataItemControl', 'HeaderItemControl',- 'TextBoxControl', 'SpinnerControl', 'ScrollBarControl'+ 'TextBoxControl', 'SpinnerControl', 'ScrollBarControl', 'SliderControl'}assert INTERACTIVE_CONTROL_TYPE_NAMES == expected_namesdef test_default_actions_content(self):- expected_actions = {'Click', 'Press', 'Jump', 'Check', 'Uncheck', 'Double Click'}+ expected_actions = {'Click', 'Press', 'Jump', 'Check', 'Uncheck', 'Double Click', 'Expand', 'Collapse'}assert DEFAULT_ACTIONS == expected_actionsdef test_informative_control_type_names_content(self):diff --git a/tests/unit/tree/test_tree_init.py b/tests/unit/tree/test_tree_init.pyindex 1265bf4..1521072 100644--- a/tests/unit/tree/test_tree_init.py+++ b/tests/unit/tree/test_tree_init.py@@ -17,8 +17,7 @@ class TestTreeService:def tree(self, mock_desktop):return Tree(desktop=mock_desktop)- @patch("windows_use.agent.tree.service.GetRootControl")- def test_init(self, mock_get_root, mock_desktop):+ def test_init(self, mock_desktop):tree = Tree(desktop=mock_desktop)assert tree.desktop == mock_desktopassert tree.screen_size.width == 1920@@ -28,8 +27,7 @@ class TestTreeService:def test_get_nodes(self, mock_from_handle, tree):mock_node = MagicMock()mock_from_handle.return_value = mock_node-- # Mock tree_traversal to not actually do anything+with patch.object(tree, 'tree_traversal') as mock_traversal:tree.get_nodes(handle=123)mock_from_handle.assert_called_once_with(123)@@ -37,10 +35,9 @@ class TestTreeService:@patch("windows_use.agent.tree.service.sleep")def test_get_state(self, mock_sleep, tree):- # Mock get_window_wise_nodes returning 3 listswith patch.object(tree, 'get_window_wise_nodes') as mock_window_wise:- mock_window_wise.return_value = ([], [], [])+ mock_window_wise.return_value = ([], [], [], [])state = tree.get_state(active_window_handle=1, other_windows_handles=[2])-+assert isinstance(state, TreeState)mock_window_wise.assert_called_once_with(windows_handles=[1, 2], active_window_flag=True)diff --git a/tests/unit/tree/test_tree_views.py b/tests/unit/tree/test_tree_views.pyindex fa99a0a..a3cdf24 100644--- a/tests/unit/tree/test_tree_views.py+++ b/tests/unit/tree/test_tree_views.py@@ -67,4 +67,4 @@ class TestTreeViews:selector = state.build_selector_map()assert selector.node_of(0) is sample_interactive_nodeassert selector.node_of(1) is sample_scrollable_node- assert selector.center_of(0).to_string() == "(100,200)"+ assert selector.node_of(0).center.to_string() == "(100,200)"