fix #14740: re-check retention eligibility and validate retention_days
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+149
-9
@@ -10,11 +10,12 @@
|
||||
//! logged, never fatal.
|
||||
|
||||
use std::panic::{self, AssertUnwindSafe};
|
||||
use std::slice;
|
||||
use std::thread;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use chrono::{DateTime, Local};
|
||||
use recorder_core::model::CallId;
|
||||
use recorder_core::model::{Call, CallId};
|
||||
use recorder_core::retention::{plan_retention, RetentionAction};
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
@@ -32,8 +33,10 @@ const WAKE_INTERVAL: Duration = Duration::from_secs(60);
|
||||
pub struct PassReport {
|
||||
pub audio_deleted: Vec<CallId>,
|
||||
pub calls_deleted: Vec<CallId>,
|
||||
/// In use; tried again by the next pass.
|
||||
/// In use or changed since planned; tried again by the next pass.
|
||||
pub skipped: Vec<CallId>,
|
||||
/// Those of `skipped` whose DeepScript jobs are still on record.
|
||||
pub cleanup_pending: Vec<CallId>,
|
||||
pub failed: Vec<CallId>,
|
||||
}
|
||||
|
||||
@@ -99,6 +102,9 @@ fn run(app: &AppHandle) {
|
||||
if !report.calls_deleted.is_empty() {
|
||||
commands::prompt_queue_changed(app);
|
||||
}
|
||||
// As "Verwerfen" does: once their jobs are gone, a later pass can
|
||||
// delete them.
|
||||
processing::delete_leftover_jobs(app, report.cleanup_pending.clone());
|
||||
if !report.is_empty() {
|
||||
log::info!("retention: {}", report.summary());
|
||||
}
|
||||
@@ -107,34 +113,63 @@ fn run(app: &AppHandle) {
|
||||
/// Runs one pass over all calls as of `now`, with the retention period
|
||||
/// currently set.
|
||||
pub fn run_pass(state: &AppState, now: DateTime<Local>) -> PassReport {
|
||||
let mut report = PassReport::default();
|
||||
let calls = match state.store.list_calls() {
|
||||
Ok(calls) => calls,
|
||||
Err(e) => {
|
||||
log::error!("retention: could not list the calls: {e}");
|
||||
return report;
|
||||
return PassReport::default();
|
||||
}
|
||||
};
|
||||
for action in plan_retention(&calls, now, state.settings().retention_days) {
|
||||
let retention_days = state.settings().retention_days;
|
||||
let plan = plan_retention(&calls, now, retention_days);
|
||||
execute(state, &plan, now, retention_days)
|
||||
}
|
||||
|
||||
/// Carries out `plan`, made as of `now` for `retention_days`. Each call is
|
||||
/// planned again from its row as it is when the action runs, while nothing
|
||||
/// else can take it: a call that changed since (e.g. a "Transkribieren"
|
||||
/// that failed meanwhile, so it keeps its audio) is skipped. A call deleted
|
||||
/// meanwhile is ignored.
|
||||
fn execute(
|
||||
state: &AppState,
|
||||
plan: &[RetentionAction],
|
||||
now: DateTime<Local>,
|
||||
retention_days: u32,
|
||||
) -> PassReport {
|
||||
let mut report = PassReport::default();
|
||||
for &action in plan {
|
||||
let still_planned =
|
||||
|call: &Call| plan_retention(slice::from_ref(call), now, retention_days) == [action];
|
||||
match action {
|
||||
RetentionAction::DeleteAudio(id) => match state.delete_audio(id) {
|
||||
RetentionAction::DeleteAudio(id) => match state.delete_audio(id, still_planned) {
|
||||
Ok(()) => report.audio_deleted.push(id),
|
||||
Err(AudioDeleteError::Busy(why)) => {
|
||||
log::info!("retention: call {id}: audio kept for now: {why}");
|
||||
report.skipped.push(id);
|
||||
}
|
||||
Err(AudioDeleteError::NotFound) => {
|
||||
log::info!("retention: call {id}: already deleted");
|
||||
}
|
||||
Err(AudioDeleteError::Failed(e)) => {
|
||||
log::error!("retention: call {id}: audio not deleted: {e}");
|
||||
report.failed.push(id);
|
||||
}
|
||||
},
|
||||
// The same path, and refusals, as "Verwerfen".
|
||||
RetentionAction::DeleteCall(id) => match state.discard_call(id) {
|
||||
RetentionAction::DeleteCall(id) => match state.discard_call_if(id, still_planned) {
|
||||
Ok(_) => report.calls_deleted.push(id),
|
||||
Err(e @ (DiscardError::Busy(_) | DiscardError::CleanupPending)) => {
|
||||
Err(e @ DiscardError::Busy(_)) => {
|
||||
log::info!("retention: call {id}: kept for now: {e}");
|
||||
report.skipped.push(id);
|
||||
}
|
||||
Err(e @ DiscardError::CleanupPending) => {
|
||||
log::info!("retention: call {id}: kept for now: {e}");
|
||||
report.skipped.push(id);
|
||||
report.cleanup_pending.push(id);
|
||||
}
|
||||
Err(DiscardError::NotFound) => {
|
||||
log::info!("retention: call {id}: already deleted");
|
||||
}
|
||||
Err(DiscardError::Other(e)) => {
|
||||
log::error!("retention: call {id}: not deleted: {e}");
|
||||
report.failed.push(id);
|
||||
@@ -249,6 +284,12 @@ mod tests {
|
||||
.record_remote_job(cleanup, "mic", "job-1")
|
||||
.unwrap();
|
||||
let undecided_old_tracks = tracks(&f, undecided_old);
|
||||
let store = &f.state.store;
|
||||
store.set_speaker_name(done_old, "me", "Hauke").unwrap();
|
||||
store
|
||||
.set_speaker_merge(done_old, "remote:2", "remote:1")
|
||||
.unwrap();
|
||||
store.set_title(done_old, Some("Bestellung")).unwrap();
|
||||
|
||||
let report = run_pass(&f.state, now);
|
||||
|
||||
@@ -257,17 +298,36 @@ mod tests {
|
||||
audio_deleted: sorted(report.audio_deleted),
|
||||
calls_deleted: report.calls_deleted,
|
||||
skipped: sorted(report.skipped),
|
||||
cleanup_pending: report.cleanup_pending,
|
||||
failed: report.failed,
|
||||
},
|
||||
PassReport {
|
||||
audio_deleted: vec![done_old],
|
||||
calls_deleted: vec![undecided_old],
|
||||
skipped: sorted(vec![uploading, cleanup]),
|
||||
cleanup_pending: vec![cleanup],
|
||||
failed: vec![],
|
||||
}
|
||||
);
|
||||
assert!(!has_audio(&f, done_old));
|
||||
assert!(f.state.store.get_call(done_old).unwrap().is_some());
|
||||
let kept = store.get_call(done_old).unwrap().unwrap();
|
||||
assert_eq!(kept.title.as_deref(), Some("Bestellung"));
|
||||
assert_eq!(
|
||||
store
|
||||
.speaker_names(done_old)
|
||||
.unwrap()
|
||||
.get("me")
|
||||
.map(String::as_str),
|
||||
Some("Hauke")
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
.speaker_merges(done_old)
|
||||
.unwrap()
|
||||
.get("remote:2")
|
||||
.map(String::as_str),
|
||||
Some("remote:1")
|
||||
);
|
||||
assert_eq!(f.state.store.get_call(undecided_old).unwrap(), None);
|
||||
assert!(undecided_old_tracks.iter().all(|p| !p.exists()));
|
||||
for kept in [done_new, undecided_new, failed_old, uploading, cleanup] {
|
||||
@@ -284,6 +344,85 @@ mod tests {
|
||||
assert!(!has_audio(&f, uploading));
|
||||
}
|
||||
|
||||
/// The plan for the calls as they are now, with 7 days.
|
||||
fn plan(f: &Fixture, now: DateTime<Local>) -> Vec<RetentionAction> {
|
||||
plan_retention(&f.state.store.list_calls().unwrap(), now, 7)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_undecided_call_that_changed_after_planning_is_kept() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let failed = call(&f, "failed", now, 8, None);
|
||||
let processing = call(&f, "processing", now, 8, None);
|
||||
let transcribed = call(&f, "transcribed", now, 8, None);
|
||||
let plan = plan(&f, now);
|
||||
assert_eq!(plan.len(), 3);
|
||||
|
||||
// "Transkribieren" without a key marks the call failed (and lets go
|
||||
// of it) between planning and the delete.
|
||||
let store = &f.state.store;
|
||||
store
|
||||
.set_status(failed, CallStatus::Failed, Some("Kein API-Schlüssel"))
|
||||
.unwrap();
|
||||
store
|
||||
.set_status(processing, CallStatus::Processing, None)
|
||||
.unwrap();
|
||||
store
|
||||
.set_status(transcribed, CallStatus::Done, None)
|
||||
.unwrap();
|
||||
store.mark_transcribed(transcribed, now).unwrap();
|
||||
|
||||
let report = execute(&f.state, &plan, now, 7);
|
||||
assert_eq!(report.calls_deleted, Vec::<CallId>::new());
|
||||
assert_eq!(
|
||||
sorted(report.skipped),
|
||||
sorted(vec![failed, processing, transcribed])
|
||||
);
|
||||
for id in [failed, processing, transcribed] {
|
||||
assert!(has_audio(&f, id), "call {id} keeps its audio");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_transcribed_call_that_changed_after_planning_keeps_its_audio() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let failed = call(&f, "failed", now, 9, Some(8));
|
||||
let undecided = call(&f, "undecided", now, 9, Some(8));
|
||||
let plan = plan(&f, now);
|
||||
assert_eq!(plan.len(), 2);
|
||||
assert!(plan
|
||||
.iter()
|
||||
.all(|action| matches!(action, RetentionAction::DeleteAudio(_))));
|
||||
let store = &f.state.store;
|
||||
store
|
||||
.set_status(failed, CallStatus::Failed, Some("Fehler"))
|
||||
.unwrap();
|
||||
store
|
||||
.set_status(undecided, CallStatus::AwaitingDecision, None)
|
||||
.unwrap();
|
||||
|
||||
let report = execute(&f.state, &plan, now, 7);
|
||||
assert_eq!(report.audio_deleted, Vec::<CallId>::new());
|
||||
assert_eq!(sorted(report.skipped), sorted(vec![failed, undecided]));
|
||||
assert!(has_audio(&f, failed));
|
||||
assert!(has_audio(&f, undecided));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_deleted_after_planning_is_ignored() {
|
||||
let f = fixture();
|
||||
let now = Local::now();
|
||||
let done = call(&f, "done", now, 9, Some(8));
|
||||
let undecided = call(&f, "undecided", now, 8, None);
|
||||
let plan = plan(&f, now);
|
||||
f.state.discard_call(done).unwrap();
|
||||
f.state.discard_call(undecided).unwrap();
|
||||
|
||||
assert_eq!(execute(&f.state, &plan, now, 7), PassReport::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_that_fails_does_not_stop_the_pass() {
|
||||
let f = fixture();
|
||||
@@ -327,6 +466,7 @@ mod tests {
|
||||
audio_deleted: vec![1, 2],
|
||||
calls_deleted: vec![3],
|
||||
skipped: vec![4],
|
||||
cleanup_pending: vec![],
|
||||
failed: vec![],
|
||||
};
|
||||
assert_eq!(
|
||||
|
||||
+176
-27
@@ -42,6 +42,8 @@ const ALREADY_PROCESSING: &str = "Wird bereits verarbeitet";
|
||||
const ALREADY_UPLOADING: &str = "Wird bereits hochgeladen";
|
||||
const BEING_RECORDED: &str = "Das Gespräch wird gerade aufgenommen";
|
||||
const PLAYING: &str = "Das Gespräch wird gerade abgespielt";
|
||||
const CHANGED: &str = "Das Gespräch hat sich inzwischen geändert";
|
||||
const NOT_FOUND: &str = "Gespräch nicht gefunden";
|
||||
|
||||
/// Why [`AppState::discard_call`] refused.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -49,8 +51,10 @@ pub enum DiscardError {
|
||||
/// DeepScript jobs of the call are still on record; their delete has to
|
||||
/// succeed first, or the cascade would forget them.
|
||||
CleanupPending,
|
||||
/// The call is recorded, processed or uploaded right now.
|
||||
/// The call is recorded, processed or uploaded right now, or no longer
|
||||
/// what the caller expected ([`AppState::discard_call_if`]).
|
||||
Busy(&'static str),
|
||||
NotFound,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
@@ -61,6 +65,7 @@ impl std::fmt::Display for DiscardError {
|
||||
"Daten bei DeepScript werden noch gelöscht – bitte später erneut versuchen.",
|
||||
),
|
||||
DiscardError::Busy(msg) => f.write_str(msg),
|
||||
DiscardError::NotFound => f.write_str(NOT_FOUND),
|
||||
DiscardError::Other(msg) => f.write_str(msg),
|
||||
}
|
||||
}
|
||||
@@ -75,8 +80,10 @@ impl From<String> for DiscardError {
|
||||
/// Why [`AppState::delete_audio`] did not delete a call's audio.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum AudioDeleteError {
|
||||
/// The call is in use; the next retention pass tries again.
|
||||
/// The call is in use, or no longer what the caller expected; the next
|
||||
/// retention pass tries again.
|
||||
Busy(&'static str),
|
||||
NotFound,
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
@@ -830,6 +837,17 @@ impl AppState {
|
||||
/// ([`AppState::claim_upload`]), or while its DeepScript jobs are still
|
||||
/// on record ([`DiscardError::CleanupPending`]).
|
||||
pub fn discard_call(&self, id: CallId) -> Result<usize, DiscardError> {
|
||||
self.discard_call_if(id, |_| true)
|
||||
}
|
||||
|
||||
/// Like [`AppState::discard_call`], but only if the call, read while
|
||||
/// nothing else can take it, still passes `still_wanted`; otherwise
|
||||
/// nothing is deleted ([`DiscardError::Busy`]).
|
||||
pub fn discard_call_if(
|
||||
&self,
|
||||
id: CallId,
|
||||
still_wanted: impl FnOnce(&Call) -> bool,
|
||||
) -> Result<usize, DiscardError> {
|
||||
if lock(&self.current)
|
||||
.as_ref()
|
||||
.is_some_and(|cur| cur.call_id == id)
|
||||
@@ -851,10 +869,13 @@ impl AppState {
|
||||
.store
|
||||
.get_call(id)
|
||||
.map_err(|e| e.to_string())?
|
||||
.ok_or_else(|| "Gespräch nicht gefunden".to_string())?;
|
||||
.ok_or(DiscardError::NotFound)?;
|
||||
if call.status == CallStatus::Processing {
|
||||
return Err(DiscardError::Busy(ALREADY_PROCESSING));
|
||||
}
|
||||
if !still_wanted(&call) {
|
||||
return Err(DiscardError::Busy(CHANGED));
|
||||
}
|
||||
let remote_jobs = self.store.remote_jobs(id).map_err(|e| e.to_string())?;
|
||||
if !remote_jobs.is_empty() {
|
||||
return Err(DiscardError::CleanupPending);
|
||||
@@ -893,14 +914,21 @@ impl AppState {
|
||||
Ok(self.prompts_waiting())
|
||||
}
|
||||
|
||||
/// Deletes a call's audio for the retention job: both track files and
|
||||
/// its cached mix, then marks the row (`audio_deleted`). Transcript,
|
||||
/// title, speaker names and merges and the CRM upload stay. Refused
|
||||
/// ([`AudioDeleteError::Busy`]) while the call is recorded, processed
|
||||
/// (or its remote jobs cleaned up), uploaded or a player holds its mix.
|
||||
/// Deletes a transcribed (`Done`) call's audio for the retention job:
|
||||
/// both track files and its cached mix, then marks the row
|
||||
/// (`audio_deleted`). Transcript, title, speaker names and merges and the
|
||||
/// CRM upload stay. Refused ([`AudioDeleteError::Busy`]) while the call
|
||||
/// is recorded, processed (or its remote jobs cleaned up), uploaded or a
|
||||
/// player holds its mix, and unless the row, read while nothing else can
|
||||
/// take the call, is `Done` with its audio not yet deleted and passes
|
||||
/// `still_due`.
|
||||
/// Already missing files are fine; a file that cannot be deleted leaves
|
||||
/// the row unmarked, so the next pass tries again.
|
||||
pub fn delete_audio(&self, id: CallId) -> Result<(), AudioDeleteError> {
|
||||
pub fn delete_audio(
|
||||
&self,
|
||||
id: CallId,
|
||||
still_due: impl FnOnce(&Call) -> bool,
|
||||
) -> Result<(), AudioDeleteError> {
|
||||
if lock(&self.current)
|
||||
.as_ref()
|
||||
.is_some_and(|cur| cur.call_id == id)
|
||||
@@ -922,11 +950,17 @@ impl AppState {
|
||||
if leases.latest.contains_key(&id) {
|
||||
return Err(AudioDeleteError::Busy(PLAYING));
|
||||
}
|
||||
let call = self.find_call(id).map_err(AudioDeleteError::Failed)?;
|
||||
let call = self
|
||||
.store
|
||||
.get_call(id)
|
||||
.map_err(|e| AudioDeleteError::Failed(e.to_string()))?
|
||||
.ok_or(AudioDeleteError::NotFound)?;
|
||||
match call.status {
|
||||
CallStatus::Recording => return Err(AudioDeleteError::Busy(BEING_RECORDED)),
|
||||
CallStatus::Processing => return Err(AudioDeleteError::Busy(ALREADY_PROCESSING)),
|
||||
_ => {}
|
||||
// Failed and undecided calls keep their audio.
|
||||
CallStatus::Done if !call.audio_deleted && still_due(&call) => {}
|
||||
_ => return Err(AudioDeleteError::Busy(CHANGED)),
|
||||
}
|
||||
// Every file is tried, so as little audio as possible stays behind.
|
||||
let mut failed = None;
|
||||
@@ -2240,7 +2274,7 @@ mod tests {
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
let before = f.state.store.get_call(id).unwrap().unwrap();
|
||||
|
||||
assert_eq!(f.state.delete_audio(id), Ok(()));
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
|
||||
let after = f.state.store.get_call(id).unwrap().unwrap();
|
||||
assert!(!before.mic_path.exists());
|
||||
@@ -2265,7 +2299,7 @@ mod tests {
|
||||
fs::remove_file(&call.mic_path).unwrap();
|
||||
fs::remove_file(&call.out_path).unwrap();
|
||||
|
||||
assert_eq!(f.state.delete_audio(id), Ok(()));
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
assert!(f.state.store.get_call(id).unwrap().unwrap().audio_deleted);
|
||||
}
|
||||
|
||||
@@ -2281,12 +2315,12 @@ mod tests {
|
||||
let claim = f.state.claim_upload(id).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id),
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(ALREADY_UPLOADING))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
drop(claim);
|
||||
assert_eq!(f.state.delete_audio(id), Ok(()));
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2296,7 +2330,7 @@ mod tests {
|
||||
// A cleanup of its remote jobs reserves a call of any status.
|
||||
assert!(f.state.reserve_processing(id));
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id),
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(ALREADY_PROCESSING))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
@@ -2307,7 +2341,7 @@ mod tests {
|
||||
.set_status(id, CallStatus::Processing, None)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id),
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(ALREADY_PROCESSING))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
@@ -2327,7 +2361,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id),
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(BEING_RECORDED))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
@@ -2344,14 +2378,14 @@ mod tests {
|
||||
let lease = f.state.prepare_playback(id).unwrap().lease;
|
||||
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id),
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(PLAYING))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
assert!(playback_file(&f, id).exists());
|
||||
|
||||
f.state.release_playback(id, lease);
|
||||
assert_eq!(f.state.delete_audio(id), Ok(()));
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2371,7 +2405,7 @@ mod tests {
|
||||
store.set_status(id, CallStatus::Done, None).unwrap();
|
||||
|
||||
assert!(matches!(
|
||||
f.state.delete_audio(id),
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Failed(_))
|
||||
));
|
||||
assert!(!f.state.store.get_call(id).unwrap().unwrap().audio_deleted);
|
||||
@@ -2379,16 +2413,131 @@ mod tests {
|
||||
assert!(!out.exists());
|
||||
|
||||
fs::remove_dir(&mic).unwrap();
|
||||
assert_eq!(f.state.delete_audio(id), Ok(()));
|
||||
assert_eq!(f.state.delete_audio(id, |_| true), Ok(()));
|
||||
assert!(f.state.store.get_call(id).unwrap().unwrap().audio_deleted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deleting_the_audio_of_an_unknown_call_fails() {
|
||||
fn an_unknown_call_is_not_found() {
|
||||
let f = fixture();
|
||||
assert!(matches!(
|
||||
f.state.delete_audio(999),
|
||||
Err(AudioDeleteError::Failed(_))
|
||||
));
|
||||
assert_eq!(
|
||||
f.state.delete_audio(999, |_| true),
|
||||
Err(AudioDeleteError::NotFound)
|
||||
);
|
||||
assert_eq!(f.state.discard_call(999), Err(DiscardError::NotFound));
|
||||
assert_eq!(
|
||||
DiscardError::NotFound.to_string(),
|
||||
"Gespräch nicht gefunden"
|
||||
);
|
||||
}
|
||||
|
||||
/// A capture source that starts and then delivers nothing.
|
||||
struct SilentSource;
|
||||
|
||||
impl CaptureSource for SilentSource {
|
||||
fn start(
|
||||
&mut self,
|
||||
_on_data: recorder_core::capture::DataCallback,
|
||||
) -> Result<recorder_core::capture::StreamFormat, recorder_core::capture::CaptureError>
|
||||
{
|
||||
Ok(recorder_core::capture::StreamFormat {
|
||||
rate: 16_000,
|
||||
channels: 1,
|
||||
})
|
||||
}
|
||||
|
||||
fn stop(&mut self) {}
|
||||
|
||||
fn failure(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_of_the_running_recording_is_not_deleted() {
|
||||
let f = fixture();
|
||||
// A row that looks deletable: only `current` says it records.
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
let dir = f.dir.path();
|
||||
let recorder = Recorder::start(
|
||||
Box::new(SilentSource),
|
||||
Box::new(SilentSource),
|
||||
&dir.join("live-mic.wav"),
|
||||
&dir.join("live-out.wav"),
|
||||
)
|
||||
.unwrap();
|
||||
*lock(&f.state.current) = Some(CurrentRecording {
|
||||
call_id: id,
|
||||
app: "Microsoft Teams".into(),
|
||||
started_at: at(10, 0, 0),
|
||||
detected: false,
|
||||
recorder,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(BEING_RECORDED))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
lock(&f.state.current).take().unwrap().recorder.discard();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_the_audio_of_a_transcribed_call_is_deleted() {
|
||||
let f = fixture();
|
||||
let (undecided, _, _) = finished_call(&f, "u");
|
||||
let (failed, _, _) = finished_call(&f, "f");
|
||||
f.state
|
||||
.store
|
||||
.set_status(failed, CallStatus::Failed, Some("Fehler"))
|
||||
.unwrap();
|
||||
for id in [undecided, failed] {
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |_| true),
|
||||
Err(AudioDeleteError::Busy(CHANGED))
|
||||
);
|
||||
assert_audio_kept(&f, id);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_the_caller_no_longer_wants_deleted_is_kept() {
|
||||
let f = fixture();
|
||||
let id = transcribed_call_with_audio(&f);
|
||||
let mut seen = None;
|
||||
assert_eq!(
|
||||
f.state.delete_audio(id, |call| {
|
||||
seen = Some(call.id);
|
||||
false
|
||||
}),
|
||||
Err(AudioDeleteError::Busy(CHANGED))
|
||||
);
|
||||
assert_eq!(seen, Some(id));
|
||||
assert_audio_kept(&f, id);
|
||||
assert!(playback_file(&f, id).exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_the_caller_no_longer_wants_deleted_is_kept() {
|
||||
let f = fixture();
|
||||
let (id, mic, out) = finished_call(&f, "a");
|
||||
f.state.queue_prompt(id);
|
||||
|
||||
assert_eq!(
|
||||
f.state
|
||||
.discard_call_if(id, |call| call.status == CallStatus::Failed),
|
||||
Err(DiscardError::Busy(CHANGED))
|
||||
);
|
||||
assert!(mic.exists());
|
||||
assert!(out.exists());
|
||||
assert!(f.state.store.get_call(id).unwrap().is_some());
|
||||
assert_eq!(f.state.prompts_waiting(), 1);
|
||||
|
||||
assert_eq!(
|
||||
f.state
|
||||
.discard_call_if(id, |call| call.status == CallStatus::AwaitingDecision),
|
||||
Ok(0)
|
||||
);
|
||||
assert_eq!(f.state.store.get_call(id).unwrap(), None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user