更新
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import Any
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtWidgets import QApplication, QLabel
|
||||
from PySide6.QtWidgets import QApplication, QLabel, QTextBrowser
|
||||
|
||||
from doctor_workstation.core import PermissionSet
|
||||
from doctor_workstation.core.errors import ApiTimeoutError
|
||||
@@ -385,7 +385,10 @@ def test_diagnosis_assistant_calls_repository_with_exact_safe_payload(
|
||||
task: str,
|
||||
) -> dict[str, Any]:
|
||||
calls.append({"diagnosis_id": diagnosis_id, "prompt": prompt, "task": task})
|
||||
return {"answer": "建议复核肾功能与眼底。", "model_key": "openai"}
|
||||
return {
|
||||
"answer": "### 核心建议\n\n**重点复核**\n\n- 肾功能\n- 眼底",
|
||||
"model_key": "openai",
|
||||
}
|
||||
|
||||
dialog = DiagnosisAiAssistantDialog(Repository())
|
||||
dialog.open_for(501, "并发症筛查", task="complication_risk")
|
||||
@@ -393,15 +396,57 @@ def test_diagnosis_assistant_calls_repository_with_exact_safe_payload(
|
||||
assert calls == [
|
||||
{"diagnosis_id": 501, "prompt": "并发症筛查", "task": "complication_risk"}
|
||||
]
|
||||
assert dialog.answer_label.text() == "建议复核肾功能与眼底。"
|
||||
assert dialog.answer_label.toPlainText() == "核心建议\n重点复核\n肾功能\n眼底"
|
||||
assert "###" not in dialog.answer_label.toPlainText()
|
||||
assert "**" not in dialog.answer_label.toPlainText()
|
||||
rendered_html = dialog.answer_label.toHtml().lower()
|
||||
assert "<h3" in rendered_html
|
||||
assert "font-weight:700" in rendered_html.replace(" ", "")
|
||||
assert "openai" in dialog.model_label.text()
|
||||
assert dialog.answer_scroll.widget().findChild(QLabel, "PrescriptionAiBody") is dialog.answer_label
|
||||
assert isinstance(dialog.answer_label, QTextBrowser)
|
||||
assert dialog.answer_label.objectName() == "PrescriptionAiAnswer"
|
||||
assert dialog.answer_label.openLinks() is False
|
||||
assert dialog.answer_label.openExternalLinks() is False
|
||||
assert dialog.loading is False
|
||||
assert dialog.retry_button.isEnabled()
|
||||
dialog.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_diagnosis_assistant_markdown_disables_model_supplied_html(
|
||||
application: QApplication,
|
||||
immediate_async: None,
|
||||
) -> None:
|
||||
class Repository:
|
||||
def analyze_diagnosis_ai(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
|
||||
return {
|
||||
"answer": "### 安全内容\n\n<img src=\"https://invalid.example/pixel\">\n\n- 建议复诊",
|
||||
"model_key": "qwen",
|
||||
}
|
||||
|
||||
dialog = DiagnosisAiAssistantDialog(Repository())
|
||||
dialog.open_for(501, "复诊建议", task="custom")
|
||||
|
||||
assert "安全内容" in dialog.answer_label.toPlainText()
|
||||
assert "建议复诊" in dialog.answer_label.toPlainText()
|
||||
assert "<img" in dialog.answer_label.toPlainText()
|
||||
assert 'src="https://invalid.example/pixel"' not in dialog.answer_label.toHtml()
|
||||
assert (
|
||||
dialog.answer_label.loadResource(
|
||||
ai_module.QTextDocument.ResourceType.ImageResource,
|
||||
"https://invalid.example/pixel",
|
||||
)
|
||||
is None
|
||||
)
|
||||
dialog.answer_label.selectAll()
|
||||
copied = dialog.answer_label.createMimeDataFromSelection()
|
||||
assert copied.hasText()
|
||||
assert copied.hasHtml() is False
|
||||
assert set(copied.formats()) == {"text/plain"}
|
||||
dialog.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_diagnosis_assistant_timeout_is_visible_and_retryable(
|
||||
application: QApplication,
|
||||
immediate_async: None,
|
||||
|
||||
Reference in New Issue
Block a user