Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ee7d606
fix: address outstanding Sourcery review findings
programmersd21 Nov 28, 2026
c0c9a1f
fix: address outstanding Sourcery review findings
programmersd21 Nov 28, 2026
71dbee4
fix: address outstanding Sourcery review findings
programmersd21 Nov 28, 2026
adcadd2
fix: address outstanding Sourcery review findings
programmersd21 Nov 28, 2026
70c602f
fix: address outstanding Sourcery review findings
programmersd21 Nov 28, 2026
2eaa81b
fix: address outstanding Sourcery review findings
programmersd21 Nov 28, 2026
45dbcb2
fix: accept scoped IPv6 and IPvFuture URL hosts
programmersd21 Nov 28, 2026
35d2fdb
fix: use reader cancellation state consistently
programmersd21 Nov 28, 2026
4509dda
test: clear selected model after discarded download
programmersd21 Nov 28, 2026
de6a9bb
fix: repair URL host validation implementation
programmersd21 Nov 28, 2026
44f69b0
test: cover malformed IPv6 zone and IPvFuture URLs
programmersd21 Nov 28, 2026
8f4f219
test: exercise Windows completion wiring on every platform
programmersd21 Nov 28, 2026
f176f94
fix: preserve successful ingest completion state
programmersd21 Nov 28, 2026
d89084c
fix: only clear the discarded managed model selection
programmersd21 Nov 28, 2026
ae1a082
fix: recognize symlinked cache ancestors
programmersd21 Nov 28, 2026
0fc1a78
fix: avoid marking normally finished jobs cancelled
programmersd21 Nov 28, 2026
6531c3b
test: cover symlinked cache ancestors
programmersd21 Nov 28, 2026
fe5eef5
test: preserve unrelated custom model selection on discard
programmersd21 Nov 28, 2026
02c9c78
test: preserve custom model selection on discard
programmersd21 Nov 28, 2026
3c6766e
fix: compare model selection paths as owned strings
programmersd21 Nov 28, 2026
9f1edb6
fix: report direct-download cleanup failures
programmersd21 Nov 28, 2026
4d60bf1
fix: repair IPvFuture URL regression assertions
programmersd21 Nov 28, 2026
e828e8b
fix: rewrite malformed URL regression test block
programmersd21 Nov 28, 2026
28d4e5c
fix: satisfy formatting and borrow checks
programmersd21 Nov 28, 2026
2e747b5
fix: satisfy formatting and borrow checks
programmersd21 Nov 28, 2026
9f05bc7
fix: satisfy formatting and borrow checks
programmersd21 Nov 28, 2026
6c52dbd
fix: satisfy formatting and borrow checks
programmersd21 Nov 28, 2026
c58cdba
fix: satisfy formatting and borrow checks
programmersd21 Nov 28, 2026
a396f7b
fix: address follow-up Sourcery review findings
programmersd21 Nov 28, 2026
2c20f74
fix: address follow-up Sourcery review findings
programmersd21 Nov 28, 2026
0714d06
fix: address follow-up Sourcery review findings
programmersd21 Nov 28, 2026
37a662f
fix: address follow-up Sourcery review findings
programmersd21 Nov 28, 2026
a42e796
fix: address follow-up Sourcery review findings
programmersd21 Nov 28, 2026
6bc0d11
fix: handle cancellation warnings in all frontends
programmersd21 Nov 28, 2026
0db552b
test: cover transient cache-lock retries
programmersd21 Nov 28, 2026
f0bbab5
fix: surface only cancellation cleanup warnings
programmersd21 Nov 28, 2026
bd34ef2
fix: repair URL validation and UNC detection
programmersd21 Nov 28, 2026
6c43dfe
test: align cache doctor expectation
programmersd21 Nov 28, 2026
ee16580
fix: clean returned audio when temp cleanup fails
programmersd21 Nov 28, 2026
12ae05e
fix: preserve pipeline errors during ingest teardown
programmersd21 Nov 28, 2026
b98ff90
fix: normalize discarded model selection paths
programmersd21 Nov 28, 2026
0cd2532
test: verify ingest drop releases blocked readers
programmersd21 Nov 28, 2026
76bbe6c
test: cover equivalent managed model paths
programmersd21 Nov 28, 2026
0c527b1
fix: restore IPvFuture host predicate
programmersd21 Nov 28, 2026
792338b
style: format cancellation warning handling
programmersd21 Nov 28, 2026
6ee57cf
style: format audio cleanup errors
programmersd21 Nov 28, 2026
cfc5754
style: format cache retry and path test
programmersd21 Nov 28, 2026
80a3d8c
style: format URL and path validation
programmersd21 Nov 28, 2026
d622e30
style: format terminal worker event match
programmersd21 Nov 28, 2026
de5b43d
fix: fail cache checks on inspection errors
programmersd21 Nov 28, 2026
2d66208
fix: handle symlinked selections and longer cache locks
programmersd21 Nov 28, 2026
0f8fe5f
fix: restore valid IPvFuture predicate
programmersd21 Nov 28, 2026
c53278c
test: synchronize ingest backpressure teardown
programmersd21 Nov 28, 2026
dc793f6
fix: compare managed model paths across Windows casing
programmersd21 Nov 28, 2026
69909e4
style: format cache permission test
programmersd21 Nov 28, 2026
bc63bad
style: format symlink discard test
programmersd21 Nov 28, 2026
423fb93
test: serialize shared model cache overrides
programmersd21 Nov 28, 2026
439bbff
fix: satisfy clippy cleanup control flow
programmersd21 Nov 28, 2026
5dbbdd1
style: apply rustfmt to cleanup condition
programmersd21 Nov 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ impl App {
WorkerEventKind::Segment(s) => self.on_segment(s),
WorkerEventKind::Done => self.on_done(),
WorkerEventKind::Cancelled => self.on_cancelled(),
WorkerEventKind::CancelledWithWarning(message) => {
self.on_cancelled_with_warning(message)
}
WorkerEventKind::Error(e) => self.on_error(e),
}
true
Expand Down Expand Up @@ -467,6 +470,12 @@ impl App {
));
}

