Retain live processing timings across UI reruns
This commit is contained in:
@@ -14,6 +14,7 @@ from mka.application.meeting_service import (
|
||||
ParticipantInput,
|
||||
ProcessingOptions,
|
||||
)
|
||||
from mka.application.progress_timing import ProcessingTimer
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -623,3 +624,111 @@ def test_process_passes_only_active_explicit_glossary_aliases(tmp_path: Path) ->
|
||||
|
||||
assert gateway.config_values is not None
|
||||
assert gateway.config_values["glossary_aliases"] == {"Lumini": "Luminy"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fails", [False, True])
|
||||
def test_process_persists_completed_and_failed_timings(tmp_path: Path, fails: bool) -> None:
|
||||
service, gateway = make_service(tmp_path)
|
||||
gateway.fail = fails
|
||||
values = iter([0.0, 1.0, 9.0, 10.0, 20.0])
|
||||
service.timer = ProcessingTimer(lambda: next(values))
|
||||
audio = tmp_path / "meeting.wav"
|
||||
audio.write_bytes(b"audio")
|
||||
|
||||
outcome = service.process(audio, meeting(), participants(), ProcessingOptions())
|
||||
|
||||
metadata = json.loads((gateway.run_dir / "run_metadata.json").read_text(encoding="utf-8"))
|
||||
assert metadata["timing"] == {
|
||||
"stages_seconds": {"preparing": 8.0, "transcription": 10.0},
|
||||
"total_seconds": 20.0,
|
||||
}
|
||||
assert outcome.succeeded is not fails
|
||||
if fails:
|
||||
assert metadata["failure"]["type"] == "TranscriptionError"
|
||||
|
||||
|
||||
def test_regeneration_starts_fresh_timer_and_retains_final_duration(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
service, gateway = make_service(tmp_path)
|
||||
write_speaker_review_artifacts(gateway.run_dir)
|
||||
clock = SimpleNamespace(value=10.0)
|
||||
service.timer = ProcessingTimer(lambda: clock.value)
|
||||
audio = tmp_path / "meeting.wav"
|
||||
audio.write_bytes(b"audio")
|
||||
service.process(audio, meeting(), participants(), ProcessingOptions())
|
||||
|
||||
clock.value = 100.0
|
||||
observed = []
|
||||
|
||||
def regenerate(run_dir: Path, context: Any, progress_sink: Any, **options: Any) -> Any:
|
||||
progress_sink(
|
||||
SimpleNamespace(
|
||||
stage="protocol_generation",
|
||||
status="started",
|
||||
elapsed_seconds=0.0,
|
||||
progress=None,
|
||||
message=None,
|
||||
)
|
||||
)
|
||||
clock.value = 105.0
|
||||
observed.append(service.timer.snapshot())
|
||||
progress_sink(
|
||||
SimpleNamespace(
|
||||
stage="protocol_generation",
|
||||
status="completed",
|
||||
elapsed_seconds=5.0,
|
||||
progress=None,
|
||||
message=None,
|
||||
)
|
||||
)
|
||||
clock.value = 109.0
|
||||
protocol = run_dir / "protocol.md"
|
||||
protocol.write_text("# Regenerated protocol\n", encoding="utf-8")
|
||||
return SimpleNamespace(run_dir=run_dir, protocol_path=protocol)
|
||||
|
||||
monkeypatch.setattr(gateway, "regenerate_protocol", regenerate)
|
||||
|
||||
service.regenerate_protocol(gateway.run_dir, {"SPEAKER_00": "martin"})
|
||||
final = service.timer.snapshot()
|
||||
|
||||
assert observed[0].active_stage == "protocol_generation"
|
||||
assert observed[0].stage_durations == {"protocol_generation": 5.0}
|
||||
assert observed[0].total_duration == 5.0
|
||||
assert observed[0].running is True
|
||||
assert final.stage_durations == {"protocol_generation": 5.0}
|
||||
assert final.total_duration == 9.0
|
||||
assert final.running is False
|
||||
|
||||
|
||||
def test_failed_regeneration_freezes_active_and_total_durations(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
service, gateway = make_service(tmp_path)
|
||||
write_speaker_review_artifacts(gateway.run_dir)
|
||||
clock = SimpleNamespace(value=20.0)
|
||||
service.timer = ProcessingTimer(lambda: clock.value)
|
||||
|
||||
def fail_regeneration(run_dir: Path, context: Any, progress_sink: Any, **options: Any) -> Any:
|
||||
progress_sink(
|
||||
SimpleNamespace(
|
||||
stage="protocol_generation",
|
||||
status="started",
|
||||
elapsed_seconds=0.0,
|
||||
progress=None,
|
||||
message=None,
|
||||
)
|
||||
)
|
||||
clock.value = 27.0
|
||||
raise RuntimeError("generation failed")
|
||||
|
||||
monkeypatch.setattr(gateway, "regenerate_protocol", fail_regeneration)
|
||||
|
||||
with pytest.raises(RuntimeError, match="generation failed"):
|
||||
service.regenerate_protocol(gateway.run_dir, {})
|
||||
clock.value = 99.0
|
||||
final = service.timer.snapshot()
|
||||
|
||||
assert final.stage_durations == {"protocol_generation": 7.0}
|
||||
assert final.total_duration == 7.0
|
||||
assert final.running is False
|
||||
|
||||
Reference in New Issue
Block a user