From d5af86008bfe5864f8a841b80efb6d1bcbcefd5d Mon Sep 17 00:00:00 2001 From: soumalya das Date: Sat, 28 Nov 2026 09:20:59 +0530 Subject: [PATCH 1/3] fix: honor cancellation after model download completes --- src/main.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main.rs b/src/main.rs index 852b990..943c405 100644 --- a/src/main.rs +++ b/src/main.rs @@ -888,6 +888,29 @@ fn change_setting(app: &mut App, forward: bool) { fn finish_model_download(app: &mut App, outcome: DownloadOutcome) { match outcome { DownloadOutcome::Ready => { + if app.download_discard { + let result = app + .download_models + .iter() + .find(|model| model.file == app.download_file) + .ok_or_else(|| "downloaded model is no longer in the catalog".to_string()) + .and_then(model::remove_model); + app.download_discard = false; + app.download_paused = false; + match result { + Ok(()) => { + app.download = app::DownloadState::Idle; + app.download_info = "download canceled ยท completed file removed".into(); + app.toast("download canceled", ToastKind::Warn); + } + Err(err) => { + app.download = app::DownloadState::Failed; + app.download_info = err.clone(); + app.set_message(err); + } + } + return; + } app.download = app::DownloadState::Done; app.download_paused = false; app.download_frac = 1.0; From 559f715aaa9847b490e2503f6eb80b0c2c02e0d0 Mon Sep 17 00:00:00 2001 From: soumalya das Date: Sat, 28 Nov 2026 09:22:13 +0530 Subject: [PATCH 2/3] test: allow isolated model cache fixtures --- src/model.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/model.rs b/src/model.rs index 20e1e9e..293c78d 100644 --- a/src/model.rs +++ b/src/model.rs @@ -424,6 +424,11 @@ thread_local! { static TEST_CACHE_DIR: std::cell::RefCell> = const { std::cell::RefCell::new(None) }; } +#[cfg(test)] +pub(crate) fn set_test_cache_dir(dir: Option) { + TEST_CACHE_DIR.with(|cache| *cache.borrow_mut() = dir); +} + /// What a `--model`/saved value can refer to. Keeping the three forms distinct /// is what makes resolution unambiguous: a catalog name is never also treated /// as a path just because a file with that name happens to exist in `$PWD`. From 532e35a334a875bc06c9d3f9eb346364bc4de2b6 Mon Sep 17 00:00:00 2001 From: soumalya das Date: Sat, 28 Nov 2026 09:22:16 +0530 Subject: [PATCH 3/3] test: cover cancellation after model commit --- src/main.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main.rs b/src/main.rs index 943c405..1f7966f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1104,6 +1104,33 @@ mod tests { assert_eq!(failed.unwrap_err(), "decoder failed"); } + #[test] + fn cancel_after_download_commit_removes_the_completed_model() { + let dir = std::env::temp_dir().join(format!("scribe-discard-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + crate::model::set_test_cache_dir(Some(dir.clone())); + + let info = crate::model::find("tiny").unwrap(); + let path = dir.join(info.file); + std::fs::write(&path, b"completed model").unwrap(); + + let mut app = App::new(&crate::cli::Args::default()); + app.download_models = crate::model::CATALOG.to_vec(); + app.download_file = info.file.to_string(); + app.download_discard = true; + app.download_paused = true; + + finish_model_download(&mut app, DownloadOutcome::Ready); + + assert!(!path.exists()); + assert!(!app.download_discard); + assert!(!app.download_paused); + assert_eq!(app.download, app::DownloadState::Idle); + crate::model::set_test_cache_dir(None); + std::fs::remove_dir_all(&dir).unwrap(); + } + #[test] fn terminal_cleanup_continues_after_a_failed_step() { use std::cell::RefCell;