"""Current-peer archive paging preserves old callers and request identities.""" import pytest from doctor_workstation.services.mock_repository import DemoDoctorRepository from doctor_workstation.services.repository import RemoteDoctorRepository class Client: def __init__(self): self.calls = [] def post(self, endpoint, payload, *, timeout=None): self.calls.append((endpoint, payload, timeout)) return {"completed": False, "sync_token": "a" * 48, "errors": []} def test_sync_optional_parameters_and_timeout_preserve_exact_legacy_payload(): client = Client() repository = RemoteDoctorRepository(client) repository.sync_im_chat_messages(501) result = repository.sync_im_chat_messages(501, scope="current", sync_token="a" * 48) assert client.calls == [ ("tcm.diagnosis/triggerImChatSync", {"diagnosis_id": 501}, 15.0), ("tcm.diagnosis/triggerImChatSync", {"diagnosis_id": 501, "scope": "current", "sync_token": "a" * 48}, 15.0), ] assert result["completed"] is False @pytest.mark.parametrize("kwargs", [{"scope": "other"}, {"sync_token": "bad"}, {"sync_token": None}]) def test_sync_rejects_invalid_options_without_network(kwargs): client = Client() with pytest.raises(ValueError): RemoteDoctorRepository(client).sync_im_chat_messages(501, **kwargs) assert not client.calls def test_mock_sync_supports_paging_contract_and_legacy_receipt(): repository = DemoDoctorRepository() assert repository.sync_im_chat_messages(501)["queued"] is True assert repository.sync_im_chat_messages(501, scope="current")["completed"] is True