"""Тесты долговечных сессий и checkpoint-файлов.""" from datetime import UTC, datetime from decimal import Decimal from voice_dictation.core.models import TranscriptionResult from voice_dictation.core.paths import AppPaths from voice_dictation.core.session_store import SessionStore def test_chunk_checkpoint_roundtrip(tmp_paths: AppPaths) -> None: store = SessionStore(tmp_paths.sessions_dir) audio_path = store.create() audio_path.write_bytes(b"audio") store.mark_recorded(audio_path, 12.5) expected = TranscriptionResult( text="полный текст чанка", duration_sec=12.5, model="gpt-4o-mini-transcribe", language="ru", prompt_used="словарь", requested_at=datetime.now(tz=UTC), cost_usd=Decimal("0.00123"), ) store.save_chunk_result(audio_path.parent, 0, expected) actual = store.load_chunk_result(audio_path.parent, 0) assert actual == expected assert store.pending() == [audio_path.parent] def test_completed_session_is_not_pending(tmp_paths: AppPaths) -> None: store = SessionStore(tmp_paths.sessions_dir) audio_path = store.create() audio_path.write_bytes(b"audio") store.mark_recorded(audio_path, 1.0) store.complete(audio_path.parent, "готово", ()) assert store.pending() == [] assert (audio_path.parent / "transcript.txt").read_text(encoding="utf-8") == "готово" def test_interrupted_recording_is_pending_when_wav_exists(tmp_paths: AppPaths) -> None: store = SessionStore(tmp_paths.sessions_dir) audio_path = store.create() audio_path.write_bytes(b"RIFF interrupted audio") assert store.pending() == [audio_path.parent]