from __future__ import annotations import os import pytest from core.models import Bounds, Scene, SceneElement from runtime.ai_planner import AIPlanner from runtime.context import TaskContext from runtime.planner_config import PlannerConfig def _scene() -> Scene: return Scene( width=390, height=844, elements=[ SceneElement(id="send", type="button", text="Send", bounds=Bounds(300, 800, 60, 30)), ], ) @pytest.mark.integration def test_real_anthropic_ai_planner_selects_a_tool() -> None: if not os.environ.get("ANTHROPIC_API_KEY"): pytest.skip("ANTHROPIC_API_KEY is required for AI planner integration test") try: import anthropic # noqa: F401 except ImportError: pytest.skip("anthropic SDK is not installed") planner = AIPlanner(config=PlannerConfig(enabled=True, provider="anthropic", timeout=15.0)) context = TaskContext(task_id="task", goal="tap the send button") steps = planner.plan(goal="tap the send button", scene=_scene(), context=context) assert isinstance(steps, list) assert len(steps) <= 1 @pytest.mark.integration def test_real_openai_ai_planner_selects_a_tool() -> None: if not os.environ.get("OPENAI_API_KEY"): pytest.skip("OPENAI_API_KEY is required for AI planner integration test") try: import openai # noqa: F401 except ImportError: pytest.skip("openai SDK is not installed") planner = AIPlanner(config=PlannerConfig(enabled=True, provider="openai", timeout=15.0)) context = TaskContext(task_id="task", goal="tap the send button") steps = planner.plan(goal="tap the send button", scene=_scene(), context=context) assert isinstance(steps, list) assert len(steps) <= 1