pub fn on_cancelled_with_warning(&mut self, message: String) {
self.on_cancelled();
self.set_message(format!("cancelled, but cleanup failed: {message}"));
self.overlay = Overlay::Message;
}

pub fn on_error(&mut self, message: String) {
self.settle_pause();
self.status = Status::Error;
Expand Down
124 changes: 113 additions & 11 deletions src/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,36 @@ struct Row {
}

fn cache_status(cache: &std::path::Path) -> (Verdict, &'static str) {
if cache.is_dir() {
(Verdict::Ok, "directory exists; write access not tested")
} else if cache.exists() {
(Verdict::Fail, "path exists but is not a directory")
} else if cache.parent().is_some_and(std::path::Path::is_dir) {
(
Verdict::Warn,
"will be created on first download; write access not tested",
)
let cache = if cache.is_absolute() {
cache.to_path_buf()
} else {
(Verdict::Fail, "parent directory is missing")
match std::env::current_dir() {
Ok(current) => current.join(cache),
Err(_) => return (Verdict::Fail, "cannot resolve relative cache path"),
}
};
if cache.is_dir() {
return (Verdict::Ok, "directory exists; write access not tested");
}
match std::fs::symlink_metadata(&cache) {
Ok(_) => return (Verdict::Fail, "path exists but is not a usable directory"),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
Err(_) => return (Verdict::Fail, "cannot inspect cache path"),
}
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
for ancestor in cache.ancestors().skip(1) {
match std::fs::symlink_metadata(ancestor) {
Ok(metadata) if metadata.is_dir() || ancestor.is_dir() => {
return (
Verdict::Warn,
"will be created on first download; write access not tested",
);
}
Ok(_) => return (Verdict::Fail, "an ancestor is not a directory"),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
Err(_) => return (Verdict::Fail, "cannot inspect cache path"),
}
}
(Verdict::Fail, "no existing parent directory")
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
}

fn version(binary: &std::path::Path, args: &[&str]) -> Option<String> {
Expand Down Expand Up @@ -313,11 +331,95 @@ mod tests {
std::fs::write(&cache, b"not a directory").unwrap();
assert_eq!(
cache_status(&cache),
(Verdict::Fail, "path exists but is not a directory")
(Verdict::Fail, "path exists but is not a usable directory")
);
std::fs::remove_dir_all(&dir).unwrap();
}

#[test]
fn cache_status_rejects_uninspectable_cache_paths() {
let dir = std::env::temp_dir().join(format!(
"scribe-doctor-uninspectable-{}",
std::process::id()
));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let parent = dir.join("not-a-directory");
std::fs::write(&parent, b"x").unwrap();
let cache = parent.join("models");
assert_eq!(
cache_status(&cache),
(Verdict::Fail, "cannot inspect cache path")
);
std::fs::remove_dir_all(&dir).unwrap();
}

#[cfg(unix)]
#[test]
fn cache_status_rejects_dangling_symlinks() {
use std::os::unix::fs::symlink;
let dir = std::env::temp_dir().join(format!("scribe-doctor-link-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let cache = dir.join("models");
symlink(dir.join("missing"), &cache).unwrap();
assert_eq!(
cache_status(&cache),
(Verdict::Fail, "path exists but is not a usable directory")
);
std::fs::remove_file(&cache).unwrap();
std::fs::remove_dir_all(&dir).unwrap();
}

#[test]
fn cache_status_accepts_relative_missing_paths() {
let cache = std::path::PathBuf::from(format!(
"scribe-doctor-relative-{}/nested/models",
std::process::id()
));
assert_eq!(
cache_status(&cache),
(
Verdict::Warn,
"will be created on first download; write access not tested"
)
);
}

#[cfg(unix)]
#[test]
fn cache_status_accepts_symlinked_directory_ancestors() {
use std::os::unix::fs::symlink;
let dir =
std::env::temp_dir().join(format!("scribe-doctor-symlink-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(dir.join("target")).unwrap();
symlink(dir.join("target"), dir.join("linked")).unwrap();
let cache = dir.join("linked").join("nested").join("models");
assert_eq!(
cache_status(&cache),
(
Verdict::Warn,
"will be created on first download; write access not tested"
)
);
std::fs::remove_dir_all(&dir).unwrap();
}

#[test]
fn cache_status_accepts_missing_parent_trees() {
let dir = std::env::temp_dir().join(format!("scribe-doctor-nested-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
assert!(!dir.exists());
let cache = dir.join("one").join("two").join("models");
assert_eq!(
cache_status(&cache),
(
Verdict::Warn,
"will be created on first download; write access not tested"
)
);
}

#[test]
fn verdict_labels_are_short() {
assert_eq!(Verdict::Ok.label(), "ok");
Expand Down
95 changes: 76 additions & 19 deletions src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ async fn fetch_async(url: &str, cancel: &Arc<AtomicBool>) -> Result<FetchedAudio
_ = cancelled(cancel) => None,
};
let Some(crate_result) = crate_result else {
let _ = std::fs::remove_file(&direct);
return Err("cancelled".into());
let cleanup = cleanup_paths(&[&direct]);
return Err(format!("cancelled{}", cleanup_suffix(cleanup)));
};
let path = match crate_result {
Ok(p) if p.is_absolute() => p,
Expand Down Expand Up @@ -187,44 +187,58 @@ async fn fetch_async(url: &str, cancel: &Arc<AtomicBool>) -> Result<FetchedAudio
{
Ok(child) => child,
Err(e) => {
cleanup_fallback(&fallback, &direct);
return Err(format!("could not download audio: {e}"));
let cleanup = cleanup_fallback(&fallback, &direct);
return Err(format!(
"could not download audio: {e}{}",
cleanup_suffix(cleanup)
));
}
};
let status = tokio::select! {
result = child.wait() => match result {
Ok(status) => status,
Err(e) => {
stop_child(&mut child).await;
cleanup_fallback(&fallback, &direct);
return Err(format!("could not download audio: {e}"));
let cleanup = cleanup_fallback(&fallback, &direct);
return Err(format!("could not download audio: {e}{}", cleanup_suffix(cleanup)));
}
},
_ = cancelled(cancel) => {
stop_child(&mut child).await;
cleanup_fallback(&fallback, &direct);
return Err("cancelled".into());
let cleanup = cleanup_fallback(&fallback, &direct);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
return Err(format!("cancelled{}", cleanup_suffix(cleanup)));
}
};
if !status.success() || !fallback.is_file() {
cleanup_fallback(&fallback, &direct);
let cleanup = cleanup_fallback(&fallback, &direct);
return Err(format!(
"no audio came out. the http path said: {crate_err}"
"no audio came out. the http path said: {crate_err}{}",
cleanup_suffix(cleanup)
));
}
fallback
}
};

if cancel.load(Ordering::Relaxed) {
let _ = std::fs::remove_file(&path);
let _ = std::fs::remove_file(&direct);
return Err("cancelled".into());
let cleanup = cleanup_paths(&[&path, &direct]);
return Err(format!("cancelled{}", cleanup_suffix(cleanup)));
}
// the crate may have written to `direct` even when it reported another
// path; keep only the file we actually return.
if direct != path {
let _ = std::fs::remove_file(&direct);
if direct != path
&& let Err(error) = cleanup_paths(&[&direct])
{
let returned_cleanup = cleanup_paths(&[&path]);
let detail = match returned_cleanup {
Ok(()) => error,
Err(returned_error) => {
format!("{error}; returned audio cleanup also failed: {returned_error}")
}
};
return Err(format!(
"audio was downloaded but temporary-file cleanup failed: {detail}"
));
}

Ok(FetchedAudio {
Expand Down Expand Up @@ -272,9 +286,34 @@ pub fn ffmpeg_path() -> Option<PathBuf> {
p.is_file().then_some(p)
}

fn cleanup_fallback(fallback: &Path, direct: &Path) {
let _ = std::fs::remove_file(fallback);
let _ = std::fs::remove_file(direct);
fn cleanup_paths(paths: &[&Path]) -> Result<(), String> {
let mut failures = Vec::new();
for path in paths {
match std::fs::remove_file(path) {
Ok(()) => {}
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
Err(error) => failures.push(format!("{}: {error}", path.display())),
}
}
if failures.is_empty() {
Ok(())
} else {
Err(format!(
"could not remove partial download(s): {}",
failures.join("; ")
))
}
}

fn cleanup_fallback(fallback: &Path, direct: &Path) -> Result<(), String> {
cleanup_paths(&[fallback, direct])
}

fn cleanup_suffix(result: Result<(), String>) -> String {
result
.err()
.map(|error| format!("; {error}"))
.unwrap_or_default()
}

/// remove a partial audio file left behind by a cancelled/interrupted fetch.
Expand Down Expand Up @@ -330,13 +369,31 @@ mod tests {
std::fs::write(&fallback, b"partial").unwrap();
std::fs::write(&direct, b"partial").unwrap();

cleanup_fallback(&fallback, &direct);
cleanup_fallback(&fallback, &direct).unwrap();

assert!(!fallback.exists());
assert!(!direct.exists());
std::fs::remove_dir_all(&dir).unwrap();
}

#[test]
fn fallback_cleanup_reports_filesystem_failures() {
let dir =
std::env::temp_dir().join(format!("scribe-fallback-error-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let fallback = dir.join("fallback.webm");
let direct = dir.join("direct.m4a");
std::fs::create_dir_all(&fallback).unwrap();
std::fs::write(&direct, b"partial").unwrap();

let error = cleanup_fallback(&fallback, &direct).unwrap_err();

assert!(error.contains("fallback.webm"));
assert!(!direct.exists());
std::fs::remove_dir_all(&dir).unwrap();
}

#[test]
fn cleanup_removes_partial_audio() {
let dir = std::env::temp_dir().join(format!("scribe-fetch-{}", std::process::id()));
Expand Down
Loading