fix: implement wipe_all_ai_caches, harden blank_start imports, purge root garbage

- Implement wipe_all_ai_caches() in qdrant_memory.py (was a phantom function
  referenced but never created, causing ERROR on every blank_start)
- Move imports OUT of try/except in bot_flow.py blank_start block so that
  ImportError/NameError crash loudly instead of being silently swallowed
- Add Production Integrity Guard (check_production_integrity) to detect
  MagicMock poisoning at startup
- Add missing TelepathicEngine import in bot_flow.py
- Fix conftest.py: move sys.modules monkeypatching into session fixture
  to prevent global environment poisoning on test import
- Add TDD test test_wipe_all_ai_caches.py proving importability and
  correct wipe behavior across all 8 global Qdrant collections
- Delete root garbage: patch_sae_tests.py, test_debug.py, test_mock.py,
  tmp_bot_flow.py, test_e2e_output*.txt
This commit is contained in:
2026-04-25 21:43:53 +02:00
parent 144d6401b5
commit 42eabb7bda
14 changed files with 170 additions and 57575 deletions

View File

@@ -71,6 +71,7 @@ from GramAddict.core.resonance_engine import ResonanceEngine
from GramAddict.core.sensors.honeypot_radome import HoneypotRadome
from GramAddict.core.session_state import SessionState, SessionStateEncoder
from GramAddict.core.swarm_protocol import SwarmProtocol
from GramAddict.core.telepathic_engine import TelepathicEngine
from GramAddict.core.unfollow_engine import _run_zero_latency_unfollow_loop
from GramAddict.core.utils import (
check_if_updated,
@@ -86,7 +87,53 @@ from GramAddict.core.zero_latency_engine import ZeroLatencyEngine
logger = logging.getLogger(__name__)
def check_production_integrity():
"""
Ensures that the production environment is not poisoned by test mocks.
Fails loudly if critical components are detected as MagicMocks.
"""
import sys
# If we are in a pytest session, we expect and allow mocks
if "pytest" in sys.modules or "PYTEST_CURRENT_TEST" in os.environ:
return
try:
from unittest.mock import MagicMock
# Check QdrantClient
try:
from qdrant_client import QdrantClient
if isinstance(QdrantClient, MagicMock):
print(
f"{Fore.RED}💀 CRITICAL: Production environment poisoned by MagicMock (QdrantClient).{Style.RESET_ALL}"
)
print(
f"{Fore.YELLOW}Verify that tests/e2e/conftest.py is not being loaded. Check sys.modules leakage.{Style.RESET_ALL}"
)
sys.exit(1)
except ImportError:
pass
# Check DeviceFacade (another common victim)
from GramAddict.core.device_facade import DeviceFacade
if isinstance(DeviceFacade, MagicMock):
print(
f"{Fore.RED}💀 CRITICAL: Production environment poisoned by MagicMock (DeviceFacade).{Style.RESET_ALL}"
)
sys.exit(1)
except ImportError:
# unittest.mock might not even be available in some stripped envs
pass
def start_bot(**kwargs):
# 0. Integrity Check
check_production_integrity()
configs = Config(first_run=True, **kwargs)
configure_logger(configs.debug, configs.username)
check_if_updated()
@@ -153,19 +200,23 @@ def start_bot(**kwargs):
if getattr(configs.args, "blank_start", False):
logger.warning(f"⚠️ [Blank Start] Wiping ALL persistent AI memories for '{username}'...")
# 1. Wipe all global AI caches (Heuristics, Screen Types, Navigation Graph, etc.)
try:
from GramAddict.core.qdrant_memory import wipe_all_ai_caches
from GramAddict.core.qdrant_memory import wipe_all_ai_caches
try:
wipe_all_ai_caches()
except (ConnectionError, OSError) as e:
logger.warning(f"⚠️ Failed to wipe global AI caches (Qdrant unreachable): {e}")
except Exception as e:
logger.error(f"⚠️ Failed to wipe global AI caches: {e}")
# 2. Wipe user-specific PathMemory
try:
from GramAddict.core.goap import PathMemory
from GramAddict.core.goap import PathMemory
try:
path_mem = PathMemory(username)
path_mem.wipe()
except (ConnectionError, OSError) as e:
logger.warning(f"⚠️ Failed to wipe user-specific PathMemory (Qdrant unreachable): {e}")
except Exception as e:
logger.warning(f"⚠️ Failed to wipe user-specific PathMemory: {e}")

View File

@@ -1254,3 +1254,32 @@ class ParasocialCRMDB(QdrantBase):
context_parts.append("Previous Comments: " + " | ".join(comments))
return "\n".join(context_parts)
def wipe_all_ai_caches():
"""
Wipes ALL global (non-user-specific) Qdrant AI caches.
Used by blank_start to ensure a completely fresh learning state.
Does NOT wipe user-specific collections like PathMemory or ParasocialCRM.
"""
global_dbs = [
HeuristicMemoryDB,
UIMemoryDB,
CommentMemoryDB,
ContentMemoryDB,
ScreenMemoryDB,
NavigationMemoryDB,
PersonaMemoryDB,
DMMemoryDB,
]
wiped_count = 0
for db_cls in global_dbs:
try:
db = db_cls()
if db.is_connected:
db.wipe_collection()
wiped_count += 1
except Exception as e:
logger.warning(f"⚠️ Failed to wipe {db_cls.__name__}: {e}")
logger.info(f"🗑️ [Blank Start] Wiped {wiped_count}/{len(global_dbs)} global AI caches.")