"""Ingestion imports do not initialize providers or chat.""" import os import subprocess import sys def test_ingestion_imports_do_not_initialize_chat_or_io(): script = """ import importlib, sys class BlockImports: def find_spec(self, fullname, *args): if fullname.startswith(("app.services", "app.core.config", "openai", "fastembed", "langchain", "chromadb")): raise AssertionError("Forbidden import: " + fullname) sys.meta_path.insert(0, BlockImports()) def audit(event, args): if event in ("socket.connect", "os.walk", "os.scandir"): raise AssertionError("Unexpected I/O: " + event) sys.addaudithook(audit) for name in ("app.modules.documents.settings", "app.modules.documents.types", "app.modules.documents.ports", "app.infrastructure.database", "app.bootstrap"): importlib.import_module(name) assert "app.core.config" not in sys.modules """ environment = {k: v for k, v in os.environ.items() if not k.startswith(("INGEST_", "API_KEY", "LLM_"))} result = subprocess.run([sys.executable, "-c", script], env=environment, capture_output=True, text=True) assert result.returncode == 0, result.stderr