M17: ground knowledge and integration evidence

This commit is contained in:
NuklearRabbit
2026-08-10 12:27:17 +02:00
parent 686795a452
commit 8030753dbc
15 changed files with 480 additions and 74 deletions
+63 -6
View File
@@ -107,9 +107,7 @@ def test_demo_provider_grounds_damage_question_in_french():
def test_demo_provider_insufficient_evidence_message_is_localized():
provider = DemoKnowledgeProvider()
nl_answer = provider.ask(
"Wat is de hoofdstad van Frankrijk?", "test-correlation-nl-2", "nl-BE"
)
nl_answer = provider.ask("Wat is de hoofdstad van Frankrijk?", "test-correlation-nl-2", "nl-BE")
fr_answer = provider.ask(
"Quelle est la capitale de la France ?", "test-correlation-fr-2", "fr-BE"
)
@@ -142,9 +140,7 @@ def test_ask_question_is_audited_without_leaking_full_text(ops_client):
"/api/v1/knowledge/questions",
json={"question": "What must I do when a vehicle returns with damage?"},
)
events = ops_client.get(
"/api/v1/audit", params={"action": "knowledge_question_asked"}
).json()
events = ops_client.get("/api/v1/audit", params={"action": "knowledge_question_asked"}).json()
assert len(events) >= 1
metadata = events[0]["metadata"]
assert "evidence_state" in metadata
@@ -288,6 +284,67 @@ def test_ragcore_provider_grounded_answer_maps_citations_to_sources(monkeypatch)
assert source.excerpt
def test_ragcore_sources_deduplicate_reuploaded_versions_and_cap_cards(monkeypatch):
provider = RAGcoreKnowledgeProvider()
monkeypatch.setattr(provider._settings, "ragcore_space_id", "space-1")
citations = []
for index in range(5):
citations.append(
{
"id": f"cite-{index}",
"document_id": f"doc-{index}",
"document_version_id": f"version-{index}",
"title": "Damage procedure" if index < 2 else f"Procedure {index}",
"section": "Return",
"excerpt": (
"Record visible damage before release."
if index < 2
else f"Unique procedure evidence {index}."
),
}
)
monkeypatch.setattr(
provider,
"_client",
lambda: _FakeClient(post_response=_FakeResponse(200, _answers_body(citations=citations))),
)
answer = provider.ask("What must I do about vehicle damage?", "dedupe-test")
assert len(answer.sources) == 3
assert sum(source.title == "Damage procedure" for source in answer.sources) == 1
def test_knowledge_feedback_is_audited_and_can_be_changed(ops_client):
answer = ops_client.post(
"/api/v1/knowledge/questions",
json={"question": "What must I do when a vehicle returns with damage?"},
).json()
payload = {"correlation_id": answer["correlation_id"], "helpful": True}
assert ops_client.post("/api/v1/knowledge/feedback", json=payload).status_code == 200
payload["helpful"] = False
assert ops_client.post("/api/v1/knowledge/feedback", json=payload).status_code == 200
events = ops_client.get(
"/api/v1/audit", params={"action": "knowledge_feedback_recorded"}
).json()
matching = [e for e in events if e["correlation_id"] == answer["correlation_id"]]
assert len(matching) == 1
assert matching[0]["metadata"]["helpful"] is False
def test_knowledge_feedback_cannot_target_another_users_exchange(client):
assert client.post("/api/v1/demo/login", json={"role": "rental_employee"}).status_code == 200
answer = client.post(
"/api/v1/knowledge/questions",
json={"question": "How do I register a vehicle return?"},
).json()
assert client.post("/api/v1/demo/login", json={"role": "operations_manager"}).status_code == 200
response = client.post(
"/api/v1/knowledge/feedback",
json={"correlation_id": answer["correlation_id"], "helpful": True},
)
assert response.status_code == 404
def test_ragcore_provider_not_answerable_is_insufficient_and_never_fabricates(monkeypatch):
provider = RAGcoreKnowledgeProvider()
monkeypatch.setattr(provider._settings, "ragcore_space_id", "space-1")