feat: Add per-case dir oneliner locks

Introduces `OnelinerLocks` to serialize read-modify-write operations on
`oneliner.json`. This prevents race conditions between the manual
override API (`PUT /api/cases/{case_id}/oneliner`) and the transcription
worker's auto-regeneration process.

The manual override now acquires a lock specific to the `case_dir`
before writing. The transcription worker's `update_oneliner` function
also acquires the same lock around its post-LLM re-read-and-write
sequence. This ensures that a doctor's manual edit always takes
precedence, even if it arrives while an auto-regeneration is in
progress.

This change also includes:
- A new `routes::oneliner_override` module for the PUT handler.
- Validation for the oneliner text length and emptiness.
- Integration tests for the override functionality, covering happy path,
  error conditions, early latching, race conditions, and parallel PUTs.
This commit is contained in:
2026-04-26 16:05:01 +02:00
parent 73fa099b51
commit c769abe3d5
17 changed files with 705 additions and 12 deletions
+3
View File
@@ -312,6 +312,7 @@ async fn worker_renames_audio_to_failed_on_permanent_whisper_error() {
busy,
vocab,
doctate_server::events::channel(),
doctate_server::oneliner_locks::OnelinerLocks::new(),
)
.await;
@@ -360,6 +361,7 @@ async fn worker_leaves_m4a_intact_on_transient_whisper_error() {
busy,
vocab,
doctate_server::events::channel(),
doctate_server::oneliner_locks::OnelinerLocks::new(),
)
.await;
@@ -424,6 +426,7 @@ async fn transcribe_worker_normalizes_whisper_output() {
busy,
vocab,
doctate_server::events::channel(),
doctate_server::oneliner_locks::OnelinerLocks::new(),
)
.await;