feat(tools): add long_press tool with humanize hook
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from device.manager import DeviceManager
|
||||
from tests.fakes import FakeDriver
|
||||
|
||||
|
||||
def _connected(driver: FakeDriver) -> DeviceManager:
|
||||
manager = DeviceManager()
|
||||
manager.register_device("phone", lambda: driver)
|
||||
manager.connect("phone", max_retries=1)
|
||||
return manager
|
||||
|
||||
|
||||
def test_long_press_disabled_passes_exact_coords(monkeypatch):
|
||||
monkeypatch.setenv("APEX_HUMANIZE_ENABLED", "false")
|
||||
from tools.long_press import long_press
|
||||
|
||||
driver = FakeDriver()
|
||||
res = long_press(100, 200, duration_ms=1500, manager=_connected(driver))
|
||||
assert driver.calls[-1] == ("long_press", (100, 200, 1500))
|
||||
assert res["action"] == "long_press"
|
||||
assert res["duration_ms"] == 1500
|
||||
|
||||
|
||||
def test_long_press_enabled_jitters_within_radius(monkeypatch):
|
||||
import random
|
||||
|
||||
monkeypatch.setenv("APEX_HUMANIZE_ENABLED", "true")
|
||||
from tools.humanize import set_rng
|
||||
from tools.long_press import long_press
|
||||
|
||||
set_rng(random.Random(5))
|
||||
try:
|
||||
driver = FakeDriver()
|
||||
long_press(100, 200, duration_ms=1500, manager=_connected(driver))
|
||||
finally:
|
||||
set_rng(None)
|
||||
name, args = driver.calls[-1]
|
||||
assert name == "long_press"
|
||||
px, py, _ = args
|
||||
assert abs(px - 100) <= 5.0 and abs(py - 200) <= 5.0
|
||||
Reference in New Issue
Block a user