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:
45
tests/unit/test_dopamine_engine.py
Normal file
45
tests/unit/test_dopamine_engine.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import pytest
|
||||
import time
|
||||
from GramAddict.core.dopamine_engine import DopamineEngine
|
||||
|
||||
def test_dopamine_engine_wants_to_change_feed():
|
||||
try:
|
||||
engine = DopamineEngine()
|
||||
except Exception as e:
|
||||
pytest.fail(f"DopamineEngine failed to initialize: {e}")
|
||||
|
||||
# Set boredom to trigger threshold
|
||||
engine.boredom = 90.0
|
||||
|
||||
# Assert that the method exists and returns a boolean (probabilistic, so we just check type)
|
||||
result = engine.wants_to_change_feed()
|
||||
assert isinstance(result, bool), "wants_to_change_feed() must return a boolean"
|
||||
|
||||
def test_dopamine_engine_reset_session_clears_boredom():
|
||||
engine = DopamineEngine()
|
||||
|
||||
# Simulate a crashed/burnt out session
|
||||
engine.boredom = 100.0
|
||||
assert engine.is_app_session_over() is True, "Session should be over when boredom is at 100"
|
||||
|
||||
time.sleep(0.1) # small buffer for time
|
||||
old_start = engine.session_start
|
||||
|
||||
# Trigger the fix
|
||||
engine.reset_session()
|
||||
|
||||
# Verify exact state reset
|
||||
assert engine.boredom == 0.0, "Boredom must be reset to 0.0 on a new session"
|
||||
assert engine.session_start > old_start, "Session start time must be updated"
|
||||
assert engine.is_app_session_over() is False, "Session should no longer be over"
|
||||
|
||||
def test_dopamine_engine_wants_to_doomscroll():
|
||||
engine = DopamineEngine()
|
||||
|
||||
engine.boredom = 50.0
|
||||
assert engine.wants_to_doomscroll() is False
|
||||
|
||||
# Trigger doomscroll threshold
|
||||
engine.boredom = 95.0
|
||||
result = engine.wants_to_doomscroll()
|
||||
assert isinstance(result, bool)
|
||||
27
tests/unit/test_is_ad_substring.py
Normal file
27
tests/unit/test_is_ad_substring.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
from GramAddict.core.utils import is_ad
|
||||
|
||||
def test_is_ad_false_positive_abroad():
|
||||
# Simulate an IG node with 'abroad' in the text
|
||||
xml_false_positive = '''<?xml version="1.0"?>
|
||||
<hierarchy>
|
||||
<node resource-id="com.instagram.android:id/secondary_label" text="brunette_abroad" content-desc="" />
|
||||
</hierarchy>'''
|
||||
|
||||
assert not is_ad(xml_false_positive), "Bot flagged 'abroad' as an AD because it contains 'ad'!"
|
||||
|
||||
def test_is_ad_true_positive():
|
||||
xml_true_positive = '''<?xml version="1.0"?>
|
||||
<hierarchy>
|
||||
<node resource-id="com.instagram.android:id/secondary_label" text="Sponsored" content-desc="" />
|
||||
</hierarchy>'''
|
||||
|
||||
assert is_ad(xml_true_positive), "Bot failed to flag 'Sponsored'"
|
||||
|
||||
def test_is_ad_true_positive_ad_word():
|
||||
xml_ad = '''<?xml version="1.0"?>
|
||||
<hierarchy>
|
||||
<node resource-id="com.instagram.android:id/secondary_label" text="Ad" content-desc="" />
|
||||
</hierarchy>'''
|
||||
|
||||
assert is_ad(xml_ad), "Bot failed to flag standalone 'Ad'"
|
||||
Reference in New Issue
Block a user