M25: expose provenance-aware knowledge statistics
This commit is contained in:
@@ -5,7 +5,9 @@ from pathlib import Path
|
||||
|
||||
import httpx
|
||||
|
||||
from app.api.routers import knowledge as knowledge_router
|
||||
from app.core.config import get_settings
|
||||
from app.services.knowledge import KnowledgeHealth
|
||||
from app.services.knowledge.demo import DemoKnowledgeProvider
|
||||
from app.services.knowledge.ragcore import RAGcoreKnowledgeProvider
|
||||
|
||||
@@ -73,6 +75,8 @@ def test_demo_provider_health_reports_document_count():
|
||||
assert health.provider == "demo"
|
||||
assert health.available is True
|
||||
assert health.document_count == 11
|
||||
assert health.source_document_count == 11
|
||||
assert health.statistics_state == "verified"
|
||||
|
||||
|
||||
def test_demo_provider_health_reports_document_count_per_language():
|
||||
@@ -154,6 +158,46 @@ def test_knowledge_status_endpoint(ops_client):
|
||||
assert response.json()["provider"] == "demo"
|
||||
|
||||
|
||||
def test_ragcore_status_separates_sync_report_from_unverifiable_index(
|
||||
client, ops_client, monkeypatch
|
||||
):
|
||||
class FakeRagcoreProvider:
|
||||
def health(self, language="en-GB"):
|
||||
return KnowledgeHealth(
|
||||
provider="ragcore",
|
||||
available=True,
|
||||
detail="ready",
|
||||
tenant="fleet-ops",
|
||||
workspace="operations",
|
||||
collection="internal-procedures",
|
||||
document_count=None,
|
||||
source_document_count=11,
|
||||
reported_synced_document_count=None,
|
||||
reported_failed_document_count=None,
|
||||
last_sync_at=None,
|
||||
statistics_state="not_reported",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(knowledge_router, "get_knowledge_provider", FakeRagcoreProvider)
|
||||
settings = get_settings()
|
||||
sync = client.post(
|
||||
"/api/v1/integrations/n8n/procedures-sync-result",
|
||||
json={"execution_id": "rag-statistics-test", "synced": 32, "failed": 1},
|
||||
headers={"X-Service-Token": settings.n8n_callback_token},
|
||||
)
|
||||
assert sync.status_code == 200
|
||||
|
||||
response = ops_client.get("/api/v1/knowledge/status?language=nl-BE")
|
||||
assert response.status_code == 200
|
||||
status = response.json()
|
||||
assert status["document_count"] is None
|
||||
assert status["source_document_count"] == 11
|
||||
assert status["reported_synced_document_count"] == 32
|
||||
assert status["reported_failed_document_count"] == 1
|
||||
assert status["last_sync_at"] is not None
|
||||
assert status["statistics_state"] == "sync_reported"
|
||||
|
||||
|
||||
class _FakeResponse:
|
||||
def __init__(self, status_code: int, body: dict):
|
||||
self.status_code = status_code
|
||||
@@ -224,6 +268,9 @@ def test_ragcore_provider_health_reports_ready_status(monkeypatch):
|
||||
health = provider.health()
|
||||
assert health.provider == "ragcore"
|
||||
assert health.available is True
|
||||
assert health.document_count is None
|
||||
assert health.source_document_count == 11
|
||||
assert health.statistics_state == "not_reported"
|
||||
|
||||
|
||||
def test_ragcore_provider_health_reports_degraded_status(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user