Four things in tool.py existed only for tests: - the module-level _backend injection hook (its own comment: "backward- compatible empty-session injection hook (older tests)") and its mirror branches in _install_backend, _detach_locked, _get_backend and _shutdown_backend_atexit. Production installs backends only through _new_backend into the _backends cache, so with nothing assigning _backend every branch was a no-op. The two tests that assigned it now patch _new_backend, the seam the rest of the suite already uses; the atexit tests seed _backends instead. - reset_backend_for_tests, now tests/computer_use_fakes.reset_backend (the same two calls: _shutdown_backend_atexit, _reset_screenshot_dedup). - _noop_stub and _NoopBackend (pragma: no cover, docstring "Test stub"), moved verbatim to tests/computer_use_fakes.py as noop_stub / NoopBackend. - the _bounds_scale and _bounds_space_note lambdas, which only indexed _bounds_hints; the tests index _bounds_hints directly. None of these names is in hermes_cli/data/plugin_api.json (it publishes tools.computer_use.backend only) or tests/compat/old_updater_surface.json.
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""Exercise existing computer-use actions on the actual Windows/macOS CI hosts."""
|
|
|
|
import json
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from tools.computer_use import tool
|
|
from tests.computer_use_fakes import NoopBackend, reset_backend
|
|
|
|
|
|
@pytest.fixture
|
|
def backend(monkeypatch):
|
|
reset_backend()
|
|
monkeypatch.setattr(tool, "_new_backend", lambda mode: NoopBackend())
|
|
# Input actions are approval-gated; a CI runner has no approver, so the gate would block
|
|
# before the dispatch this test is about. Same seam the capture-fence tests use.
|
|
monkeypatch.setattr(tool, "_request_approval", lambda *a, **k: None)
|
|
value = tool._get_backend()
|
|
yield value
|
|
reset_backend()
|
|
|
|
|
|
@pytest.mark.parametrize("host_platform", [
|
|
pytest.param("win32", marks=pytest.mark.platforms("windows")),
|
|
pytest.param("darwin", marks=pytest.mark.platforms("macos")),
|
|
])
|
|
@pytest.mark.parametrize("args, expected_call", [
|
|
({"action": "capture", "mode": "ax"}, "capture"),
|
|
({"action": "click", "coordinate": [10, 10]}, "click"),
|
|
({"action": "type", "text": "test input"}, "type"),
|
|
({"action": "list_windows"}, "list_windows"),
|
|
])
|
|
def test_native_computer_use_dispatches_to_backend(backend, args, expected_call, host_platform):
|
|
import tools.computer_use_tool
|
|
from tools.registry import registry
|
|
|
|
assert sys.platform == host_platform
|
|
result = registry.dispatch("computer_use", args)
|
|
|
|
assert "error" not in json.loads(result)
|
|
assert [name for name, _ in backend.calls] == [expected_call]
|