Files
instagram-bot/tests/conftest.py
Marc Mintel ba4d7ffda2 chore: migrate autonomous navigation to GOAP and finalize 100% E2E test stabilization
- Delegate legacy BFS navigation to structure-based GOAP system
- Harden Situational Awareness Engine (SAE) for modal and obstacle clearance
- Fix device sizing calculations during mocked humanized scrolls
- Remove deprecated V8 test stubs and legacy debug entrypoints
- Stabilize Telepathic Engine context parsing thresholds
Result: 66/66 E2E and integration tests passing
2026-04-19 22:14:56 +02:00

122 lines
3.8 KiB
Python

import pytest
import logging
from unittest.mock import MagicMock
MagicMock.app_id = "com.instagram.android"
MagicMock._get_current_app = MagicMock(return_value="com.instagram.android")
class MockArgs:
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
class MockConfigs:
def __init__(self, args):
self.args = args
class MockDeviceV2:
def __init__(self):
self.clicks = []
self.shells = []
self.double_clicks = []
self.presses = []
self.xml_dump = "<hierarchy><node resource-id='com.instagram.android:id/row_comment_imageview' bounds='[10,10][20,20]' content-desc='Story' text='following' /><node resource-id='com.instagram.android:id/button_like' bounds='[50,50][60,60]' /><node resource-id='com.instagram.android:id/reel_viewer' /></hierarchy>"
def click(self, x, y):
self.clicks.append((x, y))
self.xml_dump += f"<node new='true' x='{x}' y='{y}' />"
def shell(self, cmd):
self.shells.append(cmd)
def double_click(self, x, y, duration=0):
self.double_clicks.append((x, y))
def press(self, key):
self.presses.append(key)
def dump_hierarchy(self):
return self.xml_dump
class MockDevice:
def __init__(self):
self.deviceV2 = MockDeviceV2()
self.app_id = "com.instagram.android"
def _get_current_app(self):
return "com.instagram.android"
def get_info(self):
return {"displayWidth": 1080, "displayHeight": 2400}
def cm_to_pixels(self, cm):
return cm * 10
def dump_hierarchy(self):
return self.deviceV2.dump_hierarchy()
def click(self, x=None, y=None, obj=None):
if obj:
x, y = obj.get("x", 0), obj.get("y", 0)
self.deviceV2.click(x, y)
class MockTelepathicEngine:
def find_best_node(self, xml, intent_description, device=None, **kwargs):
description = intent_description.lower()
if "story ring" in description:
return {"x": 100, "y": 100, "description": "Story Ring", "score": 1.0}
if "follow" in description or "folgen" in description:
return {"x": 200, "y": 200, "text": "Follow", "description": "Follow Button", "score": 1.0}
if "first image" in description or "profile grid" in description:
return {"x": 300, "y": 300, "description": "Grid Image", "score": 1.0}
return None
def _extract_semantic_nodes(self, xml, intent=None, threshold=0.0):
return [{"x": 10, "y": 10}]
def verify_success(self, intent_description, post_click_xml, previous_state_xml=None):
return True
def confirm_click(self, *args, **kwargs):
pass
def reject_click(self, *args, **kwargs):
pass
@classmethod
def get_instance(cls):
return cls()
@pytest.fixture
def mock_logger():
return logging.getLogger("test")
@pytest.fixture
def device():
return MockDevice()
@pytest.fixture(autouse=True)
def telepathic_mock(monkeypatch):
import GramAddict.core.telepathic_engine
engine = MockTelepathicEngine()
monkeypatch.setattr(GramAddict.core.telepathic_engine.TelepathicEngine, "get_instance", lambda: engine)
return engine
@pytest.fixture
def mock_cognitive_stack():
stack = {
"dopamine": MagicMock(),
"darwin": MagicMock(),
"resonance": MagicMock(),
"active_inference": MagicMock(),
"growth_brain": MagicMock(),
"swarm": MagicMock(),
"radome": MagicMock(),
"nav_graph": MagicMock(),
"zero_engine": MagicMock(),
"crm": MagicMock(),
"telepathic": MockTelepathicEngine()
}
stack["radome"].sanitize_xml.side_effect = lambda x: x
return stack