feat: implement brain-driven dynamic decision making to prevent goap traps

This commit is contained in:
2026-04-27 22:28:53 +02:00
parent 93175b7caf
commit da804b174a
4 changed files with 132 additions and 10 deletions

View File

@@ -0,0 +1,33 @@
from unittest.mock import patch
from GramAddict.core.navigation.planner import GoalPlanner
from GramAddict.core.perception.screen_identity import ScreenType
def test_planner_falls_back_to_brain_when_hd_map_fails():
"""
Test that if HD Map routing fails because the structural target is not visible
(and thus in explored_nav_actions), the planner falls back to the Brain
to dynamically pick an action like 'scroll down'.
"""
planner = GoalPlanner("testuser")
# Simulate a screen where the target isn't visible
screen = {
"screen_type": ScreenType.OWN_PROFILE,
"available_actions": ["press back", "scroll down", "tap profile tab"],
"context": {},
}
# Simulate that 'tap following list' failed previously and is in explored actions
explored = {"tap following list"}
# The brain should realize that 'scroll down' is the best way to uncover the target
with patch("GramAddict.core.navigation.brain.ask_brain_for_action", return_value="scroll down") as mock_brain:
action = planner.plan_next_step("go to followers/following list", screen, explored_nav_actions=explored)
# Verify the brain was queried
mock_brain.assert_called_once()
# Verify the brain's decision is respected
assert action == "scroll down"