Hardening: Streamlined testing infrastructure, unified toolkit, and established English TDD standards

This commit is contained in:
2026-04-21 10:17:27 +02:00
parent ee3022e95d
commit fff9ec5b0a
9 changed files with 322 additions and 118 deletions

View File

@@ -0,0 +1,48 @@
import os
import pytest
from unittest.mock import MagicMock
from GramAddict.core.telepathic_engine import TelepathicEngine
from GramAddict.core.device_facade import DeviceFacade
@pytest.mark.skipif(not os.environ.get("RUN_LIVE_AI_TESTS"), reason="Requires a running local LLM/Ollama instance and RUN_LIVE_AI_TESTS=1")
def test_real_llm_pathfinding_on_golden_fixture():
"""
Validates that the REAL telepathic engine (hitting the real LLM endpoint)
can successfully parse a real IG XML dump and locate standard elements
without hallucinating or crashing.
"""
# 1. Load a real XML dump from our golden fixtures
fixture_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "fixtures")
xml_path = os.path.join(fixture_dir, "explore_feed_dump.xml")
assert os.path.exists(xml_path), "Golden fixture explore_feed_dump.xml is missing. Make sure sync_fixtures.py was run."
with open(xml_path, "r", encoding="utf-8") as f:
xml_data = f.read()
# 2. Setup a fresh real engine
engine = TelepathicEngine()
# Mute the actual screencap logic, but provide valid display bounds
device = MagicMock(spec=DeviceFacade)
device.get_info.return_value = {"displayWidth": 1080, "displayHeight": 2400}
# Mock screenshot to prevent hitting the adb shell during this specific offline text-parsing test
device.screenshot = MagicMock()
# 3. Fire the intent against the real LLM endpoint.
# We force min_confidence=1.1 so it ALWAYS hits the LLM Vision Cortex Fallback
# and bypasses the local vector DB cache (to ensure we test the prompt & JSON extraction).
result = engine.find_best_node(xml_data, "tap reels tab", min_confidence=1.1, device=device)
# 4. Assert it actually found something sane instead of hallucinating
assert result is not None, "Real LLM failed to understand the XML and return a valid action json."
assert "x" in result and "y" in result, "Coordinates missing from VLM payload"
# The Reels tab on standard IG UI is in the bottom navigation bar
# usually around y=2200-2400 and roughly x=540
assert result["y"] > 2000, f"Expected reels tab to be at the bottom screen, but got y={result['y']}"
assert 400 < result["x"] < 700, f"Expected reels tab to be in bottom middle, but got x={result['x']}"
print(f"SUCCESS: LLM detected reels tab correctly at x={result['x']}, y={result['y']}")