feat(agent): log answer comments

This commit is contained in:
2026-09-17 00:02:31 +02:00
parent c005b9b306
commit d9c612e354
10 changed files with 241 additions and 55 deletions
+27
View File
@@ -92,6 +92,7 @@ def test_frontend_assets_use_v1_api_and_unknown_assets_are_hidden():
assert styles.status_code == 200
assert 'fetch("/v1/ask"' in script.text
assert 'fetch("/v1/ratings"' in script.text
assert 'fetch("/v1/comments"' in script.text
assert "innerHTML" not in script.text
assert missing.status_code == 404
@@ -202,9 +203,23 @@ def test_v1_rating_is_persisted_for_logged_answer(monkeypatch, tmp_path):
)
assert rating.status_code == 200
assert rating.json()["accepted"] is True
comment = client.post(
"/v1/comments",
json={
"request_id": "rated-answer-1",
"comment": "Bitte diesen Fall ins Goldset aufnehmen.",
},
headers={"Authorization": "Bearer service-secret"},
)
assert comment.status_code == 200
assert comment.json()["comment_id"] > 0
row = app.state.rag.audit.recent()[0]
assert row["rating"] == "up"
assert row["feedback"] == "Hilfreich und nachvollziehbar"
assert row["comments"][0]["comment"] == (
"Bitte diesen Fall ins Goldset aufnehmen."
)
missing = client.post(
"/v1/ratings",
@@ -212,6 +227,18 @@ def test_v1_rating_is_persisted_for_logged_answer(monkeypatch, tmp_path):
headers={"Authorization": "Bearer service-secret"},
)
assert missing.status_code == 404
missing_comment = client.post(
"/v1/comments",
json={"request_id": "missing-answer", "comment": "Nicht vorhanden"},
headers={"Authorization": "Bearer service-secret"},
)
assert missing_comment.status_code == 404
blank_comment = client.post(
"/v1/comments",
json={"request_id": "rated-answer-1", "comment": " "},
headers={"Authorization": "Bearer service-secret"},
)
assert blank_comment.status_code == 422
def test_health_does_not_expose_internal_ollama_url():
+20
View File
@@ -40,6 +40,15 @@ def test_audit_persists_interaction_and_rating(tmp_path):
try:
store.record_interaction(interaction_payload())
store.record_rating("test-request-1", "down", "Quelle war nicht passend")
first_comment_id = store.record_comment(
"test-request-1", "Bitte mit einer anderen Quelle prüfen."
)
second_comment_id = store.record_comment(
"test-request-1", "Der Stand ist für mich besonders wichtig."
)
# Retry mit derselben Request-ID aktualisiert die Interaktion, ohne ihre
# bereits gespeicherten Bewertungen oder Kommentare zu löschen.
store.record_interaction(interaction_payload())
rows = store.recent()
finally:
store.close()
@@ -50,6 +59,11 @@ def test_audit_persists_interaction_and_rating(tmp_path):
assert rows[0]["citations"] == ["lb-min-01"]
assert rows[0]["rating"] == "down"
assert rows[0]["feedback"] == "Quelle war nicht passend"
assert [item["comment_id"] for item in rows[0]["comments"]] == [
first_comment_id,
second_comment_id,
]
assert rows[0]["comments"][0]["comment"].startswith("Bitte mit")
def test_audit_can_omit_free_text_and_still_log_metadata(tmp_path, capsys):
@@ -63,6 +77,7 @@ def test_audit_can_omit_free_text_and_still_log_metadata(tmp_path, capsys):
try:
store.record_interaction(interaction_payload())
store.record_rating("test-request-1", "up", "soll nicht gespeichert werden")
store.record_comment("test-request-1", "auch dieser Kommentar ist privat")
row = store.recent()[0]
finally:
store.close()
@@ -71,10 +86,13 @@ def test_audit_can_omit_free_text_and_still_log_metadata(tmp_path, capsys):
assert row["question"] is None
assert row["answer"] is None
assert row["feedback"] is None
assert row["comments"][0]["comment"] is None
assert "Was gilt?" not in output
assert "soll nicht gespeichert werden" not in output
assert "auch dieser Kommentar ist privat" not in output
assert '"event": "agent_interaction"' in output
assert '"event": "agent_rating"' in output
assert '"event": "agent_comment"' in output
def test_rating_requires_existing_interaction(tmp_path):
@@ -82,6 +100,8 @@ def test_rating_requires_existing_interaction(tmp_path):
try:
with pytest.raises(KeyError):
store.record_rating("missing", "up", None)
with pytest.raises(KeyError):
store.record_comment("missing", "Kommentar")
finally:
store.close()