Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
test: add snapshot tests for gh/glab CLI not installed (#780)
Maximilian Roosa9b58b708635
diff --git a/src/git/mr_ref.rs b/src/git/mr_ref.rsindex 71147b8f5..3cfa948d8 100644--- a/src/git/mr_ref.rs+++ b/src/git/mr_ref.rs@@ -104,7 +104,7 @@ pub fn fetch_mr_info(mr_number: u32, repo_root: &std::path::Path) -> anyhow::Res// Check if glab is not installed (OS error for command not found)if e.kind() == ErrorKind::NotFound {bail!(- "GitLab CLI (glab) not installed; install from https://gitlab.com/gitlab-org/cli"+ "GitLab CLI (glab) not installed; install from https://gitlab.com/gitlab-org/cli#installation");}return Err(anyhow::Error::from(e).context("Failed to run glab mr view"));diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex 4f8b72d1d..17ac67604 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -2498,3 +2498,56 @@ fn test_switch_mr_unknown_error(#[from(repo_with_remote)] repo: TestRepo) {assert_cmd_snapshot!("switch_mr_unknown_error", cmd);});}++/// Set up a minimal bin directory with only git (no gh/glab).+///+/// Creates a temporary directory with a symlink to git, excluding gh/glab.+/// Returns the path to use as PATH.+fn setup_minimal_bin_without_cli(repo: &TestRepo) -> std::path::PathBuf {+ let minimal_bin = repo.root_path().join("minimal-bin");+ fs::create_dir_all(&minimal_bin).unwrap();++ // Find git binary using the which crate (cross-platform)+ let git_path = which::which("git").expect("git must be installed to run tests");++ // Symlink git into our minimal bin directory+ #[cfg(unix)]+ std::os::unix::fs::symlink(&git_path, minimal_bin.join("git")).unwrap();+ #[cfg(windows)]+ std::os::windows::fs::symlink_file(&git_path, minimal_bin.join("git.exe")).unwrap();++ minimal_bin+}++/// Configure PATH to exclude gh/glab, keeping only git.+///+/// This simulates the "CLI not installed" scenario.+fn configure_cli_not_installed_env(cmd: &mut std::process::Command, minimal_bin: &Path) {+ cmd.env("PATH", minimal_bin);+}++/// Test pr: when gh CLI is not installed+#[rstest]+fn test_switch_pr_gh_not_installed(#[from(repo_with_remote)] repo: TestRepo) {+ let minimal_bin = setup_minimal_bin_without_cli(&repo);++ let settings = setup_snapshot_settings(&repo);+ settings.bind(|| {+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);+ configure_cli_not_installed_env(&mut cmd, &minimal_bin);+ assert_cmd_snapshot!("switch_pr_gh_not_installed", cmd);+ });+}++/// Test mr: when glab CLI is not installed+#[rstest]+fn test_switch_mr_glab_not_installed(#[from(repo_with_remote)] repo: TestRepo) {+ let minimal_bin = setup_minimal_bin_without_cli(&repo);++ let settings = setup_snapshot_settings(&repo);+ settings.bind(|| {+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["mr:101"], None);+ configure_cli_not_installed_env(&mut cmd, &minimal_bin);+ assert_cmd_snapshot!("switch_mr_glab_not_installed", cmd);+ });+}diff --git a/tests/snapshots/integration__integration_tests__switch__switch_mr_glab_not_installed.snap b/tests/snapshots/integration__integration_tests__switch__switch_mr_glab_not_installed.snapnew file mode 100644index 000000000..ceea464ad--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_mr_glab_not_installed.snap@@ -0,0 +1,39 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "mr:101"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ PATH: "[PATH]"+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ WT_TEST_DELAYED_STREAM_MS: "-1"+ WT_TEST_EPOCH: "1735776000"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching MR !101...[39m+[31m✗[39m [31mGitLab CLI (glab) not installed; install from https://gitlab.com/gitlab-org/cli#installation[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gh_not_installed.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gh_not_installed.snapnew file mode 100644index 000000000..3ccbbb3c8--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gh_not_installed.snap@@ -0,0 +1,39 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "pr:101"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ PATH: "[PATH]"+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ WT_TEST_DELAYED_STREAM_MS: "-1"+ WT_TEST_EPOCH: "1735776000"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching PR #101...[39m+[31m✗[39m [31mGitHub CLI (gh) not installed; install from https://cli.github.com/[39m