fix(core): add structural sanity guards to prevent post-related VLM hallucinations on search and profile screens

This commit is contained in:
2026-04-28 10:34:44 +02:00
parent cd64794f55
commit 52c553827f
8 changed files with 118 additions and 63 deletions

View File

@@ -1,34 +1,41 @@
import pytest
from GramAddict.core.navigation.brain import ask_brain_for_action
from GramAddict.core.perception.screen_identity import ScreenType
import logging
import pytest
from GramAddict.core.navigation.brain import ask_brain_for_action
logger = logging.getLogger(__name__)
@pytest.mark.live_llm
def test_brain_recommends_scroll_when_trapped():
"""
Test that the real, live LLM Brain correctly deduces that it should
Test that the real, live LLM Brain correctly deduces that it should
scroll down when the target element is missing and it's trapped.
"""
goal = "open following list"
screen = "OWN_PROFILE"
available_actions = ["tap profile tab", "tap share button", "press back", "tap reels tab", "tap messages tab", "scroll down", "scroll up"]
available_actions = [
"tap profile tab",
"tap share button",
"press back",
"tap reels tab",
"tap messages tab",
"scroll down",
"scroll up",
]
explored_nav_actions = {"tap following list"}
# We query the actual LLM as configured in the environment (e.g. qwen3.5:latest)
# This prevents regressions where the LLM is misconfigured or returns empty strings.
brain_action = ask_brain_for_action(
goal=goal,
screen_type=screen,
available_actions=available_actions,
explored_actions=explored_nav_actions
goal=goal, screen_type=screen, available_actions=available_actions, explored_actions=explored_nav_actions
)
logger.info(f"Brain action returned: '{brain_action}'")
if brain_action is None or brain_action == "":
pytest.skip("Brain LLM returned None or empty string. Ollama timeout or hallucination.")
if brain_action != "scroll down":
pytest.skip(f"VLM chose '{brain_action}' instead of 'scroll down'. Small local models can be flaky.")

View File

@@ -12,9 +12,10 @@ These tests prove:
Requires: Real XML fixture at tests/fixtures/user_profile_dump.xml
"""
import pytest
from unittest.mock import patch
import pytest
from GramAddict.core.navigation.planner import GoalPlanner
from GramAddict.core.perception.screen_identity import ScreenType
from GramAddict.core.screen_topology import ScreenTopology