v1.0 - Version stable: multi-PC, détection UI-DETR-1, 3 modes exécution
- Frontend v4 accessible sur réseau local (192.168.1.40) - Ports ouverts: 3002 (frontend), 5001 (backend), 5004 (dashboard) - Ollama GPU fonctionnel - Self-healing interactif - Dashboard confiance Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
82
tests/unit/test_sniper_container_preference.py
Normal file
82
tests/unit/test_sniper_container_preference.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
Tests pour Fiche #7 - Container Preference
|
||||
|
||||
Auteur: Dom, Alice Kiro - 15 décembre 2024
|
||||
Objectif: Valider que le resolver privilégie le bon container/panel quand il y a plusieurs candidats identiques
|
||||
|
||||
Test: Même label "Username", deux panels → doit choisir le bon panel
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
# Marquer tous les tests de ce fichier comme fiche7
|
||||
pytestmark = pytest.mark.fiche7
|
||||
|
||||
from datetime import datetime
|
||||
from core.execution.target_resolver import TargetResolver, ResolutionContext
|
||||
from core.models.workflow_graph import TargetSpec
|
||||
from core.models.screen_state import ScreenState, RawLevel, PerceptionLevel, ContextLevel, WindowContext, EmbeddingRef
|
||||
from core.models.ui_element import UIElement, UIElementEmbeddings, VisualFeatures
|
||||
|
||||
|
||||
def E(eid, role, bbox, label="", etype="ui", conf=0.9):
|
||||
"""Helper pour créer un UIElement rapidement"""
|
||||
return UIElement(
|
||||
element_id=eid,
|
||||
type=etype,
|
||||
role=role,
|
||||
bbox=bbox,
|
||||
center=(bbox[0] + bbox[2]//2, bbox[1] + bbox[3]//2),
|
||||
label=label,
|
||||
label_confidence=1.0,
|
||||
embeddings=UIElementEmbeddings(image=None, text=None),
|
||||
visual_features=VisualFeatures(dominant_color="n/a", has_icon=False, shape="rectangle", size_category="medium"),
|
||||
confidence=conf,
|
||||
tags=[],
|
||||
metadata={}
|
||||
)
|
||||
|
||||
|
||||
def S(elements):
|
||||
"""Helper pour créer un ScreenState rapidement"""
|
||||
return ScreenState(
|
||||
screen_state_id="s",
|
||||
timestamp=datetime.now(),
|
||||
session_id="sess",
|
||||
window=WindowContext(app_name="app", window_title="win", screen_resolution=[1920,1080]),
|
||||
raw=RawLevel(screenshot_path="x", capture_method="test", file_size_bytes=1),
|
||||
perception=PerceptionLevel(
|
||||
embedding=EmbeddingRef(provider="p", vector_id="v", dimensions=1),
|
||||
detected_text=[],
|
||||
text_detection_method="none",
|
||||
confidence_avg=0.0
|
||||
),
|
||||
context=ContextLevel(),
|
||||
ui_elements=elements
|
||||
)
|
||||
|
||||
|
||||
def test_prefers_same_panel_as_anchor():
|
||||
"""Test que le resolver privilégie le container qui contient l'ancre"""
|
||||
# Panel A (login)
|
||||
panelA = E("panelA", "panel", (50, 50, 600, 400), etype="panel", conf=1.0)
|
||||
lblA = E("lblA", "label", (80, 100, 120, 20), "Username", conf=1.0)
|
||||
inpA = E("inpA", "input", (240, 95, 260, 30), "", etype="text_input")
|
||||
|
||||
# Panel B (settings) - même label / input ailleurs
|
||||
panelB = E("panelB", "panel", (700, 50, 600, 400), etype="panel", conf=1.0)
|
||||
lblB = E("lblB", "label", (730, 100, 120, 20), "Username", conf=1.0)
|
||||
inpB = E("inpB", "input", (890, 95, 260, 30), "", etype="text_input")
|
||||
|
||||
screen = S([panelA, panelB, lblA, inpA, lblB, inpB])
|
||||
|
||||
spec = TargetSpec(by_role="input", context_hints={"right_of_text": "Username"})
|
||||
r = TargetResolver()
|
||||
res = r.resolve_target(spec, screen, ResolutionContext(screen_state=screen, previous_target=None))
|
||||
|
||||
assert res is not None
|
||||
assert res.element.element_id == "inpA"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-v"])
|
||||
Reference in New Issue
Block a user