Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat(config): add version check to `wt config show --full` (#1011)
Maximilian Roos4acb2d74b6a9
diff --git a/docs/content/config.md b/docs/content/config.mdindex 7ac4460ab..163484ff8 100644--- a/docs/content/config.md+++ b/docs/content/config.md@@ -413,6 +413,7 @@ wt config show --fullThis tests:- **CI tool status** — Whether `gh` (GitHub) or `glab` (GitLab) is installed and authenticated- **Commit generation** — Whether the LLM command can generate commit messages+- **Version check** — Whether a newer version is available on GitHub### Command reference@@ -423,7 +424,7 @@ Usage: <b><span class=c>wt config show</span></b> <span class=c>[OPTIONS]</span><b><span class=g>Options:</span></b><b><span class=c>--full</span></b>- Run diagnostic checks (CI tools, commit generation)+ Run diagnostic checks (CI tools, commit generation, version)<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>Print help (see a summary with '-h')diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.mdindex 73358aa61..6253b7384 100644--- a/skills/worktrunk/reference/config.md+++ b/skills/worktrunk/reference/config.md@@ -403,6 +403,7 @@ wt config show --fullThis tests:- **CI tool status** — Whether `gh` (GitHub) or `glab` (GitLab) is installed and authenticated- **Commit generation** — Whether the LLM command can generate commit messages+- **Version check** — Whether a newer version is available on GitHub### Command reference@@ -412,7 +413,7 @@ Usage: <b><span class=c>wt config show</span></b> <span class=c>[OPTIONS]</span><b><span class=g>Options:</span></b><b><span class=c>--full</span></b>- Run diagnostic checks (CI tools, commit generation)+ Run diagnostic checks (CI tools, commit generation, version)<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>Print help (see a summary with '-h')diff --git a/src/cli/config.rs b/src/cli/config.rsindex 3954ab4a1..2a2493d85 100644--- a/src/cli/config.rs+++ b/src/cli/config.rs@@ -222,10 +222,11 @@ wt config show --fullThis tests:- **CI tool status** — Whether `gh` (GitHub) or `glab` (GitLab) is installed and authenticated-- **Commit generation** — Whether the LLM command can generate commit messages"#+- **Commit generation** — Whether the LLM command can generate commit messages+- **Version check** — Whether a newer version is available on GitHub"#)]Show {- /// Run diagnostic checks (CI tools, commit generation)+ /// Run diagnostic checks (CI tools, commit generation, version)#[arg(long)]full: bool,},diff --git a/src/commands/config/show.rs b/src/commands/config/show.rsindex d8f834b2d..d71c5d5f2 100644--- a/src/commands/config/show.rs+++ b/src/commands/config/show.rs@@ -298,6 +298,9 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {}}+ // Check for newer version on GitHub+ render_version_check(out)?;+// Test commit generation - use effective config for current projectlet config = UserConfig::load()?;let project_id = Repository::current()@@ -307,31 +310,30 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {if !commit_config.is_configured() {writeln!(out, "{}", hint_message("Commit generation not configured"))?;- return Ok(());- }-- let command_display = commit_config.command.as_ref().unwrap().clone();+ } else {+ let command_display = commit_config.command.as_ref().unwrap().clone();- match test_commit_generation(&commit_config) {- Ok(message) => {- writeln!(- out,- "{}",- success_message(cformat!(- "Commit generation working (<bold>{command_display}</>)"- ))- )?;- writeln!(out, "{}", format_with_gutter(&message, None))?;- }- Err(e) => {- writeln!(- out,- "{}",- error_message(cformat!(- "Commit generation failed (<bold>{command_display}</>)"- ))- )?;- writeln!(out, "{}", format_with_gutter(&e.to_string(), None))?;+ match test_commit_generation(&commit_config) {+ Ok(message) => {+ writeln!(+ out,+ "{}",+ success_message(cformat!(+ "Commit generation working (<bold>{command_display}</>)"+ ))+ )?;+ writeln!(out, "{}", format_with_gutter(&message, None))?;+ }+ Err(e) => {+ writeln!(+ out,+ "{}",+ error_message(cformat!(+ "Commit generation failed (<bold>{command_display}</>)"+ ))+ )?;+ writeln!(out, "{}", format_with_gutter(&e.to_string(), None))?;+ }}}@@ -966,6 +968,92 @@ pub(super) fn render_ci_tool_status(Ok(())}+/// Render version update check (fetches from GitHub)+fn render_version_check(out: &mut String) -> anyhow::Result<()> {+ match fetch_latest_version() {+ Ok(latest) => {+ let current = crate::cli::version_str();+ let current_semver = env!("CARGO_PKG_VERSION");+ if is_newer_version(&latest, current_semver) {+ writeln!(+ out,+ "{}",+ info_message(cformat!(+ "Update available: <bold>{latest}</> (current: {current})"+ ))+ )?;+ } else {+ writeln!(+ out,+ "{}",+ success_message(cformat!("Up to date (<bold>{current}</>)"))+ )?;+ }+ }+ Err(e) => {+ log::debug!("Version check failed: {e}");+ writeln!(out, "{}", hint_message("Version check unavailable"))?;+ }+ }+ Ok(())+}++/// Fetch the latest release version from GitHub+fn fetch_latest_version() -> anyhow::Result<String> {+ // Allow tests to inject a version without network access.+ // Set to "error" to simulate a fetch failure.+ if let Ok(version) = std::env::var("WORKTRUNK_TEST_LATEST_VERSION") {+ if version == "error" {+ anyhow::bail!("simulated fetch failure");+ }+ return Ok(version);+ }++ let user_agent = format!(+ "worktrunk/{} (https://worktrunk.dev)",+ env!("CARGO_PKG_VERSION")+ );+ let output = Cmd::new("curl")+ .args([+ "--silent",+ "--fail",+ "--max-time",+ "5",+ "--header",+ &format!("User-Agent: {user_agent}"),+ "https://api.github.com/repos/max-sixty/worktrunk/releases/latest",+ ])+ .run()?;++ if !output.status.success() {+ anyhow::bail!("GitHub API request failed");+ }++ let json: serde_json::Value = serde_json::from_slice(&output.stdout)?;+ let tag = json["tag_name"]+ .as_str()+ .ok_or_else(|| anyhow::anyhow!("missing tag_name in response"))?;++ // Strip leading 'v' prefix (e.g., "v0.23.2" -> "0.23.2")+ Ok(tag.strip_prefix('v').unwrap_or(tag).to_string())+}++/// Compare two semver version strings (e.g., "0.24.0" > "0.23.2")+fn is_newer_version(latest: &str, current: &str) -> bool {+ let parse = |s: &str| -> Option<(u32, u32, u32)> {+ let mut parts = s.splitn(3, '.');+ Some((+ parts.next()?.parse().ok()?,+ parts.next()?.parse().ok()?,+ parts.next()?.parse().ok()?,+ ))+ };+ match (parse(latest), parse(current)) {+ (Some(l), Some(c)) => l > c,+ _ => false,+ }+}+#[cfg(test)]mod tests {use super::*;@@ -980,4 +1068,24 @@ mod tests {assert!(version.chars().next().unwrap().is_ascii_digit());assert!(version.contains('.'));}++ #[test]+ fn test_is_newer_version() {+ // Newer versions+ assert!(is_newer_version("0.24.0", "0.23.2"));+ assert!(is_newer_version("1.0.0", "0.99.99"));+ assert!(is_newer_version("0.23.3", "0.23.2"));+ assert!(is_newer_version("0.23.2", "0.23.1"));++ // Same version+ assert!(!is_newer_version("0.23.2", "0.23.2"));++ // Older versions+ assert!(!is_newer_version("0.23.1", "0.23.2"));+ assert!(!is_newer_version("0.22.0", "0.23.2"));++ // Invalid input+ assert!(!is_newer_version("invalid", "0.23.2"));+ assert!(!is_newer_version("0.23.2", "invalid"));+ }}diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 510dfbca1..180204c4b 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -2712,6 +2712,12 @@ fn setup_snapshot_settings_for_paths_with_home(r"(git: \x1b\[1m)[0-9]+\.[0-9]+\.[0-9]+[^\x1b]*","${1}[VERSION]",);+ // Version check: "Up to date (<bold>VERSION</>)" or "current: VERSION)"+ // version_str() can be: v0.8.5, v0.8.5-2-gabcdef, v0.8.5-dirty, 0.8.5, or bare hash (8465a1f)+ settings.add_filter(+ r"(current: |Up to date \(\x1b\[1m)(?:v?[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9]+-g[0-9a-f]+)?(?:-dirty)?|[0-9a-f]{7,40})",+ "${1}[VERSION]",+ );// Normalize project root paths in "Binary invoked as:" debug output// Tests run cargo which produces paths like /path/to/worktrunk/target/debug/wtdiff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex 41d9261f1..343543dd5 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -652,6 +652,8 @@ fn test_config_show_full_not_configured(mut repo: TestRepo, temp_home: TempDir)repo.configure_mock_commands(&mut cmd);// Override WORKTRUNK_CONFIG_PATH to point to our test configcmd.env("WORKTRUNK_CONFIG_PATH", &config_path);+ // Inject current version for deterministic version check output+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"));cmd.arg("config").arg("show").arg("--full")@@ -688,6 +690,72 @@ command = "nonexistent-llm-command-12345 -m test-model"repo.configure_mock_commands(&mut cmd);// Override WORKTRUNK_CONFIG_PATH to point to our test configcmd.env("WORKTRUNK_CONFIG_PATH", &config_path);+ // Inject current version for deterministic version check output+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"));+ cmd.arg("config")+ .arg("show")+ .arg("--full")+ .current_dir(repo.root_path());+ set_temp_home_env(&mut cmd, temp_home.path());++ assert_cmd_snapshot!(cmd);+ });+}++#[rstest]+fn test_config_show_full_update_available(mut repo: TestRepo, temp_home: TempDir) {+ // Setup mock gh/glab for deterministic BINARIES output+ repo.setup_mock_ci_tools_unauthenticated();++ // Create isolated config directory+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");+ fs::create_dir_all(&global_config_dir).unwrap();+ let config_path = global_config_dir.join("config.toml");+ fs::write(+ &config_path,+ "worktree-path = \"../{{ repo }}.{{ branch }}\"",+ )+ .unwrap();++ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);+ settings.bind(|| {+ let mut cmd = wt_command();+ repo.configure_wt_cmd(&mut cmd);+ repo.configure_mock_commands(&mut cmd);+ cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);+ // Inject a higher version to trigger update-available message+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", "99.0.0");+ cmd.arg("config")+ .arg("show")+ .arg("--full")+ .current_dir(repo.root_path());+ set_temp_home_env(&mut cmd, temp_home.path());++ assert_cmd_snapshot!(cmd);+ });+}++#[rstest]+fn test_config_show_full_version_check_unavailable(mut repo: TestRepo, temp_home: TempDir) {+ repo.setup_mock_ci_tools_unauthenticated();++ let global_config_dir = temp_home.path().join(".config").join("worktrunk");+ fs::create_dir_all(&global_config_dir).unwrap();+ let config_path = global_config_dir.join("config.toml");+ fs::write(+ &config_path,+ "worktree-path = \"../{{ repo }}.{{ branch }}\"",+ )+ .unwrap();++ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);+ settings.bind(|| {+ let mut cmd = wt_command();+ repo.configure_wt_cmd(&mut cmd);+ repo.configure_mock_commands(&mut cmd);+ cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);+ // Simulate a fetch failure+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", "error");cmd.arg("config").arg("show").arg("--full")diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snapindex f4f1f451e..86bd25648 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap@@ -14,6 +14,7 @@ info: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@@ -27,6 +28,7 @@ info:USERPROFILE: "[TEST_HOME]"WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_LATEST_VERSION: 0.23.2WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"WT_TEST_DELAYED_STREAM_MS: "-1"@@ -60,6 +62,7 @@ exit_code: 0[36mDIAGNOSTICS[39m[2m↳[22m [2mCI status requires GitHub or GitLab remote[22m+[32m✓[39m [32mUp to date ([1m[VERSION][22m)[39m[31m✗[39m [31mCommit generation failed ([1mnonexistent-llm-command-12345 -m test-model[22m)[39m[107m [0m [31m✗[39m [31mCommit generation command failed[39m[107m [0m [107m [0m sh: nonexistent-llm-command-12345: command not founddiff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snapindex 2f5ca3e36..22138a0d5 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap@@ -14,6 +14,7 @@ info: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@@ -27,6 +28,7 @@ info:USERPROFILE: "[TEST_HOME]"WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_LATEST_VERSION: 0.23.2WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"WT_TEST_DELAYED_STREAM_MS: "-1"@@ -57,6 +59,7 @@ exit_code: 0[36mDIAGNOSTICS[39m[2m↳[22m [2mCI status requires GitHub or GitLab remote[22m+[32m✓[39m [32mUp to date ([1m[VERSION][22m)[39m[2m↳[22m [2mCommit generation not configured[22m[36mOTHER[39mdiff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_update_available.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_update_available.snapnew file mode 100644index 000000000..b9356aec6--- /dev/null+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_update_available.snap@@ -0,0 +1,68 @@+---+source: tests/integration_tests/config_show.rs+info:+ program: wt+ args:+ - config+ - show+ - "--full"+ 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]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_LATEST_VERSION: 99.0.0+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ WT_TEST_DELAYED_STREAM_MS: "-1"+ WT_TEST_EPOCH: "1735776000"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36mUSER CONFIG[39m ~/.config/worktrunk/config.toml+[107m [0m worktree-path = [32m"../{{ repo }}.{{ branch }}"++[36mPROJECT CONFIG[39m _REPO_/.config/wt.toml+[2m↳[22m [2mNot found[22m++[36mSHELL INTEGRATION[39m+[33m▲[39m [33mShell integration not active[39m+[107m [0m Invoked as: [1m[PROJECT_ROOT]/target/debug/wt[22m++[2m○[22m [2mbash: Skipped; ~/.bashrc not found[22m+[2m○[22m [2mzsh: Skipped; ~/.zshrc not found[22m+[2m○[22m [2mfish: Skipped; ~/.config/fish/functions not found[22m++[36mCLAUDE CODE[39m+[2m○[22m [1mclaude[22m CLI not installed++[36mDIAGNOSTICS[39m+[2m↳[22m [2mCI status requires GitHub or GitLab remote[22m+[2m○[22m Update available: [1m99.0.0[22m (current: [VERSION])+[2m↳[22m [2mCommit generation not configured[22m++[36mOTHER[39m+[2m○[22m wt: [1m[VERSION][22m+[2m○[22m git: [1m[VERSION][22m+[2m○[22m Hyperlinks: [1minactive[22mdiff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_version_check_unavailable.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_version_check_unavailable.snapnew file mode 100644index 000000000..9cee66d5c--- /dev/null+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_version_check_unavailable.snap@@ -0,0 +1,68 @@+---+source: tests/integration_tests/config_show.rs+info:+ program: wt+ args:+ - config+ - show+ - "--full"+ 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]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_LATEST_VERSION: error+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ WT_TEST_DELAYED_STREAM_MS: "-1"+ WT_TEST_EPOCH: "1735776000"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36mUSER CONFIG[39m ~/.config/worktrunk/config.toml+[107m [0m worktree-path = [32m"../{{ repo }}.{{ branch }}"++[36mPROJECT CONFIG[39m _REPO_/.config/wt.toml+[2m↳[22m [2mNot found[22m++[36mSHELL INTEGRATION[39m+[33m▲[39m [33mShell integration not active[39m+[107m [0m Invoked as: [1m[PROJECT_ROOT]/target/debug/wt[22m++[2m○[22m [2mbash: Skipped; ~/.bashrc not found[22m+[2m○[22m [2mzsh: Skipped; ~/.zshrc not found[22m+[2m○[22m [2mfish: Skipped; ~/.config/fish/functions not found[22m++[36mCLAUDE CODE[39m+[2m○[22m [1mclaude[22m CLI not installed++[36mDIAGNOSTICS[39m+[2m↳[22m [2mCI status requires GitHub or GitLab remote[22m+[2m↳[22m [2mVersion check unavailable[22m+[2m↳[22m [2mCommit generation not configured[22m++[36mOTHER[39m+[2m○[22m wt: [1m[VERSION][22m+[2m○[22m git: [1m[VERSION][22m+[2m○[22m Hyperlinks: [1minactive[22mdiff --git a/tests/snapshots/integration__integration_tests__help__help_config_show.snap b/tests/snapshots/integration__integration_tests__help__help_config_show.snapindex b2d487e40..d4c7947fe 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_show.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_show.snap@@ -9,6 +9,7 @@ info:env:CLICOLOR_FORCE: "1"COLUMNS: "500"+ GIT_EDITOR: ""LANG: CLC_ALL: CPSModulePath: ""@@ -33,7 +34,7 @@ Usage: [1m[36mwt config show[0m [36m[OPTIONS][0m[1m[32mOptions:[0m[1m[36m--full[0m- Run diagnostic checks (CI tools, commit generation)+ Run diagnostic checks (CI tools, commit generation, version)[1m[36m-h[0m, [1m[36m--help[0mPrint help (see a summary with '-h')@@ -62,3 +63,4 @@ Use [2m--full[0m to run diagnostic checks:This tests:- [1mCI tool status[0m — Whether [2mgh[0m (GitHub) or [2mglab[0m (GitLab) is installed and authenticated- [1mCommit generation[0m — Whether the LLM command can generate commit messages+- [1mVersion check[0m — Whether a newer version is available on GitHub