Add read-only production runtime audit

This commit is contained in:
2026-08-17 11:17:40 +07:00
parent 057d4ed9dc
commit a1de4715a4
106 changed files with 6869 additions and 1782 deletions
@@ -7,6 +7,7 @@ from the real METFORMIN and PARACETAMOL sections in `duocthu_v1`.
from __future__ import annotations
import json
from dataclasses import replace
import pytest
@@ -516,6 +517,43 @@ def test_a_real_negative_verdict_is_still_an_unsupported_claim():
assert metrics.total(GENERATION_REJECTED, reason="request_budget_exhausted") == 0
def test_patient_candidate_list_retries_one_noisy_entailment_rejection():
metrics = InMemoryMetrics()
result = _result()
result = replace(
result,
evidence=(replace(result.evidence[0], drug_id="metformin"),),
)
generator = _Generator(
[
{"claims": [{"drug_id": "metformin", "text": "Người lớn uống 500 mg", "citations": [1]}],
"evidence_sufficient": True},
{"claims": [{"drug_id": "metformin", "text": "Người lớn uống 500 mg", "citations": [1]}],
"evidence_sufficient": True},
],
entailment_payload=[
{"entailed": False, "unsupported": [1]},
{"entailed": True, "unsupported": [], "complete": True},
],
)
service = GroundedAnswerService(_FixedRouting(result), generator, metrics)
grounded = service.answer_from_result(
"Trong các thuốc trên thuốc nào cần lưu ý hơn với bệnh thận?",
result,
list_mode=True,
patient_specific=True,
candidate_drug_ids=("metformin",),
prechecked=True,
)
assert grounded.generated is True
assert grounded.result.decision == EvidenceDecision.ANSWERABLE
assert generator._call == 2
assert generator._entailment_call == 2
assert metrics.total(GENERATION_REJECTED, reason="unsupported_claim") == 0
def test_entailment_check_is_skipped_when_there_are_no_claims():
"""No claims at all (2026-08-10: the structured-claims schema makes a
claim's `text` a required, non-empty field, so the old "answer is