"""End-to-end upload pipeline: file bytes → DB rows.""" import pytest from pathlib import Path from app.db.schema import ensure_context_schema from app.glean.doc_upload import glean_upload from app.context.store import list_facts, list_documents from app.context.chunker import UnsupportedDocType @pytest.fixture def db(tmp_path): db_path = tmp_path / "t.db" ensure_context_schema(db_path) return db_path def test_ingest_yaml_creates_facts_and_doc(db): yaml_bytes = b""" services: plex: image: plexinc/pms-docker ports: - "32400:32400" """ result = glean_upload(db, "docker-compose.yml", yaml_bytes) assert result["doc_type"] == "yaml" assert result["facts_written"] >= 1 assert result["chunks_written"] >= 1 docs = list_documents(db) assert len(docs) == 1 assert docs[0].filename == "docker-compose.yml" facts = list_facts(db, category="service") assert any(f.key == "plex" for f in facts) def test_ingest_markdown_no_facts(db): md = b"# Runbook\n\nRestart plex with `systemctl restart plex`." result = glean_upload(db, "runbook.md", md) assert result["doc_type"] == "markdown" assert result["facts_written"] == 0 assert result["chunks_written"] >= 1 def test_ingest_raises_on_bad_type(db): with pytest.raises(UnsupportedDocType): glean_upload(db, "report.pdf", b"data")