Skip to content

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

Add completion benchmarks and tests for various scenarios

Maximilian Roos7b87945d5702
diff --git a/Cargo.lock b/Cargo.lock
index 78a2dc476..e10d1f6c0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -11,6 +11,12 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "anes"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299"
+
[[package]]
name = "anstream"
version = "0.6.21"
@@ -137,6 +143,12 @@ dependencies = [
"syn",
]
+[[package]]
+name = "autocfg"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
+
[[package]]
name = "base64"
version = "0.21.7"
@@ -172,12 +184,51 @@ dependencies = [
"serde",
]
+[[package]]
+name = "bumpalo"
+version = "3.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
+
+[[package]]
+name = "cast"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
+
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
+[[package]]
+name = "ciborium"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
+dependencies = [
+ "ciborium-io",
+ "ciborium-ll",
+ "serde",
+]
+
+[[package]]
+name = "ciborium-io"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
+
+[[package]]
+name = "ciborium-ll"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
+dependencies = [
+ "ciborium-io",
+ "half",
+]
+
[[package]]
name = "clap"
version = "4.5.49"
@@ -303,6 +354,67 @@ dependencies = [
"libc",
]
+[[package]]
+name = "criterion"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f"
+dependencies = [
+ "anes",
+ "cast",
+ "ciborium",
+ "clap",
+ "criterion-plot",
+ "is-terminal",
+ "itertools",
+ "num-traits",
+ "once_cell",
+ "oorandom",
+ "plotters",
+ "rayon",
+ "regex",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "tinytemplate",
+ "walkdir",
+]
+
+[[package]]
+name = "criterion-plot"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1"
+dependencies = [
+ "cast",
+ "itertools",
+]
+
+[[package]]
+name = "crossbeam-deque"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
+dependencies = [
+ "crossbeam-epoch",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-epoch"
+version = "0.9.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
+dependencies = [
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
+
[[package]]
name = "crunchy"
version = "0.2.4"
@@ -446,6 +558,12 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
+[[package]]
+name = "either"
+version = "1.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
+
[[package]]
name = "encode_unicode"
version = "1.0.0"
@@ -640,6 +758,17 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
+[[package]]
+name = "half"
+version = "2.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
+dependencies = [
+ "cfg-if",
+ "crunchy",
+ "zerocopy",
+]
+
[[package]]
name = "hashbrown"
version = "0.14.5"
@@ -676,6 +805,12 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
+[[package]]
+name = "hermit-abi"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
+
[[package]]
name = "ident_case"
version = "1.0.1"
@@ -718,18 +853,48 @@ dependencies = [
"serde_json",
]
+[[package]]
+name = "is-terminal"
+version = "0.4.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
+[[package]]
+name = "itertools"
+version = "0.10.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
+dependencies = [
+ "either",
+]
+
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
+[[package]]
+name = "js-sys"
+version = "0.3.81"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305"
+dependencies = [
+ "once_cell",
+ "wasm-bindgen",
+]
+
[[package]]
name = "json5"
version = "0.4.1"
@@ -763,6 +928,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
+[[package]]
+name = "log"
+version = "0.4.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
+
[[package]]
name = "memchr"
version = "2.7.6"
@@ -775,6 +946,15 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
[[package]]
name = "num_threads"
version = "0.1.7"
@@ -796,6 +976,12 @@ version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
+[[package]]
+name = "oorandom"
+version = "11.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e"
+
[[package]]
name = "option-ext"
version = "0.2.0"
@@ -879,6 +1065,34 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
+[[package]]
+name = "plotters"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747"
+dependencies = [
+ "num-traits",
+ "plotters-backend",
+ "plotters-svg",
+ "wasm-bindgen",
+ "web-sys",
+]
+
+[[package]]
+name = "plotters-backend"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a"
+
+[[package]]
+name = "plotters-svg"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670"
+dependencies = [
+ "plotters-backend",
+]
+
[[package]]
name = "powerfmt"
version = "0.2.0"
@@ -945,6 +1159,26 @@ version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
+[[package]]
+name = "rayon"
+version = "1.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f"
+dependencies = [
+ "either",
+ "rayon-core",
+]
+
+[[package]]
+name = "rayon-core"
+version = "1.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
+dependencies = [
+ "crossbeam-deque",
+ "crossbeam-utils",
+]
+
[[package]]
name = "redox_users"
version = "0.5.2"
@@ -1083,6 +1317,15 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
+[[package]]
+name = "same-file"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
+dependencies = [
+ "winapi-util",
+]
+
[[package]]
name = "semver"
version = "1.0.27"
@@ -1283,6 +1526,16 @@ dependencies = [
"crunchy",
]
+[[package]]
+name = "tinytemplate"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc"
+dependencies = [
+ "serde",
+ "serde_json",
+]
+
[[package]]
name = "toml"
version = "0.8.23"
@@ -1456,6 +1709,16 @@ dependencies = [
"libc",
]
+[[package]]
+name = "walkdir"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
+dependencies = [
+ "same-file",
+ "winapi-util",
+]
+
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
@@ -1471,6 +1734,84 @@ dependencies = [
"wit-bindgen",
]
+[[package]]
+name = "wasm-bindgen"
+version = "0.2.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d"
+dependencies = [
+ "cfg-if",
+ "once_cell",
+ "rustversion",
+ "wasm-bindgen-macro",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-backend"
+version = "0.2.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19"
+dependencies = [
+ "bumpalo",
+ "log",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-backend",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "web-sys"
+version = "0.3.81"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120"
+dependencies = [
+ "js-sys",
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "winapi-util"
+version = "0.1.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
+dependencies = [
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "windows-link"
version = "0.2.1"
@@ -1659,6 +2000,7 @@ dependencies = [
"clap",
"clap_complete",
"config",
+ "criterion",
"directories",
"insta",
"insta-cmd",
@@ -1679,3 +2021,23 @@ dependencies = [
"encoding_rs",
"hashlink",
]
+
+[[package]]
+name = "zerocopy"
+version = "0.8.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c"
+dependencies = [
+ "zerocopy-derive",
+]
+
+[[package]]
+name = "zerocopy-derive"
+version = "0.8.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
diff --git a/Cargo.toml b/Cargo.toml
index 2d9daa0e2..de9d8c93c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -32,3 +32,8 @@ assert_cmd = "2.0"
tempfile = "3.14"
toml = "0.8"
rstest = "0.23"
+criterion = "0.5"
+
+[[bench]]
+name = "completion"
+harness = false
diff --git a/README.md b/README.md
index f09b4f6e9..b3af2a2bd 100644
--- a/README.md
+++ b/README.md
@@ -80,6 +80,7 @@ wt completion fish > ~/.config/fish/completions/wt.fish
- Zsh currently uses Bash-compatible completion syntax. Dynamic branch completion may require `bashcompinit`. For best results, use Fish or Bash.
- Regenerate completion scripts after updating `wt`
- Debug completion: Set `WT_DEBUG_COMPLETION=1` to see errors
+- Performance: Run `cargo bench` to measure completion performance on your system
## Usage
diff --git a/benches/completion.rs b/benches/completion.rs
new file mode 100644
index 000000000..f74d5992d
--- /dev/null
+++ b/benches/completion.rs
@@ -0,0 +1,149 @@
+use criterion::{Criterion, criterion_group, criterion_main};
+use std::process::Command;
+use tempfile::TempDir;
+
+/// Create a test git repository with specified number of branches and worktrees
+fn setup_test_repo(num_branches: usize, num_worktrees: usize) -> TempDir {
+ let temp_dir = tempfile::tempdir().unwrap();
+ let repo_path = temp_dir.path();
+
+ // Initialize git repo
+ Command::new("git")
+ .args(&["init"])
+ .current_dir(repo_path)
+ .output()
+ .unwrap();
+
+ // Configure git
+ Command::new("git")
+ .args(&["config", "user.name", "Test"])
+ .current_dir(repo_path)
+ .output()
+ .unwrap();
+
+ Command::new("git")
+ .args(&["config", "user.email", "[email protected]"])
+ .current_dir(repo_path)
+ .output()
+ .unwrap();
+
+ // Create initial commit
+ Command::new("git")
+ .args(&["commit", "--allow-empty", "-m", "initial"])
+ .current_dir(repo_path)
+ .output()
+ .unwrap();
+
+ // Create branches
+ for i in 0..num_branches {
+ Command::new("git")
+ .args(&["branch", &format!("branch-{}", i)])
+ .current_dir(repo_path)
+ .output()
+ .unwrap();
+ }
+
+ // Create worktrees on separate branches
+ for i in 0..num_worktrees {
+ let worktree_path = repo_path.join(format!("wt-{}", i));
+ Command::new("git")
+ .args(&[
+ "worktree",
+ "add",
+ "-b",
+ &format!("wt-branch-{}", i),
+ worktree_path.to_str().unwrap(),
+ ])
+ .current_dir(repo_path)
+ .output()
+ .unwrap();
+ }
+
+ temp_dir
+}
+
+fn bench_completion_switch(c: &mut Criterion) {
+ let mut group = c.benchmark_group("completion_switch");
+
+ // Benchmark with 10 branches
+ group.bench_function("10_branches", |b| {
+ let temp = setup_test_repo(10, 0);
+ b.iter(|| {
+ Command::new("cargo")
+ .args(&["run", "--", "complete", "wt", "switch", ""])
+ .current_dir(temp.path())
+ .output()
+ .unwrap();
+ });
+ });
+
+ // Benchmark with 50 branches
+ group.bench_function("50_branches", |b| {
+ let temp = setup_test_repo(50, 0);
+ b.iter(|| {
+ Command::new("cargo")
+ .args(&["run", "--", "complete", "wt", "switch", ""])
+ .current_dir(temp.path())
+ .output()
+ .unwrap();
+ });
+ });
+
+ // Benchmark with 100 branches
+ group.bench_function("100_branches", |b| {
+ let temp = setup_test_repo(100, 0);
+ b.iter(|| {
+ Command::new("cargo")
+ .args(&["run", "--", "complete", "wt", "switch", ""])
+ .current_dir(temp.path())
+ .output()
+ .unwrap();
+ });
+ });
+
+ group.finish();
+}
+
+fn bench_completion_switch_with_worktrees(c: &mut Criterion) {
+ let mut group = c.benchmark_group("completion_switch_filtered");
+
+ // Benchmark with 50 branches, 10 with worktrees (tests filtering performance)
+ group.bench_function("50_branches_10_worktrees", |b| {
+ let temp = setup_test_repo(50, 10);
+ b.iter(|| {
+ Command::new("cargo")
+ .args(&["run", "--", "complete", "wt", "switch", ""])
+ .current_dir(temp.path())
+ .output()
+ .unwrap();
+ });
+ });
+
+ group.finish();
+}
+
+fn bench_completion_push(c: &mut Criterion) {
+ let mut group = c.benchmark_group("completion_push");
+
+ // Benchmark push completion (shows all branches, no filtering)
+ group.bench_function("100_branches", |b| {
+ let temp = setup_test_repo(100, 0);
+ b.iter(|| {
+ Command::new("cargo")
+ .args(&["run", "--", "complete", "wt", "push", ""])
+ .current_dir(temp.path())
+ .output()
+ .unwrap();
+ });
+ });
+
+ group.finish();
+}
+
+criterion_group!(
+ benches,
+ bench_completion_switch,
+ bench_completion_switch_with_worktrees,
+ bench_completion_push
+);
+criterion_main!(benches);
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index d3d0efbae..49e1eb7e4 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -207,3 +207,141 @@ fn test_init_fish_includes_no_file_flag() {
// Check that completions include -f flag
assert!(stdout.contains("-f -a '(__wt_complete)'"));
}
+
+#[test]
+fn test_completion_command_zsh() {
+ let mut cmd = Command::cargo_bin("wt").unwrap();
+ let output = cmd.arg("completion").arg("zsh").output().unwrap();
+
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+
+ // Check for Zsh completion structure
+ assert!(stdout.contains("_wt"));
+ assert!(stdout.contains("compdef"));
+}
+
+#[test]
+fn test_complete_base_flag_short_form() {
+ let temp = TestRepo::new();
+ temp.commit("initial");
+
+ // Create branches
+ StdCommand::new("git")
+ .args(&["branch", "develop"])
+ .current_dir(temp.root_path())
+ .output()
+ .unwrap();
+
+ // Test completion for -b flag (short form of --base)
+ let mut cmd = Command::cargo_bin("wt").unwrap();
+ let output = cmd
+ .current_dir(temp.root_path())
+ .args(&[
+ "complete",
+ "wt",
+ "switch",
+ "--create",
+ "new-branch",
+ "-b",
+ "",
+ ])
+ .output()
+ .unwrap();
+
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ let branches: Vec<&str> = stdout.lines().collect();
+
+ // Should show all branches as potential base
+ assert!(branches.iter().any(|b| b.contains("develop")));
+}
+
+#[test]
+fn test_complete_empty_repo_returns_empty() {
+ let temp = TestRepo::new();
+ // No commits, no branches
+
+ // Test completion in empty repo
+ let mut cmd = Command::cargo_bin("wt").unwrap();
+ let output = cmd
+ .current_dir(temp.root_path())
+ .args(&["complete", "wt", "switch", ""])
+ .output()
+ .unwrap();
+
+ // Should succeed but return no branches
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ assert_eq!(stdout.trim(), "");
+}
+
+#[test]
+fn test_complete_with_partial_prefix() {
+ let temp = TestRepo::new();
+ temp.commit("initial");
+
+ // Create branches with common prefix
+ StdCommand::new("git")
+ .args(&["branch", "feature/one"])
+ .current_dir(temp.root_path())
+ .output()
+ .unwrap();
+
+ StdCommand::new("git")
+ .args(&["branch", "feature/two"])
+ .current_dir(temp.root_path())
+ .output()
+ .unwrap();
+
+ StdCommand::new("git")
+ .args(&["branch", "hotfix/bug"])
+ .current_dir(temp.root_path())
+ .output()
+ .unwrap();
+
+ // Complete with partial prefix - should return all branches
+ // (shell completion framework handles the prefix filtering)
+ let mut cmd = Command::cargo_bin("wt").unwrap();
+ let output = cmd
+ .current_dir(temp.root_path())
+ .args(&["complete", "wt", "switch", "feat"])
+ .output()
+ .unwrap();
+
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+
+ // Should return all branches, not just those matching "feat"
+ // The shell will filter based on user input
+ assert!(stdout.contains("feature/one"));
+ assert!(stdout.contains("feature/two"));
+ assert!(stdout.contains("hotfix/bug"));
+}
+
+#[test]
+fn test_complete_switch_no_available_branches() {
+ let mut temp = TestRepo::new();
+ temp.commit("initial");
+
+ // Create two branches, both with worktrees - this should result in no available branches
+ temp.add_worktree("feature-worktree", "feature/new");
+ temp.add_worktree("hotfix-worktree", "hotfix/bug");
+
+ // From the main worktree, test completion - should return empty since both non-main branches have worktrees
+ // and we're currently in the main worktree
+ let mut cmd = Command::cargo_bin("wt").unwrap();
+ let output = cmd
+ .current_dir(temp.root_path())
+ .args(&["complete", "wt", "switch", ""])
+ .output()
+ .unwrap();
+
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+
+ // Should not include branches that have worktrees
+ assert!(!stdout.contains("feature/new"));
+ assert!(!stdout.contains("hotfix/bug"));
+ // May include main if it doesn't have a worktree
+}