Wire up query history: localStorage session persistence + sidebar UI

This commit is contained in:
2026-08-14 17:44:36 +07:00
parent 9be5819710
commit 057d4ed9dc
23 changed files with 1231 additions and 30 deletions
@@ -227,6 +227,62 @@ def test_list_mode_skips_the_sufficiency_clarify():
assert g.generated is True
def test_list_mode_prepends_a_lookup_not_recommendation_notice_block():
"""Feature-List #14: a condition/symptom -> drug list reads like a
treatment recommendation unless it is explicitly labelled as a lookup.
The notice must be a fixed block the model never writes (so it can't be
reworded or dropped), first in `blocks`, and carry the plan's
`needs_warning` flag so the UI actually renders it set apart."""
result = _answerable(_evidence(0, 100), _evidence(1, 200))
gen = _Generator(
{"claims": [
{"text": "Đoạn bằng chứng 0", "citations": [1]},
{"text": "Đoạn bằng chứng 1", "citations": [2]},
], "evidence_sufficient": True, "clarifying_question": None},
)
service = GroundedAnswerService(_Routing(result), gen)
g = service.answer_from_result("thuốc gì trị sốt", result, list_mode=True)
assert g.blocks[0].title == "Đọc cho đúng"
assert g.blocks[0].kind == "warning"
assert "TRA CỨU" in g.blocks[0].claims[0].text
assert "KHÔNG PHẢI" in g.blocks[0].claims[0].text
assert g.plan is not None and g.plan.needs_warning is True
# The generated claims still follow, untouched, after the fixed notice.
assert len(g.blocks) == 2
def test_single_drug_answer_has_no_list_mode_notice():
"""The notice is specific to `list_mode` (multi-drug reverse lookup) —
an ordinary single-drug attribute answer must not carry it."""
evidence = Evidence(
evidence_id="a__chong_chi_dinh__0",
matched_doc_id="a__chong_chi_dinh__0",
kind="prose",
text="Chống chỉ định của thuốc A.",
score=1.0,
source_refs=(SourceRef(physical_page=100, precision="exact", printed_page=101),),
hydrated_from_parent=False,
requires_visual_check=False,
drug_id="a",
drug_name="A",
section_key="chong_chi_dinh",
)
result = _answerable(evidence)
gen = _Generator({
"claims": [{"text": "Không dùng thuốc A khi mẫn cảm.", "citations": [1]}],
"evidence_sufficient": True,
"clarifying_question": None,
"quick_replies": [],
})
service = GroundedAnswerService(_Routing(result), gen)
g = service.answer_from_result("Chống chỉ định của A?", result, list_mode=False)
assert all(block.title != "Đọc cho đúng" for block in g.blocks)
def test_list_mode_rejects_a_generated_drug_outside_candidate_set():
evidence = Evidence(
evidence_id="a__chi_dinh__0",