Hardening: Streamlined testing infrastructure, unified toolkit, and established English TDD standards

This commit is contained in:
2026-04-21 10:17:27 +02:00
parent ee3022e95d
commit fff9ec5b0a
9 changed files with 322 additions and 118 deletions

View File

@@ -66,12 +66,6 @@ def start_bot(**kwargs):
prewarm_ollama_models(configs)
except Exception as e:
logger.debug(f"Prewarm failed: {e}")
if getattr(configs.args, "capture_e2e_dumps", False):
device = create_device(configs.device_id, configs.app_id, configs.args)
from GramAddict.core.dump_capturer import capture_all
capture_all(device)
return
sessions = PersistentList("sessions", SessionStateEncoder)
device = create_device(configs.device_id, configs.app_id, configs.args)

View File

@@ -141,7 +141,6 @@ class Config:
self.parser.add_argument("--time-delta-session", help="Time delta between sessions", default=None)
self.parser.add_argument("--restart-atx-agent", action="store_true", help="Restart atx agent")
self.parser.add_argument("--allow-untested-ig-version", action="store_true", help="Allow untested IG version")
self.parser.add_argument("--capture-e2e-dumps", action="store_true", help="Automatically navigate through the app and capture missing XML dumps for the test suite")
# Interaction settings
self.parser.add_argument("--likes-count", help="Likes count", default="2-3")

View File

@@ -1,105 +0,0 @@
import os
import time
import logging
logger = logging.getLogger(__name__)
def capture_all(device):
"""
Automated E2E Dump Capturer Sequence.
Navigates through the Instagram UI and securely saves exact XML representations
to satisfy the `e2e_device_dump_injector` test requirements.
Warning: Requires a logged-in session and active device connection.
"""
logger.info("📸 Initiating E2E Dump Capture Sequence!")
FIX_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "tests", "fixtures")
os.makedirs(FIX_DIR, exist_ok=True)
def _save_dump(filename, description):
logger.info(f"⏳ Waiting for UI to settle for [{description}]...")
time.sleep(3.5) # ensure animations finish
xml_data = device.dump_hierarchy()
path = os.path.join(FIX_DIR, filename)
with open(path, "w", encoding="utf-8") as f:
f.write(xml_data)
logger.info(f"✅ Saved ECHTEN DUMP to {filename}")
print("\n" + "="*50)
print("🤖 MANUAL E2E DUMP CAPTURE SEQUENCE")
print("="*50)
print("Please follow the instructions below to capture the required fixtures.")
print("If an IG update changed the layout, you can navigate there naturally.")
print("="*50 + "\n")
try:
# Pre-condition: Device connected
logger.info("Verifying device connection...")
device.info
# 1. Comment Sheet
input("\n👉 1. COMMENT SHEET:\nOpen Instagram, scroll to any post on the HomeFeed, and open the comment section.\nWhen the comment sheet is fully visible, press ENTER to capture...")
_save_dump("comment_sheet.xml", "Post Comment Sheet")
# 2. Stories Feed
input("\n👉 2. STORIES FEED:\nGo to the HomeFeed and tap any user's story right at the top.\nWhile the story is playing (video/photo is visible), press ENTER to capture...")
_save_dump("stories_feed_dump.xml", "Active Story Playback")
# 3. DM Inbox
input("\n👉 3. DM INBOX:\nGo back to the HomeFeed and tap the message icon in the top right to open your inbox.\nWhen your list of chats is visible, press ENTER to capture...")
_save_dump("dm_inbox_dump.xml", "DM Inbox / Threads List")
# 4. Profile Scraping & Unfollow List
input("\n👉 4. OWN PROFILE:\nGo to your OWN profile by tapping your avatar in the bottom right corner.\nWhen your bio and grid are fully visible, press ENTER to capture...")
_save_dump("scraping_profile_dump.xml", "Own Profile Root (User Info)")
input("\n👉 4.b FOLLOWING LIST:\nFrom your profile, tap your 'Following' (Abonniert) count to open the list of people you follow.\nWhen the list is fully loaded, press ENTER to capture...")
_save_dump("unfollow_list_dump.xml", "Following List Iteration View")
# 5. Search Feed
input("\n👉 5. EXPLORE SEARCH:\nTap the magnifying glass (Explore) tab at the bottom. Then, tap into the top 'Search' bar so your keyboard opens.\nWhen you are in the search state, press ENTER to capture...")
_save_dump("search_feed_dump.xml", "Explore Search Input Focus")
# 6. Reels Feed
input("\n👉 6. REELS FEED:\nTap the Reels (Video) tab at the bottom center. Let a video start playing.\nPress ENTER to capture...")
_save_dump("reels_feed_dump.xml", "Reels Video Feed")
# 7. Notifications
input("\n👉 7. NOTIFICATIONS (ACTIVITY):\nGo to the HomeFeed and tap the Heart icon in the top right to open notifications.\nPress ENTER to capture...")
_save_dump("notifications_dump.xml", "Activity / Notifications tab")
# 8. Explore Grid
input("\n👉 8. EXPLORE GRID:\nTap the magnifying glass (Explore) tab, but do NOT tap the search bar.\nWhen the grid of images/videos is visible, press ENTER to capture...")
_save_dump("explore_feed_dump.xml", "Explore Discovery Grid")
# 9. Other User's Profile
input("\n👉 9. ALIEN PROFILE:\nNavigate to ANY OTHER user's profile (e.g. from your Feed or Search).\nWhen their bio and grid are visible, press ENTER to capture...")
_save_dump("user_profile_dump.xml", "Alien Profile Root")
# 10. Followers List
input("\n👉 10. FOLLOWERS LIST:\nFrom that profile (or your own), tap the 'Followers' (Abonnenten) count.\nWhen the list of followers is visible, press ENTER to capture...")
_save_dump("followers_list_dump.xml", "Followers List Iteration View")
# 11. Carousel Post
input("\n👉 11. CAROUSEL POST:\nScroll your Feed until you see a Carousel (a post with multiple swipable images/videos).\nWhen it is visible, press ENTER to capture...")
_save_dump("carousel_post_dump.xml", "Carousel Post Wrapper")
# 12. Sponsored Post / Ad
input("\n👉 12. SPONSORED AD:\nScroll your Feed or Stories until you see a Sponsored / Gesponsert Post with an action button.\nWhen the Ad is visible, press ENTER to capture...")
_save_dump("home_feed_with_ad.xml", "Sponsored Ad Post")
# 13. Inside DM Chat
input("\n👉 13. DM CHAT THREAD:\nOpen any message thread in your DM inbox.\nWhen the chat messages and text input field are visible, press ENTER to capture...")
_save_dump("dm_thread_dump.xml", "Direct Message Chat Thread")
print("\n" + "="*50)
logger.info("🎉 Capture Sequence Complete! All 13 E2E dumps have been placed into tests/fixtures/")
print("="*50 + "\n")
except KeyboardInterrupt:
print("\n")
logger.info("🛑 Capture Sequence Interrupted by User.")
except Exception as e:
logger.error(f"💥 Capture Sequence crashed: {e}", exc_info=True)