Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(tui): cancel drops pending run start; gate git snapshots to cli
Akarshan Biswas8563fe00e7c7
diff --git a/src-tauri/src/core/agent/git.rs b/src-tauri/src/core/agent/git.rsindex 3d1803029..f60d05d07 100644--- a/src-tauri/src/core/agent/git.rs+++ b/src-tauri/src/core/agent/git.rs@@ -100,7 +100,7 @@ pub(crate) fn snapshot_ref(thread_id: &str) -> String {/// The repository top-level for `path`, or `None` when `path` is not inside a/// git work tree (workspace-restore is unavailable then; the agent still edits/// in place). Also `None` when `git` is not installed.-#[cfg(any(feature = "cli", test))]+#[cfg(feature = "cli")]pub(crate) fn repo_root(path: &Path) -> Option<PathBuf> {let p = path.to_string_lossy();git(&["-C", &p, "rev-parse", "--show-toplevel"])@@ -226,7 +226,7 @@ pub(crate) fn restore(repo: &Path, target: &str, latest: &str) -> Result<(), Strresult}-#[cfg(test)]+#[cfg(all(test, feature = "cli"))]mod tests {use super::*;use std::sync::atomic::Ordering;@@ -236,7 +236,6 @@ mod tests {/// Init a throwaway repo with one commit, or `None` if git is unavailable so/// the suite skips instead of failing on a box without git.- #[cfg(feature = "cli")]fn init_repo() -> Option<PathBuf> {let n = COUNTER.fetch_add(1, Ordering::SeqCst);let root = std::env::temp_dir().join(format!("jan_snap_test_{}_{n}", std::process::id()));@@ -254,7 +253,6 @@ mod tests {repo_root(&root)}- #[cfg(feature = "cli")]#[test]fn snapshot_restore_roundtrip() {let Some(root) = init_repo() else { return };@@ -286,7 +284,6 @@ mod tests {let _ = std::fs::remove_dir_all(&root);}- #[cfg(feature = "cli")]#[test]fn snapshot_is_invisible_to_user_state() {let Some(root) = init_repo() else { return };@@ -301,7 +298,6 @@ mod tests {let _ = std::fs::remove_dir_all(&root);}- #[cfg(feature = "cli")]#[test]fn base_snapshot_picks_up_preexisting_dirty_tracked_file() {let Some(root) = init_repo() else { return };@@ -320,7 +316,6 @@ mod tests {let _ = std::fs::remove_dir_all(&root);}- #[cfg(feature = "cli")]#[test]fn checkpoint_only_stages_reported_paths() {let Some(root) = init_repo() else { return };@@ -351,7 +346,6 @@ mod tests {let _ = std::fs::remove_dir_all(&root);}- #[cfg(feature = "cli")]#[test]fn repo_root_is_none_outside_git() {let n = COUNTER.fetch_add(1, Ordering::SeqCst);diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 2a81e409b..0ecb808c8 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -1534,6 +1534,10 @@ impl App {}self.status = Status::Idle;self.run_started = None;+ // Drop any run queued but not yet spawned (still gated on model/MCP/+ // snapshot readiness); otherwise the loop starts it once ready and the+ // cancel is silently undone.+ self.want_start = false;self.detail = "cancelled".to_string();self.scrollback = 0;self.gap(Kind::Meta);@@ -5639,6 +5643,22 @@ mod tests {assert!(tail.contains("(+10 more)"), "tail: {tail}");}+ #[test]+ fn cancel_clears_pending_run_start() {+ let mut app = test_app();+ // Submit while the run is still gated on model/MCP/snapshot readiness:+ // want_start is armed but no run has spawned yet.+ app.submit_user("do a thing".into());+ assert!(app.want_start, "submit should arm want_start");+ assert_eq!(app.status, Status::Running);+ app.cancel_run();+ assert!(+ !app.want_start,+ "cancel must drop the pending start or the loop re-spawns it"+ );+ assert_eq!(app.status, Status::Idle);+ }+#[test]fn cancel_keeps_streamed_prose_and_tool_calls() {let mut app = test_app();