Hardened E2E integrity, purged synthetic mocks, and implemented proactive device discovery.

This commit is contained in:
2026-04-29 15:42:03 +02:00
parent 6abb519e3b
commit 0ed12303ac
9 changed files with 442 additions and 65 deletions

View File

@@ -175,11 +175,23 @@ def make_real_device_with_xml(monkeypatch):
def start(self):
pass
class MockTouch:
def __init__(self, parent):
self.parent = parent
def down(self, x, y):
self.parent.interaction_log.append({"action": "click", "coords": (x, y)})
def up(self, x, y):
pass
class MockU2Device:
def __init__(self, xml):
self.xml = xml
self.info = {"sdkInt": 30, "displaySizeDpX": 400, "displayWidth": 1080, "screenOn": True}
self.settings = {}
self.interaction_log = []
self.touch = MockTouch(self)
def dump_hierarchy(self, compressed=False):
if isinstance(self.xml, list):
@@ -188,24 +200,30 @@ def make_real_device_with_xml(monkeypatch):
return self.xml
def screenshot(self):
from PIL import Image
return Image.new("RGB", (1080, 1920), color="black")
return None
def app_current(self):
return {"package": "com.instagram.android"}
def shell(self, cmd):
pass
if isinstance(cmd, str) and cmd.startswith("input tap"):
parts = cmd.split()
try:
x, y = int(parts[-2]), int(parts[-1])
self.interaction_log.append({"action": "click", "coords": (x, y)})
except (ValueError, IndexError):
pass
elif isinstance(cmd, str) and cmd.startswith("input swipe"):
pass # We could log it if needed
def press(self, key):
pass
self.interaction_log.append({"action": "press", "key": key})
def swipe(self, sx, sy, ex, ey, **kwargs):
pass
self.interaction_log.append({"action": "swipe", "start": (sx, sy), "end": (ex, ey)})
def click(self, x, y):
pass
self.interaction_log.append({"action": "click", "coords": (x, y)})
def watcher(self, name):
return MockU2Watcher()
@@ -235,11 +253,6 @@ def make_real_device_with_image(monkeypatch):
import GramAddict.core.device_facade as device_facade
from GramAddict.core.device_facade import DeviceFacade
if isinstance(img_path, str):
img = Image.open(img_path)
else:
img = img_path
class MockU2Watcher:
def when(self, xpath=None, **kwargs):
return self
@@ -250,12 +263,24 @@ def make_real_device_with_image(monkeypatch):
def start(self):
pass
class MockTouch:
def __init__(self, parent):
self.parent = parent
def down(self, x, y):
self.parent.interaction_log.append({"action": "click", "coords": (x, y)})
def up(self, x, y):
pass
class MockU2Device:
def __init__(self, img, xml):
self.img = img
self.xml = xml
self.info = {"sdkInt": 30, "displaySizeDpX": 400, "displayWidth": 1080, "screenOn": True}
self.settings = {}
self.interaction_log = []
self.touch = MockTouch(self)
def dump_hierarchy(self, compressed=False):
if self.xml:
@@ -266,22 +291,33 @@ def make_real_device_with_image(monkeypatch):
return ""
def screenshot(self):
return self.img
if isinstance(self.img, list):
res = self.img.pop(0) if self.img else None
if res is None:
return Image.new("RGB", (1, 1), color="black")
return Image.open(res) if isinstance(res, str) else res
return Image.open(self.img) if isinstance(self.img, str) else self.img
def app_current(self):
return {"package": "com.instagram.android"}
def shell(self, cmd):
pass
if isinstance(cmd, str) and cmd.startswith("input tap"):
parts = cmd.split()
try:
x, y = int(parts[-2]), int(parts[-1])
self.interaction_log.append({"action": "click", "coords": (x, y)})
except (ValueError, IndexError):
pass
def press(self, key):
pass
self.interaction_log.append({"action": "press", "key": key})
def swipe(self, sx, sy, ex, ey, **kwargs):
pass
self.interaction_log.append({"action": "swipe", "start": (sx, sy), "end": (ex, ey)})
def click(self, x, y):
pass
self.interaction_log.append({"action": "click", "coords": (x, y)})
def watcher(self, name):
return MockU2Watcher()
@@ -290,10 +326,9 @@ def make_real_device_with_image(monkeypatch):
pass
def mock_connect(*args, **kwargs):
return MockU2Device(img, xml_content)
return MockU2Device(img_path, xml_content)
monkeypatch.setattr(device_facade.u2, "connect", mock_connect)
device = DeviceFacade("test_device", "com.instagram.android", None)
return device