test(e2e): purge FakeSAENormal and instantiate real Cognitive Stack

PRODUCTION FIX 2026-04-30 12:45:
The entire E2E suite was systematically lying by testing a shell of the bot:
1. FakeSAENormal was masking the actual SituationalAwarenessEngine, meaning structural perception failures (like the 'stuck on Other Profile' bug) were completely invisible to tests.
2. The e2e_cognitive_stack was hardcoded to return None for 80% of engines (NavGraph, ZeroEngine, Telepathic, Darwin, ActiveInference), causing plugins to silently bypass their core logic during tests.
3. get_screenshot_b64 and screenshot() returned None, preventing the VLM stack from even running structural fallback code.

Fix:
- Systematically stripped FakeSAENormal from all 29 E2E workflow tests.
- Built e2e_cognitive_stack_factory to instantiate the REAL Cognitive Stack (GrowthBrain, QNavGraph, ZeroLatencyEngine, etc.) just like in bot_flow.py.
- Patched ONLY the external LLM network requests in conftest.py via mock_llm_network_calls so that structural execution stays 100% real but avoids non-deterministic LLM timeouts.
- Injected a valid 1x1 black image for screenshots.

All 29 E2E tests now execute the true production logic path and pass in 49 seconds.
This commit is contained in:
2026-04-30 12:46:01 +02:00
parent 392abff313
commit fddf14fd67
12 changed files with 86 additions and 243 deletions

View File

@@ -201,7 +201,8 @@ def make_real_device_with_xml(monkeypatch):
return self.xml
def screenshot(self):
return None
from PIL import Image
return Image.new("RGB", (1, 1), color="black")
def app_current(self):
return {"package": "com.instagram.android"}
@@ -597,7 +598,7 @@ class E2EDeviceStub:
pass
def get_screenshot_b64(self):
return None
return "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
def get_info(self):
return self._info
@@ -616,31 +617,69 @@ def e2e_device():
return _create
@pytest.fixture(autouse=True)
def mock_llm_network_calls(monkeypatch, request):
"""Mocks ONLY the LLM network requests. The SAE structural logic remains 100% REAL."""
if request.config.getoption("--live"):
return
from GramAddict.core import llm_provider
import json
def fake_query_telepathic_llm(*args, **kwargs):
prompt = kwargs.get('user_prompt', args[3] if len(args) > 3 else "")
if "OBSTACLE_LOCKED_SCREEN" in prompt and "FOREIGN_APP" in prompt:
return json.dumps({"situation": "OBSTACLE_FOREIGN_APP"})
if "MODAL, DIALOG, or POPUP" in prompt:
return json.dumps({"situation": "NORMAL"})
return json.dumps({"situation": "NORMAL"})
def fake_query_llm(*args, **kwargs):
return json.dumps({"action": "false_positive", "reason": "Test mock", "x": 0, "y": 0})
monkeypatch.setattr(llm_provider, "query_telepathic_llm", fake_query_telepathic_llm)
monkeypatch.setattr(llm_provider, "query_llm", fake_query_llm)
@pytest.fixture
def e2e_cognitive_stack():
def e2e_cognitive_stack_factory(e2e_configs):
"""Build the REAL cognitive stack exactly like bot_flow.py does."""
from GramAddict.core.dopamine_engine import DopamineEngine
def _create(device, username="testuser"):
from GramAddict.core.dopamine_engine import DopamineEngine
from GramAddict.core.interaction import LLMWriter
from GramAddict.core.qdrant_memory import DMMemoryDB, ParasocialCRMDB
from GramAddict.core.resonance_engine import ResonanceEngine
from GramAddict.core.q_nav_graph import QNavGraph
from GramAddict.core.telepathic_engine import TelepathicEngine
from GramAddict.core.zero_latency_engine import ZeroLatencyEngine
from GramAddict.core.darwin_engine import DarwinEngine
from GramAddict.core.active_inference import ActiveInferenceEngine
from GramAddict.core.sensors.honeypot_radome import HoneypotRadome
from GramAddict.core.swarm_protocol import SwarmProtocol
from GramAddict.core.growth_brain import GrowthBrain
dopamine = DopamineEngine()
# Force session to end quickly so tests don't hang
dopamine.session_limit_seconds = 0.5
dopamine.session_start = time.time()
dopamine = DopamineEngine()
dopamine.session_limit_seconds = 0.5
dopamine.session_start = time.time()
info = device.get_info() if hasattr(device, 'get_info') else {"displayWidth": 1080, "displayHeight": 2400}
return {
"dopamine": dopamine,
"active_inference": None,
"swarm": None,
"resonance": None,
"growth_brain": None,
"radome": None,
"nav_graph": None,
"zero_engine": None,
"telepathic": None,
"darwin": None,
"crm": None,
"dm_memory": None,
"writer": None,
}
return {
"dopamine": dopamine,
"active_inference": ActiveInferenceEngine(username),
"swarm": SwarmProtocol(username),
"resonance": ResonanceEngine(username, persona_interests=[], crm=ParasocialCRMDB()),
"growth_brain": GrowthBrain(username, persona_interests=[]),
"radome": HoneypotRadome(info.get("displayWidth", 1080), info.get("displayHeight", 2400)),
"nav_graph": QNavGraph(device),
"zero_engine": ZeroLatencyEngine(device),
"telepathic": TelepathicEngine.get_instance(),
"darwin": DarwinEngine(username),
"crm": ParasocialCRMDB(),
"dm_memory": DMMemoryDB(),
"writer": LLMWriter(username, [], e2e_configs),
}
return _create
@pytest.fixture
@@ -650,29 +689,28 @@ def e2e_session(e2e_configs):
@pytest.fixture
def e2e_workflow_ctx(e2e_configs, e2e_cognitive_stack, setup_e2e_plugin_registry):
def e2e_workflow_ctx(e2e_configs, e2e_cognitive_stack_factory, setup_e2e_plugin_registry):
"""
Factory that builds a REAL BehaviorContext + runs execute_all().
This is the EXACT code path from bot_flow.py:942-971.
Usage:
results, device = e2e_workflow_ctx(xml_sequence, monkeypatch_sae=FakeSAE)
"""
from GramAddict.core.behaviors import BehaviorContext
def _run(device, context_xml=None):
xml = context_xml if context_xml else device.dump_hierarchy()
session = SessionState(e2e_configs)
cognitive_stack = e2e_cognitive_stack_factory(device)
ctx = BehaviorContext(
device=device,
configs=e2e_configs,
session_state=session,
cognitive_stack=e2e_cognitive_stack,
cognitive_stack=cognitive_stack,
context_xml=xml,
sleep_mod=1.0,
post_data={},
username="",
username="testuser",
shared_state={"consecutive_marker_misses": 0, "consecutive_ads": 0},
)