更新bug
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
@@ -480,6 +481,81 @@ def test_remote_start_call_requires_and_normalizes_current_record_id() -> None:
|
||||
]
|
||||
|
||||
|
||||
def test_remote_call_record_identity_is_reused_for_room_recording_and_end() -> None:
|
||||
"""Room binding and COS finalization must never select a different latest call."""
|
||||
|
||||
client = RecordingClient()
|
||||
repository = RemoteDoctorRepository(client) # type: ignore[arg-type]
|
||||
|
||||
repository.bind_call_room(501, " room-901 ", call_record_id=901)
|
||||
repository.end_call(501, call_record_id=901)
|
||||
|
||||
assert client.post_calls == [
|
||||
(
|
||||
"tcm.diagnosis/bindCallRoom",
|
||||
{"diagnosis_id": 501, "room_id": "room-901", "call_record_id": 901},
|
||||
),
|
||||
(
|
||||
"tcm.diagnosis/endCall",
|
||||
{"diagnosis_id": 501, "call_record_id": 901},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def test_remote_local_audio_upload_keeps_exact_call_identity_and_mime(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
class MultipartClient(RecordingClient):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.multipart_calls: list[
|
||||
tuple[str, dict[str, tuple[str, bytes, str]], dict[str, Any]]
|
||||
] = []
|
||||
|
||||
def post_multipart(
|
||||
self,
|
||||
endpoint: str,
|
||||
*,
|
||||
files: dict[str, tuple[str, bytes, str]],
|
||||
data: dict[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
self.multipart_calls.append((endpoint, files, data))
|
||||
completed = int(data["chunk_index"]) == int(data["chunk_total"]) - 1
|
||||
return {
|
||||
"call_record_id": 901,
|
||||
"completed": completed,
|
||||
"file_url": "https://cos.example.test/calls/local-audio.webm"
|
||||
if completed
|
||||
else "",
|
||||
"media_kind": "local_audio",
|
||||
}
|
||||
|
||||
recording = tmp_path / "local-audio.webm"
|
||||
recording.write_bytes(b"a" * (4 * 1024 * 1024 + 3))
|
||||
client = MultipartClient()
|
||||
repository = RemoteDoctorRepository(client) # type: ignore[arg-type]
|
||||
|
||||
result = repository.upload_call_recording(
|
||||
recording,
|
||||
501,
|
||||
call_record_id=901,
|
||||
mime_type="audio/webm;codecs=opus",
|
||||
)
|
||||
|
||||
assert result["completed"] is True
|
||||
assert result["call_record_id"] == 901
|
||||
assert result["media_kind"] == "local_audio"
|
||||
assert len(client.multipart_calls) == 2
|
||||
assert all(call[0] == "tcm.diagnosis/uploadCallRecording" for call in client.multipart_calls)
|
||||
for _endpoint, files, data in client.multipart_calls:
|
||||
assert data["diagnosis_id"] == 501
|
||||
assert data["call_record_id"] == 901
|
||||
assert data["mime_type"] == "audio/webm;codecs=opus"
|
||||
assert str(data["upload_id"]).startswith("local_audio_")
|
||||
assert files["file"][0] == "local-audio.webm"
|
||||
assert files["file"][2] == "audio/webm;codecs=opus"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"response",
|
||||
[None, {}, {"ok": True}, {"call_record_id": 0}, {"callRecordId": -1}, {"id": True}],
|
||||
@@ -645,6 +721,34 @@ def test_remote_diagnosis_ai_assistant_uses_first_party_endpoint_only() -> None:
|
||||
assert client.timeouts == [105.0]
|
||||
|
||||
|
||||
def test_ai_post_type_error_after_dispatch_is_never_retried() -> None:
|
||||
class FailingAfterDispatchClient:
|
||||
token = "token"
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.calls = 0
|
||||
|
||||
def post(
|
||||
self,
|
||||
endpoint: str,
|
||||
payload: dict[str, Any] | None = None,
|
||||
*,
|
||||
timeout: float | None = None,
|
||||
) -> Any:
|
||||
assert endpoint == "tcm.diagnosis/generatePatientAiReport"
|
||||
assert payload == {"patient_id": 301, "model": "qwen"}
|
||||
assert timeout == 105.0
|
||||
self.calls += 1
|
||||
raise TypeError("transport failed after dispatch")
|
||||
|
||||
client = FailingAfterDispatchClient()
|
||||
|
||||
with pytest.raises(TypeError, match="after dispatch"):
|
||||
RemoteDoctorRepository(client).generate_patient_ai_report(301, model="qwen")
|
||||
|
||||
assert client.calls == 1
|
||||
|
||||
|
||||
def test_remote_diagnosis_ai_stream_normalises_chunks_in_order() -> None:
|
||||
class StreamingClient(RecordingClient):
|
||||
def post_event_stream(self, endpoint: str, payload: dict[str, Any], **kwargs: Any):
|
||||
|
||||
Reference in New Issue
Block a user