Files
duocthu/apps/ai-service/tests/test_bootstrap.py
T

39 lines
1.5 KiB
Python

"""`_catalog_names` — the drug names shown to `LlmQueryUnderstander`.
Reproduces a live 2026-08-06 bug: picking the first N aliases alphabetically
could drop a drug's own recognizable name entirely, breaking multi-turn
follow-ups where the drug is no longer restated in the raw turn text (see
`docs/progress-log.md` for the exact failure: "Liều paracetamol cho trẻ em"
-> two clarify rounds -> "Không tìm thấy paracetamol").
"""
from bootstrap import _catalog_names
def test_alphabetically_early_junk_alias_does_not_bury_the_canonical_name():
aliases = {
"paracetamol_acetaminophen": {
"0Frezefev", "ABAB", "Ace kid 80", "PARACETAMOL", "Acetaminophen",
},
}
shown = _catalog_names(aliases)["paracetamol_acetaminophen"]
assert "paracetamol acetaminophen" in shown
def test_canonical_name_is_always_first():
aliases = {"metformin": {"METFORMIN", "Axiol", "Dybis", "Zzyzx"}}
shown = _catalog_names(aliases)["metformin"]
assert shown.split(", ")[0] == "metformin"
def test_drug_with_no_aliases_still_shows_its_canonical_name():
shown = _catalog_names({"some_drug": set()})["some_drug"]
assert shown == "some drug"
def test_output_is_capped_and_does_not_duplicate_the_canonical_name():
aliases = {"drug_x": {f"Brand{i}" for i in range(20)} | {"DRUG X", "drug x"}}
shown = _catalog_names(aliases)["drug_x"].split(", ")
assert shown[0] == "drug x"
assert shown.count("drug x") == 1
assert len(shown) <= 3