Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add Codecov badge to README
Maximilian Roos38c7a056c327
diff --git a/README.md b/README.mdindex cc2196a1d..9ec1a427a 100644--- a/README.md+++ b/README.md@@ -6,6 +6,7 @@[](https://crates.io/crates/worktrunk)[](https://opensource.org/licenses/MIT)[](https://github.com/max-sixty/worktrunk/actions?query=branch%3Amain+workflow%3Aci)+[](https://codecov.io/gh/max-sixty/worktrunk)<!-- Dev badges (uncomment when repo is public and has traction) --><!-- [](https://crates.io/crates/worktrunk) -->diff --git a/src/commands/config.rs b/src/commands/config.rsindex 4dacf16c2..44e9151a9 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -871,3 +871,45 @@ pub fn handle_cache_refresh() -> anyhow::Result<()> {Ok(())}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn test_comment_out_config_basic() {+ let input = "key = \"value\"\n";+ let expected = "# key = \"value\"\n";+ assert_eq!(comment_out_config(input), expected);+ }++ #[test]+ fn test_comment_out_config_preserves_existing_comments() {+ let input = "# This is a comment\nkey = \"value\"\n";+ let expected = "# This is a comment\n# key = \"value\"\n";+ assert_eq!(comment_out_config(input), expected);+ }++ #[test]+ fn test_comment_out_config_preserves_empty_lines() {+ let input = "key1 = \"value\"\n\nkey2 = \"value\"\n";+ let expected = "# key1 = \"value\"\n\n# key2 = \"value\"\n";+ assert_eq!(comment_out_config(input), expected);+ }++ #[test]+ fn test_comment_out_config_preserves_trailing_newline() {+ let with_newline = "key = \"value\"\n";+ let without_newline = "key = \"value\"";++ assert!(comment_out_config(with_newline).ends_with('\n'));+ assert!(!comment_out_config(without_newline).ends_with('\n'));+ }++ #[test]+ fn test_comment_out_config_section_headers() {+ let input = "[hooks]\ncommand = \"npm test\"\n";+ let expected = "# [hooks]\n# command = \"npm test\"\n";+ assert_eq!(comment_out_config(input), expected);+ }+}diff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rsindex c2543b90b..b6bb06203 100644--- a/src/commands/list/ci_status.rs+++ b/src/commands/list/ci_status.rs@@ -324,6 +324,78 @@ mod tests {);}}++ #[test]+ fn test_is_retriable_error() {+ // Rate limit errors+ assert!(is_retriable_error("API rate limit exceeded"));+ assert!(is_retriable_error("rate limit exceeded for requests"));+ assert!(is_retriable_error("Error 403: forbidden"));+ assert!(is_retriable_error("HTTP 429 Too Many Requests"));++ // Network errors+ assert!(is_retriable_error("connection timed out"));+ assert!(is_retriable_error("network error"));+ assert!(is_retriable_error("timeout waiting for response"));++ // Case insensitivity+ assert!(is_retriable_error("RATE LIMIT"));+ assert!(is_retriable_error("Connection Reset"));++ // Non-retriable errors+ assert!(!is_retriable_error("branch not found"));+ assert!(!is_retriable_error("invalid credentials"));+ assert!(!is_retriable_error("permission denied"));+ assert!(!is_retriable_error(""));+ }++ #[test]+ fn test_ci_status_color() {+ use anstyle::AnsiColor;++ assert_eq!(CiStatus::Passed.color(), AnsiColor::Green);+ assert_eq!(CiStatus::Running.color(), AnsiColor::Blue);+ assert_eq!(CiStatus::Failed.color(), AnsiColor::Red);+ assert_eq!(CiStatus::Conflicts.color(), AnsiColor::Yellow);+ assert_eq!(CiStatus::Error.color(), AnsiColor::Yellow);+ assert_eq!(CiStatus::NoCI.color(), AnsiColor::BrightBlack);+ }++ #[test]+ fn test_pr_status_indicator() {+ let pr_passed = PrStatus {+ ci_status: CiStatus::Passed,+ source: CiSource::PullRequest,+ is_stale: false,+ url: None,+ };+ assert_eq!(pr_passed.indicator(), "●");++ let branch_running = PrStatus {+ ci_status: CiStatus::Running,+ source: CiSource::Branch,+ is_stale: false,+ url: None,+ };+ assert_eq!(branch_running.indicator(), "●");++ let error_status = PrStatus {+ ci_status: CiStatus::Error,+ source: CiSource::PullRequest,+ is_stale: false,+ url: None,+ };+ assert_eq!(error_status.indicator(), "⚠");+ }++ #[test]+ fn test_pr_status_error_constructor() {+ let error = PrStatus::error();+ assert_eq!(error.ci_status, CiStatus::Error);+ assert_eq!(error.source, CiSource::Branch);+ assert!(!error.is_stale);+ assert!(error.url.is_none());+ }}/// Maximum number of PRs/MRs to fetch when filtering by source repository.diff --git a/src/commands/select.rs b/src/commands/select.rsindex fbb33541a..13d5d6091 100644--- a/src/commands/select.rs+++ b/src/commands/select.rs@@ -981,4 +981,69 @@ mod tests {assert!(!pager_needs_paging_disabled("/path/to/delta-preview"));assert!(pager_needs_paging_disabled("batcat")); // Debian's bat package name}++ #[test]+ fn test_shell_escape_simple() {+ // Simple strings pass through unchanged+ assert_eq!(shell_escape("hello"), "hello");+ assert_eq!(shell_escape("foo-bar"), "foo-bar");+ assert_eq!(shell_escape("path/to/file"), "path/to/file");+ }++ #[test]+ fn test_shell_escape_with_spaces() {+ // Strings with spaces get quoted+ assert_eq!(shell_escape("hello world"), "'hello world'");+ assert_eq!(shell_escape("path/to/my file"), "'path/to/my file'");+ }++ #[test]+ fn test_shell_escape_with_special_chars() {+ // Special shell characters get quoted+ assert_eq!(shell_escape("foo$bar"), "'foo$bar'");+ assert_eq!(shell_escape("foo`bar"), "'foo`bar'");+ assert_eq!(shell_escape("foo;bar"), "'foo;bar'");+ assert_eq!(shell_escape("foo|bar"), "'foo|bar'");+ assert_eq!(shell_escape("foo&bar"), "'foo&bar'");+ assert_eq!(shell_escape("foo*bar"), "'foo*bar'");+ assert_eq!(shell_escape("foo?bar"), "'foo?bar'");+ }++ #[test]+ fn test_shell_escape_with_quotes() {+ // Single quotes get escaped specially+ assert_eq!(shell_escape("it's"), "'it'\\''s'");+ assert_eq!(shell_escape("don't"), "'don'\\''t'");+ // Double quotes trigger quoting but don't need internal escaping+ assert_eq!(shell_escape("say \"hi\""), "'say \"hi\"'");+ }++ #[test]+ fn test_render_preview_tabs_working_tree_mode() {+ let output = WorktreeSkimItem::render_preview_tabs(PreviewMode::WorkingTree);+ // Tab 1 should be bold (active), tabs 2 and 3 dimmed+ assert!(output.contains("1: HEAD±"));+ assert!(output.contains("2: log"));+ assert!(output.contains("3: main…±"));+ assert!(output.contains("Enter: switch"));+ // Verify structure: tabs on first line, controls on second+ assert!(output.contains(" | "));+ assert!(output.ends_with("\n\n"));+ }++ #[test]+ fn test_render_preview_tabs_log_mode() {+ let output = WorktreeSkimItem::render_preview_tabs(PreviewMode::Log);+ assert!(output.contains("1: HEAD±"));+ assert!(output.contains("2: log"));+ assert!(output.contains("3: main…±"));+ }++ #[test]+ fn test_render_preview_tabs_branch_diff_mode() {+ let output = WorktreeSkimItem::render_preview_tabs(PreviewMode::BranchDiff);+ assert!(output.contains("1: HEAD±"));+ assert!(output.contains("2: log"));+ assert!(output.contains("3: main…±"));+ }}diff --git a/src/display.rs b/src/display.rsindex a845ab3e3..1dc9cf0df 100644--- a/src/display.rs+++ b/src/display.rs@@ -221,4 +221,115 @@ mod tests {assert!(result.width() <= 20, "Width should be <= 20");assert!(result.ends_with('…'), "Should end with ellipsis");}++ #[test]+ fn test_format_relative_time_short() {+ let now: i64 = 1700000000; // Fixed timestamp for testing++ // Just now (< 1 minute)+ assert_eq!(format_relative_time_impl(now - 30, now, true), "now");+ assert_eq!(format_relative_time_impl(now - 59, now, true), "now");++ // Minutes+ assert_eq!(format_relative_time_impl(now - 60, now, true), "1m");+ assert_eq!(format_relative_time_impl(now - 120, now, true), "2m");+ assert_eq!(format_relative_time_impl(now - 3599, now, true), "59m");++ // Hours+ assert_eq!(format_relative_time_impl(now - 3600, now, true), "1h");+ assert_eq!(format_relative_time_impl(now - 7200, now, true), "2h");++ // Days+ assert_eq!(format_relative_time_impl(now - 86400, now, true), "1d");+ assert_eq!(format_relative_time_impl(now - 172800, now, true), "2d");++ // Weeks+ assert_eq!(format_relative_time_impl(now - 604800, now, true), "1w");++ // Months+ assert_eq!(format_relative_time_impl(now - 2592000, now, true), "1mo");++ // Years+ assert_eq!(format_relative_time_impl(now - 31536000, now, true), "1y");++ // Future timestamp+ assert_eq!(format_relative_time_impl(now + 1000, now, true), "future");+ }++ #[test]+ fn test_format_relative_time_long() {+ let now: i64 = 1700000000;++ assert_eq!(format_relative_time_impl(now - 30, now, false), "just now");+ assert_eq!(+ format_relative_time_impl(now - 60, now, false),+ "1 minute ago"+ );+ assert_eq!(+ format_relative_time_impl(now - 120, now, false),+ "2 minutes ago"+ );+ assert_eq!(+ format_relative_time_impl(now - 3600, now, false),+ "1 hour ago"+ );+ assert_eq!(+ format_relative_time_impl(now - 86400, now, false),+ "1 day ago"+ );+ assert_eq!(+ format_relative_time_impl(now + 1000, now, false),+ "in the future"+ );+ }++ #[test]+ fn test_find_common_prefix() {+ // Empty input+ let empty: Vec<PathBuf> = vec![];+ assert_eq!(find_common_prefix(&empty), PathBuf::new());++ // Single path+ let single = vec![PathBuf::from("/home/user/projects")];+ assert_eq!(+ find_common_prefix(&single),+ PathBuf::from("/home/user/projects")+ );++ // Common prefix exists+ let paths = vec![+ PathBuf::from("/home/user/projects/foo"),+ PathBuf::from("/home/user/projects/bar"),+ PathBuf::from("/home/user/projects/baz"),+ ];+ assert_eq!(+ find_common_prefix(&paths),+ PathBuf::from("/home/user/projects")+ );++ // No common prefix beyond root+ let paths = vec![+ PathBuf::from("/home/user/projects"),+ PathBuf::from("/var/log"),+ ];+ assert_eq!(find_common_prefix(&paths), PathBuf::from("/"));+ }++ #[test]+ fn test_shorten_path() {+ let prefix = PathBuf::from("/home/user/projects");++ // Path within prefix+ let path = PathBuf::from("/home/user/projects/foo/bar");+ assert_eq!(shorten_path(&path, &prefix), "./foo/bar");++ // Path equals prefix+ assert_eq!(shorten_path(&prefix, &prefix), ".");++ // Path outside prefix (falls back to full path)+ let other = PathBuf::from("/var/log/syslog");+ // The result includes tilde expansion, so just check it doesn't start with "./"+ let result = shorten_path(&other, &prefix);+ assert!(!result.starts_with("./"));+ }}diff --git a/src/shell.rs b/src/shell.rsindex 3778990fc..ad069fe01 100644--- a/src/shell.rs+++ b/src/shell.rs@@ -434,4 +434,55 @@ mod tests {));assert!("invalid".parse::<Shell>().is_err());}++ #[test]+ fn test_shell_display() {+ assert_eq!(Shell::Bash.to_string(), "bash");+ assert_eq!(Shell::Fish.to_string(), "fish");+ assert_eq!(Shell::Zsh.to_string(), "zsh");+ assert_eq!(Shell::PowerShell.to_string(), "powershell");+ }++ #[test]+ fn test_shell_config_line_bash() {+ let line = Shell::Bash.config_line();+ assert!(line.contains("eval"));+ assert!(line.contains("wt config shell init bash"));+ assert!(line.contains("command -v wt"));+ }++ #[test]+ fn test_shell_config_line_zsh() {+ let line = Shell::Zsh.config_line();+ assert!(line.contains("eval"));+ assert!(line.contains("wt config shell init zsh"));+ }++ #[test]+ fn test_shell_config_line_fish() {+ let line = Shell::Fish.config_line();+ assert!(line.contains("type -q wt"));+ assert!(line.contains("wt config shell init fish"));+ assert!(line.contains("source"));+ }++ #[test]+ fn test_shell_config_line_powershell() {+ let line = Shell::PowerShell.config_line();+ assert!(line.contains("Invoke-Expression"));+ assert!(line.contains("wt config shell init powershell"));+ }++ #[test]+ fn test_shell_init_generate() {+ // Test that shell init generates valid output for each shell+ let shells = [Shell::Bash, Shell::Zsh, Shell::Fish, Shell::PowerShell];+ for shell in shells {+ let init = ShellInit::new(shell);+ let result = init.generate();+ assert!(result.is_ok(), "Failed to generate for {:?}", shell);+ let output = result.unwrap();+ assert!(!output.is_empty(), "Empty output for {:?}", shell);+ }+ }}diff --git a/src/styling/format.rs b/src/styling/format.rsindex 5b2648f94..3232761ec 100644--- a/src/styling/format.rs+++ b/src/styling/format.rs@@ -332,3 +332,82 @@ pub(crate) fn format_bash_with_gutter_at_width(pub fn format_bash_with_gutter(content: &str, left_margin: &str) -> String {format_with_gutter(content, left_margin, None)}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn test_wrap_text_at_width_no_wrap_needed() {+ let result = wrap_text_at_width("short text", 20);+ assert_eq!(result, vec!["short text"]);+ }++ #[test]+ fn test_wrap_text_at_width_basic_wrap() {+ let result = wrap_text_at_width("hello world foo bar", 10);+ // Words wrap at boundaries, each line fits within max_width+ assert_eq!(result, vec!["hello", "world foo", "bar"]);+ }++ #[test]+ fn test_wrap_text_at_width_zero_width() {+ let result = wrap_text_at_width("hello world", 0);+ assert_eq!(result, vec!["hello world"]);+ }++ #[test]+ fn test_wrap_text_at_width_empty_input() {+ let result = wrap_text_at_width("", 20);+ assert_eq!(result, vec![""]);+ }++ #[test]+ fn test_wrap_text_at_width_single_long_word() {+ // Single word longer than max_width should still be included+ let result = wrap_text_at_width("superlongword", 5);+ assert_eq!(result, vec!["superlongword"]);+ }++ #[test]+ fn test_wrap_styled_text_no_wrap_needed() {+ let result = wrap_styled_text("short text", 20);+ assert_eq!(result, vec!["short text"]);+ }++ #[test]+ fn test_wrap_styled_text_zero_width() {+ let result = wrap_styled_text("hello world", 0);+ assert_eq!(result, vec!["hello world"]);+ }++ #[test]+ fn test_wrap_styled_text_empty_input() {+ let result = wrap_styled_text("", 20);+ assert_eq!(result, vec![""]);+ }++ #[test]+ fn test_format_with_gutter_basic() {+ let result = format_with_gutter("hello", "", Some(80));+ // Should have gutter formatting+ assert!(result.contains("hello"));+ assert!(result.ends_with('\n'));+ }++ #[test]+ fn test_format_with_gutter_multiline() {+ let result = format_with_gutter("line1\nline2", "", Some(80));+ // Each line should be formatted separately+ assert!(result.contains("line1"));+ assert!(result.contains("line2"));+ // Should have 2 newlines (one per line)+ assert_eq!(result.matches('\n').count(), 2);+ }++ #[test]+ fn test_gutter_overhead_constant() {+ // Verify the overhead matches documented value+ assert_eq!(GUTTER_OVERHEAD, 3);+ }+}diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 8252ab6d1..8a7d9b2a8 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -564,6 +564,19 @@ pub fn configure_cli_command(cmd: &mut Command) {cmd.env("CLICOLOR_FORCE", "1");cmd.env("SOURCE_DATE_EPOCH", TEST_EPOCH.to_string());cmd.env("COLUMNS", "150");++ // Pass through LLVM coverage profiling environment for subprocess coverage collection.+ // When running under cargo-llvm-cov, spawned binaries need LLVM_PROFILE_FILE to record+ // their coverage data. Without this, integration test coverage isn't captured.+ for key in [+ "LLVM_PROFILE_FILE",+ "CARGO_LLVM_COV",+ "CARGO_LLVM_COV_TARGET_DIR",+ ] {+ if let Ok(val) = std::env::var(key) {+ cmd.env(key, val);+ }+ }}/// Set home environment variables for commands that rely on isolated temp homes.diff --git a/tests/common/progressive_output.rs b/tests/common/progressive_output.rsindex 983b6f46b..eb9adf540 100644--- a/tests/common/progressive_output.rs+++ b/tests/common/progressive_output.rs@@ -563,6 +563,19 @@ fn configure_pty_environment(cmd: &mut CommandBuilder, repo: &TestRepo) {for (key, value) in repo.test_env_vars() {cmd.env(key, value);}++ // Pass through LLVM coverage profiling environment for subprocess coverage collection.+ // When running under cargo-llvm-cov, spawned binaries need LLVM_PROFILE_FILE to record+ // their coverage data.+ for key in [+ "LLVM_PROFILE_FILE",+ "CARGO_LLVM_COV",+ "CARGO_LLVM_COV_TARGET_DIR",+ ] {+ if let Ok(val) = std::env::var(key) {+ cmd.env(key, val);+ }+ }}#[cfg(test)]