This commit is contained in:
Your Name
2026-10-23 10:40:43 +08:00
parent e974d3cfa5
commit a3d2d3170d
14 changed files with 1660 additions and 83 deletions
@@ -11,6 +11,7 @@ import pytest
from PySide6.QtCore import QEvent, QTimer
from PySide6.QtWidgets import QApplication
from doctor_workstation.core.errors import ApiBusinessError
from doctor_workstation.ui.dialogs import ai_consult as module
REQUIRED = (
@@ -207,3 +208,140 @@ def test_attachment_progress_does_not_block_first_actual_column_receipt(dialog,
assert "基本信息:无(已提交)" in text and "日常整个页面:已提交" in text
assert "图片附件1(图片):未提交" in text
assert "状态未回报" not in text
def test_actual_file_upload_progress_is_distinct_from_model_submission(dialog):
items = [{"kind": "image", "label": "图片附件1", "status": "uploaded"},
{"kind": "document", "label": "文档附件1", "status": "uploading"}]
emit(dialog, {"event": "progress", "phase": "attachments", "status": "uploading",
"upload_index": 2, "upload_total": 2, "items": items,
"attachment_transfer": "uploaded_files", "required_sections": sections("prepared")})
text = dialog._stream_bubble.transfer_status.text()
assert "正在上传附件(2/2)" in text
assert "图片附件1(图片):已上传,待提交" in text
assert "文档附件1(文档):上传中" in text
assert "生命体征:已整理,待提交" in text
emit(dialog, {"event": "done", "answer": "合成正文", "transfer_manifest_final": True,
"items": [{**item, "status": "submitted"} for item in items],
"attachment_transfer": "uploaded_files", "required_sections": sections()})
assert "图片附件1(图片):已上传并提交" in dialog._stream_bubble.transfer_status.text()
def submitted_images():
return [
{"kind": "image", "label": f"图片附件{index}", "status": "submitted"}
for index in (1, 2)
]
def submit_images(dialog):
emit(dialog, {"event": "progress", "phase": "attachments", "status": "submitted",
"items": submitted_images(), "attachment_count": 2,
"required_sections": sections()})
def fail(dialog, data):
dialog._stream_failed(dialog._generation, dialog._stream_generation, ApiBusinessError(
"合成必需资料提交失败", data=data,
))
def test_failed_progress_without_items_does_not_keep_successful_file_receipts(dialog):
submit_images(dialog)
emit(dialog, {"event": "progress", "phase": "attachments", "status": "failed",
"required_sections": sections("failed")})
text = dialog._stream_bubble.transfer_status.text()
assert "基本信息:无(提交失败)" in text
assert "图片附件1(图片):提交失败" in text
assert "图片附件2(图片):提交失败" in text
assert "引用已提交" not in text
fail(dialog, {"code": "REQUIRED_FILES_REJECTED"})
dialog._stream_finished(dialog._generation, dialog._stream_generation, dialog._stream_worker)
assert "引用已提交" not in dialog._stream_bubble.transfer_status.text()
assert not dialog._asking and not dialog._stream_completed
assert dialog.send_button.isEnabled() and dialog._stream_ended_at is not None
assert dialog._stream_meta["status"] == "failed" and dialog._stream_worker is None
def test_failed_terminal_manifest_corrects_all_observed_receipts_and_keeps_tail(dialog):
submit_images(dialog)
emit(dialog, {"event": "delta", "text": "合成已有正文"})
emit(dialog, {"event": "delta", "text": "未刷新尾段"})
failed_items = [{**item, "status": "failed"} for item in submitted_images()]
fail(dialog, {"code": "REQUIRED_FILES_REJECTED", "transfer_manifest_final": True,
"items": failed_items, "required_sections": sections("failed"),
"attachment_count": 2, "source_summary": {"diagnosis_count": 3}})
text = dialog._stream_bubble.transfer_status.text()
assert "图片附件1(图片):提交失败" in text and "引用已提交" not in text
assert "基本信息:无(提交失败)" in text and "诊单 3 条" in text
assert dialog._stream_meta["source_summary"]["required_sections"] == sections("failed")
assert dialog._stream_bubble._raw_payload.startswith("合成已有正文未刷新尾段")
assert "合成必需资料提交失败" in dialog._stream_bubble._raw_payload
assert not dialog._stream_completed and not dialog._stream_timeout_timer.isActive()
emit(dialog, {"event": "done", "answer": "不得覆盖失败", "required_sections": sections()})
assert "不得覆盖失败" not in dialog._stream_bubble._raw_payload
assert "引用已提交" not in dialog._stream_bubble.transfer_status.text()
@pytest.mark.parametrize("code", ["REQUIRED_FILES_REJECTED", "REQUIRED_FILES_UNSUPPORTED",
"REQUIRED_FILES_INVALID"])
@pytest.mark.parametrize("manifest", [{}, {"items": [], "required_sections": []}])
def test_legacy_required_file_error_without_manifest_fails_known_receipts_only(dialog, code, manifest):
submit_images(dialog)
dialog._stream_meta["items"].append(
{"kind": "document", "label": "文档附件1", "status": "omitted"},
)
fail(dialog, {"code": code, **manifest})
text = dialog._stream_bubble.transfer_status.text()
assert "图片附件1(图片):提交失败" in text and "引用已提交" not in text
assert "文档附件1(文档):未提交" in text
assert "基本信息:无(提交失败)" in text
def test_error_manifest_without_final_marker_can_correct_failed_items(dialog):
submit_images(dialog)
fail(dialog, {"items": [{**item, "status": "failed"} for item in submitted_images()],
"source_summary": {"required_sections": sections("failed")}})
text = dialog._stream_bubble.transfer_status.text()
assert "图片附件1(图片):提交失败" in text and "引用已提交" not in text
assert "基本信息:无(提交失败)" in text
def test_failure_receipt_preserves_explicit_per_item_results(dialog):
submit_images(dialog)
emit(dialog, {"event": "progress", "phase": "attachments", "status": "failed",
"required_sections": sections("failed"),
"items": [{**submitted_images()[0], "status": "failed"},
submitted_images()[1]]})
text = dialog._stream_bubble.transfer_status.text()
assert "图片附件1(图片):提交失败" in text
assert "图片附件2(图片):引用已提交" in text
def test_authoritative_failure_with_empty_manifest_can_replace_previous_items(dialog):
submit_images(dialog)
fail(dialog, {"code": "REQUIRED_FILES_INVALID", "transfer_manifest_final": True,
"items": [], "attachment_count": 0, "required_sections": sections("failed")})
text = dialog._stream_bubble.transfer_status.text()
assert "图片附件" not in text and "本请求附件通道:0 项" in text
assert "基本信息:无(提交失败)" in text
@pytest.mark.parametrize("data", [None, {"code": "UPSTREAM_STREAM_INTERRUPTED"},
{"source_summary": {"required_sections": sections("prepared")},
"items": [], "attachment_count": 0}])
def test_generation_failure_keeps_actual_submitted_receipts(dialog, data):
submit_images(dialog)
fail(dialog, data)
text = dialog._stream_bubble.transfer_status.text()
assert "图片附件1(图片):引用已提交" in text
assert "基本信息:无(已提交)" in text
assert "本请求附件通道:2 项" in text
assert not dialog._stream_completed and not dialog._asking
def test_failure_with_no_manifest_does_not_invent_sources_or_file_items(dialog):
fail(dialog, {"code": "REQUIRED_FILES_REJECTED"})
text = dialog._stream_bubble.transfer_status.text()
assert "资料栏目清单:服务器尚未回传。" in text
assert "图片附件" not in text and "无(提交失败)" not in text