_capture_screen() accepte un monitor_idx optionnel (None = composite legacy). Index logique 0..N-1 mappé sur mss.monitors[idx+1] (mss[0] = composite). Les 3 niveaux de grounding (OCR, UI-TARS, VLM) propagent l'offset retourné par la capture pour traduire les coordonnées locales monitor en coordonnées absolues écran (correct pour pyautogui.click). find_element_on_screen() accepte monitor_idx et le forwarde aux 3 niveaux. Backward 100% : monitor_idx=None partout → comportement strictement actuel. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
42 lines
2.0 KiB
Python
42 lines
2.0 KiB
Python
# tests/integration/test_grounding_offset.py
|
|
"""Tests intégration pour la propagation d'offset multi-écrans (QW1)."""
|
|
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
from core.execution import input_handler
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_screen():
|
|
"""Mock une capture mss : retourne un PIL Image factice + offsets."""
|
|
from PIL import Image
|
|
img = Image.new("RGB", (1920, 1080), color="white")
|
|
return img
|
|
|
|
|
|
def test_capture_screen_default_returns_composite_when_no_idx(mock_screen):
|
|
"""_capture_screen() sans monitor_idx → composite, offset (0, 0)."""
|
|
with patch("core.execution.input_handler.mss") as mock_mss:
|
|
ctx = mock_mss.mss.return_value.__enter__.return_value
|
|
ctx.monitors = [{"left": 0, "top": 0, "width": 3840, "height": 1080}]
|
|
ctx.grab.return_value = MagicMock(size=(3840, 1080), bgra=b"\x00" * (3840 * 1080 * 4))
|
|
with patch("core.execution.input_handler.PILImage.frombytes", return_value=mock_screen):
|
|
screen, w, h, ox, oy = input_handler._capture_screen()
|
|
assert (w, h, ox, oy) == (3840, 1080, 0, 0)
|
|
|
|
|
|
def test_capture_screen_targets_specific_monitor_with_offset(mock_screen):
|
|
"""_capture_screen(monitor_idx=1) → cible monitors[2] (mss skip [0]), offset = monitor.left."""
|
|
with patch("core.execution.input_handler.mss") as mock_mss:
|
|
ctx = mock_mss.mss.return_value.__enter__.return_value
|
|
# mss layout : [0]=composite, [1]=primary, [2]=secondary
|
|
ctx.monitors = [
|
|
{"left": 0, "top": 0, "width": 3840, "height": 1080},
|
|
{"left": 0, "top": 0, "width": 1920, "height": 1080},
|
|
{"left": 1920, "top": 0, "width": 1920, "height": 1080},
|
|
]
|
|
ctx.grab.return_value = MagicMock(size=(1920, 1080), bgra=b"\x00" * (1920 * 1080 * 4))
|
|
with patch("core.execution.input_handler.PILImage.frombytes", return_value=mock_screen):
|
|
screen, w, h, ox, oy = input_handler._capture_screen(monitor_idx=1)
|
|
assert (w, h, ox, oy) == (1920, 1080, 1920, 0)
|