Files
rag-technical-docs-assistant/tests/unit/test_imports.py
amirhosein mazaheri ff9c32823c feat(ingestion): add Phase 6 operator tooling, smoke validation, and verification tests
- Add app/ingest.py CLI command for standalone document ingestion
- Add app/ingestion_smoke.py opt-in real-provider smoke test harness with redacted diagnostics
- Add unit and integration tests for Phase 6 operator tooling and audit import coverage
- Update tests/README.md with Phase 5/6 acceptance test results
2026-10-07 16:21:52 +03:30

43 lines
2.2 KiB
Python

"""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", "app.ingest",
"app.infrastructure.file_store",
"app.modules.documents.intake", "app.modules.documents.formats",
"app.modules.documents.errors", "app.modules.documents.extraction_artifacts",
"app.modules.documents.normalization",
"app.modules.documents.extraction", "app.modules.documents.chunking",
"app.modules.documents.processing", "app.infrastructure.gemini_vision",
"app.infrastructure.extraction_candidates",
"app.infrastructure.intake_repository",
"app.modules.documents.embeddings", "app.infrastructure.openai_embeddings",
"app.modules.documents.worker", "app.infrastructure.worker_repository", "app.worker",
"app.modules.documents.review", "app.modules.documents.operational_limits",
"app.infrastructure.review_candidates", "app.infrastructure.review_repository",
"app.ingestion_smoke"):
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