94 lines
3.3 KiB
Python
94 lines
3.3 KiB
Python
|
|
"""Phase 0 end-to-end pipeline test.
|
||
|
|
|
||
|
|
Runs the actual OntoCast workflow through the FastAPI ``/process`` endpoint
|
||
|
|
with a tiny JSON input. Verifies Acceptance Gate 0 evidence:
|
||
|
|
|
||
|
|
- /health, /info, /process respond OK
|
||
|
|
- ontology + facts Turtle are produced
|
||
|
|
- BudgetTracker reports non-zero LLM call/triple counts
|
||
|
|
- Filesystem TripleStoreManager writes artifacts under working_directory
|
||
|
|
|
||
|
|
Skipped unless ``LLM_API_KEY`` is set (see ``conftest.py``).
|
||
|
|
"""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import importlib
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
from fastapi.testclient import TestClient
|
||
|
|
|
||
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||
|
|
if str(REPO_ROOT) not in sys.path:
|
||
|
|
sys.path.insert(0, str(REPO_ROOT))
|
||
|
|
|
||
|
|
main_module = importlib.import_module("platform.api.main")
|
||
|
|
deps_module = importlib.import_module("platform.api.deps")
|
||
|
|
platform_config = importlib.import_module("platform.config")
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.e2e
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_full_pipeline_writes_ontology_and_facts(
|
||
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||
|
|
) -> None:
|
||
|
|
# Point the working directory at the test's tmp_path so artifacts don't
|
||
|
|
# leak between runs.
|
||
|
|
monkeypatch.setenv("ONTOCAST_WORKING_DIRECTORY", str(tmp_path / "work"))
|
||
|
|
# Honor whatever LLM provider the operator configured.
|
||
|
|
assert os.environ.get("LLM_API_KEY"), "LLM_API_KEY must be set for e2e"
|
||
|
|
|
||
|
|
# Force a fresh AppContext so the new working_directory wins.
|
||
|
|
deps_module.reset_app_context_for_testing()
|
||
|
|
settings = platform_config.load_settings()
|
||
|
|
await deps_module.initialize_app_context(settings, head_chunks=1)
|
||
|
|
|
||
|
|
app = main_module.create_app()
|
||
|
|
|
||
|
|
# Tiny but ontology-rich payload.
|
||
|
|
payload = {
|
||
|
|
"text": (
|
||
|
|
"Alice works at Acme Corporation in Berlin. "
|
||
|
|
"Acme Corporation manufactures bicycles."
|
||
|
|
),
|
||
|
|
"ontology_user_instruction": "Focus on person-organization-location relations.",
|
||
|
|
"facts_user_instruction": "Extract employment and manufacturing facts.",
|
||
|
|
}
|
||
|
|
|
||
|
|
with TestClient(app) as client:
|
||
|
|
# /health & /info first as smoke
|
||
|
|
assert client.get("/health").status_code == 200
|
||
|
|
assert client.get("/info").status_code == 200
|
||
|
|
|
||
|
|
response = client.post(
|
||
|
|
"/process",
|
||
|
|
content=json.dumps(payload),
|
||
|
|
headers={"Content-Type": "application/json"},
|
||
|
|
)
|
||
|
|
|
||
|
|
assert response.status_code == 200, response.text
|
||
|
|
body = response.json()
|
||
|
|
assert body["status"] == "success"
|
||
|
|
assert body["data"]["ontology"], "ontology TTL must not be empty"
|
||
|
|
assert body["data"]["facts"], "facts TTL must not be empty"
|
||
|
|
|
||
|
|
budget = body["metadata"]["budget"]
|
||
|
|
assert budget["calls_count"] > 0, "BudgetTracker must record at least one LLM call"
|
||
|
|
assert (
|
||
|
|
budget["ontology_triples_generated"] > 0
|
||
|
|
or budget["facts_triples_generated"] > 0
|
||
|
|
), "BudgetTracker must record triple generation"
|
||
|
|
|
||
|
|
# The filesystem manager should have created artifacts somewhere under
|
||
|
|
# working_directory. We don't assert exact filenames (those depend on
|
||
|
|
# the document hash) — just that the directory is non-empty.
|
||
|
|
work_dir = tmp_path / "work"
|
||
|
|
written = list(work_dir.rglob("*"))
|
||
|
|
assert any(p.suffix in {".ttl", ".rdf"} for p in written if p.is_file()), (
|
||
|
|
f"No RDF artifacts produced under {work_dir}"
|
||
|
|
)
|