Skip to content

The agent that grows with you

fix(test): patch threading.Event class for CUA timeout tests

Jasmine Naderi33fe1cc9e536
diff --git a/tests/tools/test_computer_use.py b/tests/tools/test_computer_use.py
index 2aaadbb37b4..0e05a830a1f 100644
--- a/tests/tools/test_computer_use.py
+++ b/tests/tools/test_computer_use.py
@@ -4085,7 +4085,7 @@ class TestStartupTimeoutPhaseDetail:
def test_timeout_error_includes_startup_phase(self):
import threading
from typing import Any, cast
- from unittest.mock import MagicMock
+ from unittest.mock import MagicMock, patch as _patch
from tools.computer_use.cua_backend import _CuaDriverSession
session = cast(Any, _CuaDriverSession.__new__(_CuaDriverSession))
@@ -4101,8 +4101,20 @@ class TestStartupTimeoutPhaseDetail:
session._bridge = fake_bridge
import asyncio
- from unittest.mock import patch as _patch
- with _patch.object(session._ready_event, "wait", return_value=False), \
+
+ class _FakeEvent:
+ """Event whose wait() always returns False (timeout path).
+
+ #69372: _start_lifecycle_locked reassigns a fresh threading.Event()
+ at line 786, so patching the pre-made instance's wait() is lost.
+ Patching threading.Event itself ensures the fresh instance also
+ has the mocked wait()."""
+ def set(self): pass
+ def is_set(self): return False
+ def clear(self): pass
+ def wait(self, timeout=None): return False
+
+ with _patch.object(threading, "Event", _FakeEvent), \
_patch.object(asyncio, "run_coroutine_threadsafe", return_value=MagicMock()), \
_patch.object(_CuaDriverSession, "_lifecycle_coro", lambda self: None):
try:
@@ -4131,7 +4143,13 @@ class TestStartupTimeoutPhaseDetail:
fake_bridge._loop = MagicMock()
session._bridge = fake_bridge
- with _patch.object(session._ready_event, "wait", return_value=False), \
+ class _FakeEvent:
+ def set(self): pass
+ def is_set(self): return False
+ def clear(self): pass
+ def wait(self, timeout=None): return False
+
+ with _patch.object(threading, "Event", _FakeEvent), \
_patch.object(asyncio, "run_coroutine_threadsafe", return_value=MagicMock()), \
_patch.object(_CuaDriverSession, "_lifecycle_coro", lambda self: None):
try: