82 lines
3.0 KiB
Python
82 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
from doctor_workstation.ui.report_provenance import report_provenance_lines
|
|
|
|
_COMMIT = "db0155dc7c42b9c6b3736896661f317c7110038f"
|
|
_URL = (
|
|
"https://github.com/xiaopangxia/TCM-Ancient-Books/blob/"
|
|
f"{_COMMIT}/123-%E6%B5%8B%E8%AF%95%E5%8F%A4%E7%B1%8D.txt#L42"
|
|
)
|
|
|
|
|
|
def test_recorded_ancient_book_reference_has_title_chapter_and_pinned_line() -> None:
|
|
lines = report_provenance_lines(
|
|
{
|
|
"prompt_version": "patient-longitudinal-report-nihaixia-ancient-v4",
|
|
"ancient_book_sources": [
|
|
{
|
|
"title": "测试古籍",
|
|
"chapter": "消渴篇",
|
|
"path": "123-测试古籍.txt",
|
|
"line": 42,
|
|
"excerpt": "消渴者,当辨其证。",
|
|
"url": _URL,
|
|
"commit": _COMMIT,
|
|
}
|
|
],
|
|
}
|
|
)
|
|
assert any(
|
|
"《测试古籍》「消渴篇」" in line
|
|
and "server/knowledge/tcm-ancient-books/123-测试古籍.txt 第42行" in line
|
|
and "版本 db0155dc7c42" in line
|
|
and "摘录:消渴者,当辨其证。" in line
|
|
for line in lines
|
|
)
|
|
assert "https://github.com" not in "\n".join(lines)
|
|
|
|
|
|
def test_locally_bundled_sources_render_without_external_urls() -> None:
|
|
lines = report_provenance_lines({
|
|
"prompt_version": "patient-longitudinal-report-nihaixia-ancient-v4",
|
|
"knowledge_source": {
|
|
"commit": "270e94e637c4249dc411e54ac6715f21247de3cb",
|
|
"path": "SKILL.md",
|
|
"url": "",
|
|
},
|
|
"ancient_book_sources": [{
|
|
"title": "测试古籍",
|
|
"chapter": "消渴篇",
|
|
"path": "123-测试古籍.txt",
|
|
"line": 42,
|
|
"excerpt": "消渴者,当辨其证。",
|
|
"commit": _COMMIT,
|
|
"url": "",
|
|
}],
|
|
})
|
|
assert any("server/knowledge/nihaixia-skill/SKILL.md" in line for line in lines)
|
|
assert any("server/knowledge/tcm-ancient-books/123-测试古籍.txt 第42行" in line for line in lines)
|
|
assert "https://github.com" not in "\n".join(lines)
|
|
|
|
|
|
def test_ancient_book_reference_rejects_conflicting_local_metadata() -> None:
|
|
lines = report_provenance_lines({
|
|
"ancient_book_sources": [
|
|
{"title": "测试古籍", "path": "别的书.txt", "line": 42, "url": _URL, "commit": _COMMIT},
|
|
{"title": "测试古籍", "path": "123-测试古籍.txt", "line": 43, "url": _URL, "commit": _COMMIT},
|
|
],
|
|
})
|
|
assert all("古籍参考:《" not in line for line in lines)
|
|
|
|
|
|
def test_old_or_unverified_report_does_not_gain_ancient_citation() -> None:
|
|
lines = report_provenance_lines(
|
|
{
|
|
"prompt_version": "patient-longitudinal-report-nihaixia-v3",
|
|
"ancient_book_sources": [
|
|
{"title": "伪造", "url": _URL.replace(_COMMIT, "0" * 40), "commit": _COMMIT}
|
|
],
|
|
}
|
|
)
|
|
assert all("古籍参考:《" not in line for line in lines)
|