Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Fix: make maximum status symbols test deterministic (#9)
Maximilian Roosc4493619f9d2
diff --git a/.claude-plugin/skills/worktrunk/reference/README.md b/.claude-plugin/skills/worktrunk/reference/README.mdindex b37a94419..b5ff4394a 100644--- a/.claude-plugin/skills/worktrunk/reference/README.md+++ b/.claude-plugin/skills/worktrunk/reference/README.md@@ -91,7 +91,7 @@ everything — standard `git worktree` commands continue working fine.### LLM-Authored Commit Messages-Worktrunk can invoke an external commands during merge operations to generate+Worktrunk can invoke external commands during merge operations to generatecommit messages. Simon Willison's [llm](https://llm.datasette.io/) tool readsthe diff and a configurable prompt, then returns a formatted commit message.@@ -831,9 +831,7 @@ The custom emoji appears directly after the git status symbols.Claude Code can automatically set/clear emoji status when coding sessions start and end. This shows which branches have active AI sessions.-**Easy setup:** The Worktrunk repository includes a `.claude-plugin` directory with pre-configured hooks. When working in this repository, the hooks are automatically available.--**Manual setup for other repositories:** Copy the hooks from [`.claude-plugin/hooks/hooks.json`](.claude-plugin/hooks/hooks.json) to `~/.claude/settings.json`.+**Easy setup:** The Worktrunk repository includes a `.claude-plugin` directory with pre-configured hooks.When using Claude:@@ -841,7 +839,7 @@ When using Claude:- Changes to `💬` when Claude needs input (waiting for permission or idle)- Clears the status completely when the session ends-**Status from other terminal:**+**Status from another terminal:**<!-- Output from: tests/snapshots/integration__integration_tests__list__with_user_status.snap -->@@ -862,7 +860,6 @@ dirty-with-status ≡?🤖 ./dirty-with-status b8346- Status is stored as `worktrunk.status.<branch>` in `.git/config`- Each branch can have its own status emoji- The hooks automatically detect the current branch and set/clear its status-- Status is shared across all worktrees on the same branch (by design)- Works with any git repository, no special configuration needed</details>diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 13bda3ea5..ce672a7a6 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -5,6 +5,7 @@ on:branches: [ main ]pull_request:branches: [ main ]+ workflow_dispatch:env:CARGO_TERM_COLOR: alwaysdiff --git a/.github/workflows/tier-2-integration-tests.yml b/.github/workflows/tier-2-integration-tests.ymlindex 4259f0627..b48e9c62a 100644--- a/.github/workflows/tier-2-integration-tests.yml+++ b/.github/workflows/tier-2-integration-tests.yml@@ -5,6 +5,7 @@ on:branches: [ main ]pull_request:branches: [ main ]+ workflow_dispatch:env:CARGO_TERM_COLOR: alwaysdiff --git a/src/commands/list/model.rs b/src/commands/list/model.rsindex ad793f9f1..3096f7722 100644--- a/src/commands/list/model.rs+++ b/src/commands/list/model.rs@@ -534,8 +534,10 @@ pub struct StatusSymbols {impl StatusSymbols {/// Render symbols with full alignment (all positions)///- /// This is used for the display fields in JSON output.- /// For table rendering with selective positions, use `render_with_mask()`.+ /// This is used for the display fields in JSON output. Skipped on Windows+ /// to avoid an unused/dead-code warning in clippy (the interactive selector+ /// that calls this exists only on Unix).+ #[cfg(unix)]pub fn render(&self) -> String {self.render_with_mask(&PositionMask::FULL)}diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rsindex 3c6f31780..85e0e45b3 100644--- a/tests/integration_tests/e2e_shell_post_start.rs+++ b/tests/integration_tests/e2e_shell_post_start.rs@@ -5,7 +5,22 @@ use crate::common::{use rstest::rstest;use std::fs;use std::thread;-use std::time::Duration;+use std::time::{Duration, Instant};++fn wait_for_file(path: &std::path::Path, timeout: Duration) {+ let start = Instant::now();+ while start.elapsed() < timeout {+ if path.exists() {+ return;+ }+ thread::sleep(Duration::from_millis(50));+ }+ panic!(+ "File was not created within {:?}: {}",+ timeout,+ path.display()+ );+}/// Test that post-start background commands work with shell integration#[rstest]@@ -71,9 +86,6 @@ approved-commands = ["sleep 0.05 && echo 'Background task done' > bg_marker.txt"output);- // Wait for background command to complete (command has sleep 0.05 + margin)- thread::sleep(Duration::from_millis(150));-// Verify background command actually ranlet worktree_path = repo.root_path()@@ -105,14 +117,13 @@ approved-commands = ["sleep 0.05 && echo 'Background task done' > bg_marker.txt"log_files);- let marker_file = worktree_path.join("bg_marker.txt");- assert!(- marker_file.exists(),- "Background command should have created bg_marker.txt in {} (logs: {:?})",- worktree_path.display(),- log_files+ // Wait for background command to complete (allow plenty of margin on CI)+ wait_for_file(+ worktree_path.join("bg_marker.txt").as_path(),+ Duration::from_secs(1),);+ let marker_file = worktree_path.join("bg_marker.txt");let content = fs::read_to_string(&marker_file).expect("Failed to read marker file");assert!(content.contains("Background task done"),@@ -321,8 +332,16 @@ approved-commands = ["sleep 0.05 && echo 'Fish background done' > fish_bg.txt"]output);- // Wait for background command (command has sleep 0.05 + margin)- thread::sleep(Duration::from_millis(150));+ // Wait for background command (allow plenty of margin on CI)+ wait_for_file(+ repo.root_path()+ .parent()+ .unwrap()+ .join("test-repo.fish-bg-test")+ .join("fish_bg.txt")+ .as_path(),+ Duration::from_secs(1),+ );// Verify background command ranlet worktree_path = repodiff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rsindex 049dc5bb0..8e476a47e 100644--- a/tests/integration_tests/list.rs+++ b/tests/integration_tests/list.rs@@ -1611,75 +1611,61 @@ fn test_list_maximum_status_symbols() {.output().unwrap();- // Create a remote repo by cloning to a separate directory- let remote_dir = repo.root_path().parent().unwrap().join("remote-repo");- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args([- "clone",- repo.root_path().to_str().unwrap(),- remote_dir.to_str().unwrap(),- ])- .output()- .unwrap();+ // Create a real bare remote so upstream exists, but keep all graph crafting local for determinism+ repo.setup_remote("main");- // In the remote repo, check out feature branch and make a commit- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["checkout", "feature"])- .current_dir(&remote_dir)- .output()- .unwrap();+ // Remember the shared base (Feature work)+ let base_sha = {+ let output = repo+ .git_command(&["rev-parse", "HEAD"])+ .current_dir(&feature)+ .output()+ .unwrap();+ String::from_utf8_lossy(&output.stdout).trim().to_string()+ };- std::fs::write(remote_dir.join("remote-file.txt"), "remote content").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "remote-file.txt"])- .current_dir(&remote_dir)+ // Remote-only commit+ std::fs::write(feature.join("remote-file.txt"), "remote content").unwrap();+ repo.git_command(&["add", "remote-file.txt"])+ .current_dir(&feature).output().unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Remote commit"])- .current_dir(&remote_dir)+ repo.git_command(&["commit", "-m", "Remote commit"])+ .current_dir(&feature).output().unwrap();+ let remote_sha = {+ let output = repo+ .git_command(&["rev-parse", "HEAD"])+ .current_dir(&feature)+ .output()+ .unwrap();+ String::from_utf8_lossy(&output.stdout).trim().to_string()+ };- // In the local feature worktree, make a different commit (creates divergence)- std::fs::write(feature.join("local-file.txt"), "local content").unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["add", "local-file.txt"])+ // Reset back to base so the remote commit is not in the local branch history+ repo.git_command(&["reset", "--hard", &base_sha]).current_dir(&feature).output().unwrap();- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["commit", "-m", "Local commit"])++ // Local-only commit (divergence on the local side)+ std::fs::write(feature.join("local-file.txt"), "local content").unwrap();+ repo.git_command(&["add", "local-file.txt"]).current_dir(&feature).output().unwrap();-- // Set up the remote repo as origin for the feature worktree- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["remote", "add", "origin", remote_dir.to_str().unwrap()])+ repo.git_command(&["commit", "-m", "Local commit"]).current_dir(&feature).output().unwrap();- // Fetch from the remote to establish tracking- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["fetch", "origin"])+ // Wire up upstream tracking deterministically: point origin/feature at the remote-only commit+ repo.git_command(&["update-ref", "refs/remotes/origin/feature", &remote_sha]).current_dir(&feature).output().unwrap();-- // Set up branch tracking- let mut cmd = Command::new("git");- repo.configure_git_cmd(&mut cmd);- cmd.args(["branch", "--set-upstream-to=origin/feature", "feature"])+ repo.git_command(&["branch", "--set-upstream-to=origin/feature", "feature"]).current_dir(&feature).output().unwrap();@@ -1749,17 +1735,7 @@ fn test_list_maximum_status_symbols() {.unwrap();// Result should show 11 chars: ?!+»✘=⊠↕⇅🤖- //- // Note: Git's ahead/behind calculation for clone-based remotes is platform-dependent:- // - Ubuntu: reports behind=0, shows ⇡ (ahead only)- // - macOS: reports behind=1, shows ⇅ (diverged)- // We normalize the flaky upstream divergence symbol and behind count to accept either.- let mut settings = list_snapshots::standard_settings(&repo);- // Normalize upstream divergence: accept both ⇡ (ahead) and ⇅ (diverged)- // Note: Yellow ANSI code (\x1b[33m) appears before the ⊠ symbol- settings.add_filter(r"↕[⇡⇅]\x1b\[33m⊠", "↕[UPSTREAM]\x1b[33m⊠");- // Normalize remote behind count: accept both ↓0 and ↓1- settings.add_filter(r"↓[01]", "↓[N]");+ let settings = list_snapshots::standard_settings(&repo);settings.bind(|| {let mut cmd = list_snapshots::command(&repo, repo.root_path());cmd.arg("--full");diff --git a/tests/snapshots/integration__integration_tests__list__maximum_status_symbols.snap b/tests/snapshots/integration__integration_tests__list__maximum_status_symbols.snapindex cdf328d1b..2a80c64bc 100644--- a/tests/snapshots/integration__integration_tests__list__maximum_status_symbols.snap+++ b/tests/snapshots/integration__integration_tests__list__maximum_status_symbols.snap@@ -12,11 +12,10 @@ info:GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/nullGIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpLJgbF4/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpoGHFYx/test-config.toml---success: trueexit_code: 0@@ -24,7 +23,7 @@ exit_code: 0----- stderr -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mmain…±[0m [1mPath[0m [1mRemote⇅[0m [1mCI[0m [1mCommit[0m [1mAge[0m [1mMessage[0m-[1m[35mmain[0m [1m[35m./test-repo[0m [2m85ed6d3d[0m [2m10 months ago[0m [2mMain advances[0m-feature [36m?!+»✘[0m[31m=[0m ↕[UPSTREAM][33m⊠[0m🤖 [32m+2[0m [31m-2[0m [32m↑2[0m [2m[31m↓[N][0m [32m+3[0m [31m-1[0m ./feature [32m↑1[0m [2m[31m↓[N][0m [2m4afb2b9e[0m [2m10 months ago[0m [2mLocal commit[0m+[1m[35mmain[0m ⇡ [1m[35m./test-repo[0m [32m↑1[0m [2m[31m↓0[0m [2m85ed6d3d[0m [2m10 months ago[0m [2mMain advances[0m+feature [36m?!+»✘[0m[31m=[0m ↕⇅[33m⊠[0m🤖 [32m+2[0m [31m-2[0m [32m↑2[0m [2m[31m↓1[0m [32m+3[0m [31m-1[0m ./feature [32m↑1[0m [2m[31m↓1[0m [2m4afb2b9e[0m [2m10 months ago[0m [2mLocal commit[0m⚪ [2mShowing 2 worktrees, 1 with changes, 1 ahead[0m