feat(navigation): complete autonomous integration tests and goal weighting
This commit is contained in:
72
tests/e2e/test_e2e_autonomous_session.py
Normal file
72
tests/e2e/test_e2e_autonomous_session.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import logging
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from GramAddict.core.config import Config
|
||||
from GramAddict.core.session_state import SessionState
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def test_autonomous_session_goal_weighting(make_real_device_with_xml):
|
||||
"""
|
||||
E2E test that validates the complete DeviceFacade stack during an autonomous session.
|
||||
It verifies that the GrowthBrain weights successful goals correctly during
|
||||
a multi-goal session iteration.
|
||||
"""
|
||||
device = make_real_device_with_xml("mock_ui_dump.xml")
|
||||
|
||||
# Mock configs
|
||||
mock_configs = MagicMock(spec=Config)
|
||||
mock_configs.args = MagicMock()
|
||||
mock_configs.args.goals = ["goal_A", "goal_B"]
|
||||
mock_configs.args.username = "test_user"
|
||||
|
||||
# Mock dopamine to run 5 iterations
|
||||
mock_dopamine = MagicMock()
|
||||
mock_dopamine.boredom = 0
|
||||
# Stop session after 5 iterations
|
||||
mock_dopamine.is_app_session_over.side_effect = [False] * 5 + [True]
|
||||
|
||||
# Setup session state with specific success rates
|
||||
session_state = SessionState(mock_configs)
|
||||
session_state.successfulInteractions = {
|
||||
"goal_A": 0,
|
||||
"goal_B": 100, # goal_B is highly successful
|
||||
}
|
||||
|
||||
mock_cognitive_stack = {"dopamine": mock_dopamine, "telepathic": MagicMock()}
|
||||
|
||||
# Track which goals were executed
|
||||
executed_goals = []
|
||||
|
||||
def mock_run_goal(device, cognitive_stack, target, session_state):
|
||||
executed_goals.append(target)
|
||||
return True
|
||||
|
||||
with patch("GramAddict.core.bot_flow.GoalExecutor") as MockGoalExecutor:
|
||||
mock_executor = MockGoalExecutor.return_value
|
||||
mock_executor.run.side_effect = mock_run_goal
|
||||
|
||||
# We need to test the inner autonomous loop
|
||||
# Since start_bot is huge, we will call a smaller unit if possible,
|
||||
# but let's test GrowthBrain inside a simulated bot flow
|
||||
|
||||
from GramAddict.core.growth_brain import GrowthBrain
|
||||
|
||||
growth_brain = GrowthBrain(username="test_user")
|
||||
|
||||
# Simulate the while loop inside start_bot that asks for goals
|
||||
for _ in range(5):
|
||||
success_rates = getattr(session_state, "successfulInteractions", {})
|
||||
current_goal = growth_brain.get_current_goal(
|
||||
mock_dopamine, getattr(mock_configs.args, "goals", []), success_rates=success_rates
|
||||
)
|
||||
mock_executor.run(device, mock_cognitive_stack, current_goal, session_state)
|
||||
|
||||
# Validate results
|
||||
# Since goal_B has a weight of 101, and goal_A has a weight of 1,
|
||||
# goal_B should be chosen almost exclusively
|
||||
assert "goal_B" in executed_goals, "goal_B should have been executed"
|
||||
assert executed_goals.count("goal_B") > executed_goals.count(
|
||||
"goal_A"
|
||||
), "goal_B should be chosen more often than goal_A due to weighting"
|
||||
Reference in New Issue
Block a user