Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Add tests for user messages and document coverage behavior (#633)

Maximilian Roos1b8f6d2ba1ae
diff --git a/CLAUDE.md b/CLAUDE.md
index fbbe09351..dd105f9cd 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -263,6 +263,20 @@ When CI shows a codecov/patch failure, investigate before declaring "ready to me
- Write a test that exercises it, or
- Document why it's intentionally untested (e.g., error paths requiring external system mocks)
+### How Coverage Works with Integration Tests
+
+Coverage is collected via `cargo llvm-cov` which instruments the binary. **Subprocess execution IS captured** — when tests spawn `wt` via `assert_cmd_snapshot!`, the instrumented binary writes coverage data to profile files that get merged into the report.
+
+When investigating uncovered lines:
+
+1. Run `task coverage` first to see actual coverage % (~92% is normal)
+2. Use `cargo llvm-cov report --show-missing-lines | grep <file>` to find specific uncovered lines
+3. **Check if tests already exist** for that functionality before writing new ones
+4. Remaining uncovered lines are typically:
+ - Error handling paths requiring mocked git failures
+ - Edge cases in shell integration states (e.g., running as `git wt`)
+ - Test assertion code (only executes when tests fail)
+
## Benchmarks
See `benches/CLAUDE.md` for details.
diff --git a/tests/integration_tests/hook_show.rs b/tests/integration_tests/hook_show.rs
index 3f6b0246d..5e6d49804 100644
--- a/tests/integration_tests/hook_show.rs
+++ b/tests/integration_tests/hook_show.rs
@@ -223,3 +223,60 @@ lint = "pre-commit run"
assert_cmd_snapshot!(cmd);
});
}
+
+/// Test `wt hook clear` when no approvals exist for the project.
+#[rstest]
+fn test_hook_clear_no_approvals(repo: TestRepo, temp_home: TempDir) {
+ // Create user config without any project approvals
+ 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,
+ r#"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);
+ cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
+ cmd.args(["hook", "approvals", "clear"])
+ .current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+/// Test `wt hook clear` when project has approvals to clear.
+#[rstest]
+fn test_hook_clear_with_approvals(repo: TestRepo, temp_home: TempDir) {
+ // Create user config with approved commands for this project
+ 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,
+ r#"worktree-path = "../{{ repo }}.{{ branch }}"
+
+[projects."repo"]
+approved-commands = ["cargo build", "cargo test", "npm install"]
+"#,
+ )
+ .unwrap();
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
+ cmd.args(["hook", "approvals", "clear"])
+ .current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index e68398540..409d92160 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -1943,3 +1943,20 @@ fn test_step_rebase_with_merge_commit(mut repo: TestRepo) {
cmd
});
}
+
+/// Test `wt step rebase` when the feature branch is already up to date with main.
+///
+/// This should show "Already up to date with main" message.
+#[rstest]
+fn test_step_rebase_already_up_to_date(mut repo: TestRepo) {
+ // Create a feature worktree but don't advance main (feature is based on main's HEAD)
+ let feature_wt = repo.add_worktree("feature");
+
+ // Run `wt step rebase` - should show "Already up to date with main"
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["rebase"],
+ Some(&feature_wt)
+ ));
+}
diff --git a/tests/snapshots/integration__integration_tests__hook_show__hook_clear_no_approvals.snap b/tests/snapshots/integration__integration_tests__hook_show__hook_clear_no_approvals.snap
new file mode 100644
index 000000000..ab81c5213
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__hook_show__hook_clear_no_approvals.snap
@@ -0,0 +1,36 @@
+---
+source: tests/integration_tests/hook_show.rs
+info:
+ program: wt
+ args:
+ - hook
+ - approvals
+ - clear
+ 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
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No approvals to clear for this project
diff --git a/tests/snapshots/integration__integration_tests__hook_show__hook_clear_with_approvals.snap b/tests/snapshots/integration__integration_tests__hook_show__hook_clear_with_approvals.snap
new file mode 100644
index 000000000..194cf9e99
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__hook_show__hook_clear_with_approvals.snap
@@ -0,0 +1,36 @@
+---
+source: tests/integration_tests/hook_show.rs
+info:
+ program: wt
+ args:
+ - hook
+ - approvals
+ - clear
+ 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
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Cleared 3 approvals for this project
diff --git a/tests/snapshots/integration__integration_tests__merge__step_rebase_already_up_to_date.snap b/tests/snapshots/integration__integration_tests__merge__step_rebase_already_up_to_date.snap
new file mode 100644
index 000000000..1716020e4
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__step_rebase_already_up_to_date.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/merge.rs
+info:
+ program: wt
+ args:
+ - step
+ - rebase
+ 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
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Already up to date with main