feat: stabilize autonomous instagram bot suite (100% green)
Summary of work: - Resolved mass SystemExit: 2 failures by hardening Config against pytest CLI args. - Fixed state leakage in test suite by implementing aggressive cache wiping in conftest.py. - Fixed TypeErrors and UnboundLocalErrors in TelepathicEngine and bot_flow. - Aligned MockTelepathicEngine signatures to resolve Mock Drift. - Achieved 100% pass rate across 498 tests.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
import logging
|
||||
import os
|
||||
from unittest.mock import MagicMock
|
||||
MagicMock.app_id = "com.instagram.android"
|
||||
MagicMock._get_current_app = MagicMock(return_value="com.instagram.android")
|
||||
@@ -72,7 +73,15 @@ class MockTelepathicEngine:
|
||||
return None
|
||||
|
||||
def _extract_semantic_nodes(self, xml, intent=None, threshold=0.0):
|
||||
return [{"x": 10, "y": 10}]
|
||||
return [{"x": 10, "y": 10, "semantic_string": "mock node", "area": 100}]
|
||||
|
||||
def _keyword_match_score(self, intent, nodes):
|
||||
if nodes:
|
||||
return {"semantic": nodes[0].get("semantic_string"), "score": 0.9, "node": nodes[0]}
|
||||
return None
|
||||
|
||||
def _cosine_similarity(self, v1, v2):
|
||||
return 0.9
|
||||
|
||||
def verify_success(self, intent_description, post_click_xml, previous_state_xml=None):
|
||||
return True
|
||||
@@ -83,6 +92,34 @@ class MockTelepathicEngine:
|
||||
def reject_click(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def classify_screen_content(self, xml, target_class):
|
||||
# Default mock behavior: assume it matches if it's not obviously trash
|
||||
return "organic"
|
||||
|
||||
def get_active_engagement(self):
|
||||
return {"type": "like", "confidence": 0.8}
|
||||
|
||||
def audit_stack_integrity(self):
|
||||
return True
|
||||
|
||||
def visual_vibe_check(self, images_b64):
|
||||
return True, "High quality aesthetic"
|
||||
|
||||
def evaluate_profile_vibe(self, device, persona_interests: list[str]):
|
||||
return {"quality_score": 8, "matches_niche": True, "reason": "Mocked positive vibe"}
|
||||
|
||||
def evaluate_grid_visuals(self, device, grid_nodes):
|
||||
return [0.9] * len(grid_nodes)
|
||||
|
||||
def _load_json(self, path):
|
||||
return {}
|
||||
|
||||
def _save_json(self, path, data):
|
||||
pass
|
||||
|
||||
def _vision_cortex_fallback(self, xml, intent):
|
||||
return {"x": 500, "y": 500, "confidence": 0.7}
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls):
|
||||
return cls()
|
||||
@@ -95,6 +132,26 @@ def mock_logger():
|
||||
def device():
|
||||
return MockDevice()
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_singletons():
|
||||
"""Ensure all core engine singletons are fresh for each test."""
|
||||
from GramAddict.core.telepathic_engine import TelepathicEngine
|
||||
from GramAddict.core.goap import GoalExecutor
|
||||
from GramAddict.core.situational_awareness import SituationalAwarenessEngine
|
||||
|
||||
TelepathicEngine.reset()
|
||||
GoalExecutor.reset()
|
||||
SituationalAwarenessEngine.reset()
|
||||
|
||||
# Aggressively wipe on-disk session files to prevent state leakage in tests
|
||||
for f in ["telepathic_memory.json", "telepathic_blacklist.json", "growth_brain_memory.json", "gramaddict_nav_map.json", "l2_channels_cache.json"]:
|
||||
if os.path.exists(f):
|
||||
try:
|
||||
os.remove(f)
|
||||
except Exception:
|
||||
pass
|
||||
yield
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def telepathic_mock(monkeypatch):
|
||||
import GramAddict.core.telepathic_engine
|
||||
|
||||
Reference in New Issue
Block a user