Add production condition retrieval smoke test
This commit is contained in:
@@ -21,6 +21,9 @@ MIGRATION = Path(__file__).resolve().parents[1] / "migrations/001_rag_retrieval_
|
||||
CONVERSATION_MIGRATION = (
|
||||
Path(__file__).resolve().parents[1] / "migrations/002_rag_conversation_turn.sql"
|
||||
)
|
||||
FEEDBACK_MIGRATION = (
|
||||
Path(__file__).resolve().parents[1] / "migrations/004_rag_answer_feedback.sql"
|
||||
)
|
||||
|
||||
|
||||
class _PlumbingEmbedder:
|
||||
@@ -134,6 +137,40 @@ def test_real_postgres_migration_insert_and_read_back():
|
||||
assert stored.citations[0]["printed_page_start"] == 101
|
||||
|
||||
|
||||
def test_real_postgres_feedback_upserts_against_a_persisted_trace():
|
||||
from adapters.postgres import PostgresTraceRepository
|
||||
|
||||
repository = PostgresTraceRepository(
|
||||
"postgresql://duoc_thu:duoc_thu@localhost:5432/duoc_thu"
|
||||
)
|
||||
repository.migrate(MIGRATION)
|
||||
repository.migrate(FEEDBACK_MIGRATION)
|
||||
trace_id = repository.save(
|
||||
query="Gút dùng thuốc gì?",
|
||||
subject_scope="human",
|
||||
intent="fact_lookup",
|
||||
decision="answerable",
|
||||
reason="grounded_evidence_available",
|
||||
resolved_drug_id="colchicin",
|
||||
citations=(),
|
||||
)
|
||||
|
||||
first = repository.save_feedback(
|
||||
trace_id=trace_id,
|
||||
rating="helpful",
|
||||
comment=None,
|
||||
conversation_id="feedback-integration",
|
||||
)
|
||||
second = repository.save_feedback(
|
||||
trace_id=trace_id,
|
||||
rating="not_helpful",
|
||||
comment="Thiếu cảnh báo suy thận.",
|
||||
conversation_id="feedback-integration",
|
||||
)
|
||||
|
||||
assert second == first
|
||||
|
||||
|
||||
def test_real_postgres_conversation_store_round_trip():
|
||||
"""F-08's durable conversation history against a real Postgres, not a
|
||||
fake — proves `append`/`recent` actually persist and window correctly,
|
||||
@@ -253,7 +290,12 @@ def test_real_rag_agent_end_to_end_through_the_http_api():
|
||||
resolver = CatalogDrugResolver({record["drug_id"]: {record["drug_name"]}})
|
||||
llm = _FakeJsonLlm(
|
||||
frame_payload={
|
||||
"turn_type": "drug_attribute", "drugs": [record["drug_id"]],
|
||||
# A bare drug name is an overview lookup in this plumbing
|
||||
# test. `drug_attribute` with attribute=None now correctly
|
||||
# asks which monograph section the user wants, so using that
|
||||
# internally-inconsistent frame would only exercise the
|
||||
# clarification guard instead of the real retrieval path.
|
||||
"turn_type": "drug_overview", "drugs": [record["drug_id"]],
|
||||
"unknown_drugs": [], "attribute": None, "population": None,
|
||||
"weight_kg": None, "age_text": None, "indication": None,
|
||||
"needs_clarify": False, "clarify_reason": None,
|
||||
@@ -282,7 +324,7 @@ def test_real_rag_agent_end_to_end_through_the_http_api():
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["decision"] == "answerable"
|
||||
assert body["decision"] == "answerable", body
|
||||
assert body["resolved_drug_id"] == record["drug_id"]
|
||||
assert body["citations"][0]["chunk_id"] == record["chunk_id"]
|
||||
assert body["citations"][0]["printed_page_start"] == (
|
||||
|
||||
Reference in New Issue
Block a user