Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Create script for Claude Code web to set up (#18)
Maximilian Roos05843d3d1cc2
diff --git a/.gitignore b/.gitignoreindex f829c04d5..c2f13b5fa 100644--- a/.gitignore+++ b/.gitignore@@ -3,3 +3,7 @@# Lychee link checker cache.lycheecachetest-concurrent.sh++# Insta snapshot test artifacts+*.snap.new+*.snap.pendingdiff --git a/CLAUDE.md b/CLAUDE.mdindex 892ed7fad..0edafabea 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -32,6 +32,33 @@ Example of escalating instead of suppressing:fn parse_config() { ... }```+## Testing++### Running Tests++```bash+# Unit tests (fast, ~200 tests)+cargo test --lib --bins++# Integration tests (~360 tests, requires bash/zsh/fish shells)+cargo test --test integration++# Run all tests via pre-merge hook (recommended before committing)+cargo run -- beta run-hook pre-merge+```++The pre-merge hook runs the full test suite and is the recommended way to verify changes before committing.++### Claude Code Web Environment++When working in Claude Code web, run the setup script first:++```bash+./scripts/setup-claude-code-web.sh+```++This installs required shells (zsh, fish) and builds the project. The permission tests (`test_permission_error_prevents_save`, `test_approval_prompt_permission_error`) automatically skip when running as root, which is common in containerized environments.+### CLI Flag DescriptionsKeep the first line of flag and argument descriptions brief—aim for 3-6 words. Use parenthetical defaults sparingly, only when the default isn't obvious from context.diff --git a/scripts/setup-claude-code-web.sh b/scripts/setup-claude-code-web.shnew file mode 100755index 000000000..5478d02d0--- /dev/null+++ b/scripts/setup-claude-code-web.sh@@ -0,0 +1,189 @@+#!/bin/bash+###############################################################################+# Claude Code Web - Environment Setup Script+###############################################################################+#+# This script prepares a fresh Claude Code web environment for worktrunk+# development. It installs required dependencies but does NOT run tests.+#+# What it does:+# - Verifies Rust toolchain (1.90.0)+# - Installs required shells (zsh, fish) on Debian/Ubuntu+# - Installs GitHub CLI (gh) for working with PRs/issues+# - Builds the project+#+# After running this script, run tests with:+# cargo test --lib --bins # Unit tests+# cargo test --test integration # Integration tests+# cargo run -- beta run-hook pre-merge # All tests (via pre-merge hook)+#+# Usage:+# ./scripts/setup-claude-code-web.sh+#+###############################################################################++set -e # Exit on error++echo "========================================"+echo "Claude Code Web - Worktrunk Setup"+echo "========================================"+echo ""++# Colors for output+GREEN='\033[0;32m'+YELLOW='\033[1;33m'+RED='\033[0;31m'+NC='\033[0m' # No Color++# Function to print status messages+print_status() {+ echo -e "${GREEN}✓${NC} $1"+}++print_warning() {+ echo -e "${YELLOW}⚠${NC} $1"+}++print_error() {+ echo -e "${RED}✗${NC} $1"+}++# Check if we're in the right directory+if [ ! -f "Cargo.toml" ] || ! grep -q "name = \"worktrunk\"" Cargo.toml; then+ print_error "Error: Must be run from worktrunk project root"+ exit 1+fi++print_status "Found worktrunk project"++# Check Rust installation+echo ""+echo "Checking Rust toolchain..."+if ! command -v cargo &> /dev/null; then+ print_error "Cargo not found. Installing Rust..."+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y+ source "$HOME/.cargo/env"+fi++RUST_VERSION=$(rustc --version | awk '{print $2}')+print_status "Rust version: $RUST_VERSION"++# Check required Rust version from rust-toolchain.toml+REQUIRED_VERSION=$(grep 'channel' rust-toolchain.toml | cut -d'"' -f2)+if [ "$RUST_VERSION" != "$REQUIRED_VERSION" ]; then+ print_warning "Expected Rust $REQUIRED_VERSION, but found $RUST_VERSION"+ echo " rustup should automatically use the correct version from rust-toolchain.toml"+fi++# Check and install shells+echo ""+echo "Checking shells for integration tests..."+SHELLS_AVAILABLE=()+SHELLS_MISSING=()++for shell in bash zsh fish; do+ if command -v "$shell" &> /dev/null; then+ SHELLS_AVAILABLE+=("$shell")+ print_status "$shell is available"+ else+ SHELLS_MISSING+=("$shell")+ fi+done++# Install missing shells+if [ ${#SHELLS_MISSING[@]} -gt 0 ]; then+ echo ""+ echo "Installing missing shells: ${SHELLS_MISSING[*]}"++ # Check if we can use apt-get (Debian/Ubuntu)+ if command -v apt-get &> /dev/null; then+ # Install quietly+ export DEBIAN_FRONTEND=noninteractive+ apt-get update -qq 2>&1 | grep -v "Failed to fetch" || true+ apt-get install -y -qq "${SHELLS_MISSING[@]}" 2>&1 | tail -5 || {+ print_warning "Could not install shells: ${SHELLS_MISSING[*]}"+ echo " Some integration tests will fail"+ }+ else+ print_warning "Package manager not found, cannot install shells: ${SHELLS_MISSING[*]}"+ echo " Some integration tests will fail"+ fi++ # Re-check which shells are now available+ SHELLS_AVAILABLE=()+ SHELLS_MISSING=()+ for shell in bash zsh fish; do+ if command -v "$shell" &> /dev/null; then+ SHELLS_AVAILABLE+=("$shell")+ print_status "$shell is now available"+ else+ SHELLS_MISSING+=("$shell")+ print_warning "$shell installation failed"+ fi+ done+fi++# Install GitHub CLI (gh)+echo ""+echo "Installing GitHub CLI..."+if command -v gh &> /dev/null; then+ print_status "gh already installed"+else+ GH_VERSION="2.63.2"+ ARCH="linux_amd64"+ URL="https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_${ARCH}.tar.gz"++ mkdir -p ~/bin+ TEMP=$(mktemp -d)+ curl -fsSL "$URL" | tar -xz -C "$TEMP"+ mv "$TEMP/gh_${GH_VERSION}_${ARCH}/bin/gh" ~/bin/gh+ chmod +x ~/bin/gh+ rm -rf "$TEMP"++ export PATH="$HOME/bin:$PATH"+ print_status "gh installed to ~/bin/gh"+fi++# Build the project+echo ""+echo "Building worktrunk..."+if cargo build 2>&1 | tail -5; then+ print_status "Build successful"+else+ print_error "Build failed"+ exit 1+fi++# Summary+echo ""+echo "========================================"+echo "Setup Summary"+echo "========================================"+print_status "Environment is ready for development"+print_status "Rust toolchain: $RUST_VERSION"+print_status "Build: OK"+print_status "Shells available: ${SHELLS_AVAILABLE[*]}"+if command -v gh &> /dev/null; then+ print_status "GitHub CLI (gh) installed"+fi++if [ ${#SHELLS_MISSING[@]} -gt 0 ]; then+ echo ""+ print_warning "Some shells not installed: ${SHELLS_MISSING[*]}"+ echo " (Tests for these shells will fail)"+fi++echo ""+echo "========================================"+echo "Next Steps"+echo "========================================"+echo "Run tests:"+echo " cargo test --lib --bins # Unit tests"+echo " cargo test --test integration # Integration tests"+echo " cargo run -- beta run-hook pre-merge # All tests (via pre-merge hook)"+echo ""+echo "Or start developing:"+echo " cargo run -- --help # Run worktrunk CLI"+echo " ./target/debug/wt list # Try a command"+echo ""+print_status "Setup complete!"diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex cc47e628d..af8169475 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -170,6 +170,10 @@ impl TestRepo {cmd.env("LANG", "C");// Oct 28, 2025 - exactly 300 days (10 months) after commit date for deterministic relative timescmd.env("SOURCE_DATE_EPOCH", "1761609600");+ // Disable git advice hints for stable output across versions+ cmd.env("GIT_CONFIG_COUNT", "1");+ cmd.env("GIT_CONFIG_KEY_0", "advice.mergeConflict");+ cmd.env("GIT_CONFIG_VALUE_0", "false");}/// Get standard test environment variables as a vector@@ -193,6 +197,10 @@ impl TestRepo {("LC_ALL".to_string(), "C".to_string()),("LANG".to_string(), "C".to_string()),("SOURCE_DATE_EPOCH".to_string(), "1761609600".to_string()),+ // Disable git advice hints for stable output across versions+ ("GIT_CONFIG_COUNT".to_string(), "1".to_string()),+ ("GIT_CONFIG_KEY_0".to_string(), "advice.mergeConflict".to_string()),+ ("GIT_CONFIG_VALUE_0".to_string(), "false".to_string()),("WORKTRUNK_CONFIG_PATH".to_string(),self.test_config_path().display().to_string(),diff --git a/tests/integration_tests/approval_pty.rs b/tests/integration_tests/approval_pty.rsindex 116724e95..3d3f22265 100644--- a/tests/integration_tests/approval_pty.rs+++ b/tests/integration_tests/approval_pty.rs@@ -6,6 +6,10 @@//! Note: These tests are separate from `approval_ui.rs` because they require PTY setup//! to simulate interactive terminals. The non-PTY tests in `approval_ui.rs` verify the//! error case (non-TTY environments).+//!+//! TODO: PTY snapshots show environment-specific linebreak variations due to timing-dependent+//! buffering of input/output interleaving. Consider normalizing extra blank lines to make+//! snapshots more stable across different environments (local vs CI vs Claude Code web).use crate::common::TestRepo;use insta::assert_snapshot;@@ -182,6 +186,8 @@ fn test_approval_prompt_multiple_commands() {assert_snapshot!("approval_prompt_multiple_commands", normalized);}+/// TODO: Find a way to test permission errors without skipping when running as root.+/// See test_permission_error_prevents_save in approval_save.rs for details.#[test]fn test_approval_prompt_permission_error() {let repo = TestRepo::new();@@ -197,12 +203,22 @@ fn test_approval_prompt_permission_error() {use std::os::unix::fs::PermissionsExt;// Create the config file first- fs::write(config_path, "# read-only config\n").unwrap();+ fs::write(&config_path, "# read-only config\n").unwrap();// Make it read-only- let mut perms = fs::metadata(config_path).unwrap().permissions();+ let mut perms = fs::metadata(&config_path).unwrap().permissions();perms.set_mode(0o444); // Read-only- fs::set_permissions(config_path, perms).unwrap();+ fs::set_permissions(&config_path, perms).unwrap();++ // Test if permissions actually restrict us (skip if running as root)+ if fs::write(&config_path, "test write").is_ok() {+ // Running as root - restore permissions and skip test+ let mut perms = fs::metadata(&config_path).unwrap().permissions();+ perms.set_mode(0o644);+ fs::set_permissions(&config_path, perms).unwrap();+ eprintln!("Skipping permission test - running with elevated privileges");+ return;+ }}let env_vars = repo.test_env_vars();diff --git a/tests/integration_tests/approval_save.rs b/tests/integration_tests/approval_save.rsindex a607c72e5..f57e3ca0d 100644--- a/tests/integration_tests/approval_save.rs+++ b/tests/integration_tests/approval_save.rs@@ -276,6 +276,11 @@ fn test_force_flag_saves_to_new_config_file() {/// are denied. The higher-level `approve_command_batch()` catches this error and/// displays a warning (see src/commands/command_approval.rs:82-85), allowing/// commands to execute even when the approval can't be saved.+///+/// TODO: Find a way to test permission errors without skipping when running as root.+/// Currently skips in containerized environments (Claude Code web, Docker) where+/// root can write to read-only files. Consider using capabilities or other mechanisms+/// to test permission handling in all environments.#[test]fn test_permission_error_prevents_save() {use std::fs::Permissions;@@ -297,6 +302,21 @@ fn test_permission_error_prevents_save() {fs::set_permissions(config_dir, readonly_perms).unwrap();}+ // Test if permissions actually restrict us (skip if running as root)+ // Root can write to read-only directories, so the test would be meaningless+ let test_file = config_dir.join("test_write");+ if fs::write(&test_file, "test").is_ok() {+ // Running as root or permissions don't work+ // Restore write permissions and skip test+ #[cfg(unix)]+ {+ let writable_perms = Permissions::from_mode(0o755);+ fs::set_permissions(config_dir, writable_perms).unwrap();+ }+ eprintln!("Skipping permission test - running with elevated privileges");+ return;+ }+// Try to save a new approval - this should faillet mut config = WorktrunkConfig::default();let result = config.approve_command_to(diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snapindex 7a998bd94..617293aa1 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap@@ -3,13 +3,13 @@ source: tests/integration_tests/approval_pty.rsexpression: normalized---y-🟡 [33m[1m[33mtest-repo[0m[33m needs approval to execute [1m[33m1[0m[33m command:[0m🔄 post-create:[40m [0m [1m[34mecho[0m [32m'test command'[0m[0m💡 Allow and remember? [1m[y/N][0m+🔄 [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'test command'[0m[0m[0mtest commanddiff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snapindex 8aca362b5..f07215dd7 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap@@ -3,13 +3,13 @@ source: tests/integration_tests/approval_pty.rsexpression: normalized---n-🟡 [33m[1m[33mtest-repo[0m[33m needs approval to execute [1m[33m1[0m[33m command:[0m🔄 post-create:[40m [0m [1m[34mecho[0m [32m'test command'[0m[0m💡 Allow and remember? [1m[y/N][0m+⚪ Commands declined, continuing worktree creation✅ [32mCreated new worktree for [1m[32mtest-decline[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO]/test-repo.test-decline[0m[0m💡 [2mTo enable automatic cd, run: wt config shell[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snapindex 9be8f95a0..9e794fde2 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap@@ -3,7 +3,6 @@ source: tests/integration_tests/approval_pty.rsexpression: normalized---y-🟡 [33m[1m[33mtest-repo[0m[33m needs approval to execute [1m[33m2[0m[33m commands:[0m🔄 post-create:@@ -13,6 +12,7 @@ y[40m [0m [1m[34mecho[0m [32m'Third command'[0m[0m💡 Allow and remember? [1m[y/N][0m+🔄 [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'First command'[0m[0m[0mFirst commanddiff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snapindex 3f4b7eaf4..1306251b5 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap@@ -3,7 +3,6 @@ source: tests/integration_tests/approval_pty.rsexpression: normalized---n-🟡 [33m[1m[33mtest-repo[0m[33m needs approval to execute [1m[33m2[0m[33m commands:[0m🔄 post-create:@@ -13,6 +12,7 @@ n[40m [0m [1m[34mecho[0m [32m'Third command'[0m[0m💡 Allow and remember? [1m[y/N][0m+⚪ Commands declined, continuing worktree creation✅ [32mCreated new worktree for [1m[32mtest-mixed-decline[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO]/test-repo.test-mixed-decline[0m[0m💡 [2mTo enable automatic cd, run: wt config shell[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snapindex ad9c09961..8a8154193 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap@@ -3,7 +3,6 @@ source: tests/integration_tests/approval_pty.rsexpression: normalized---y-🟡 [33m[1m[33mtest-repo[0m[33m needs approval to execute [1m[33m3[0m[33m commands:[0m🔄 post-create:@@ -16,6 +15,7 @@ y[40m [0m [1m[34mecho[0m [32m'Third command'[0m[0m💡 Allow and remember? [1m[y/N][0m+🔄 [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'First command'[0m[0m[0mFirst commanddiff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snapindex fcf7362ca..ab262fbfa 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap@@ -3,7 +3,6 @@ source: tests/integration_tests/approval_pty.rsexpression: normalized---y-🟡 [33m[1m[33mtest-repo[0m[33m needs approval to execute [1m[33m3[0m[33m commands:[0m🔄 post-create [1minstall[0m:@@ -16,6 +15,7 @@ y[40m [0m [1m[34mecho[0m [32m'Running tests...'[0m[0m💡 Allow and remember? [1m[y/N][0m+🔄 [36mRunning post-create [1minstall[0m:[0m[40m [0m [1m[34mecho[0m [32m'Installing dependencies...'[0m[0m[0mInstalling dependencies...diff --git a/tests/snapshots/integration__integration_tests__merge__merge_rebase_conflict.snap b/tests/snapshots/integration__integration_tests__merge__merge_rebase_conflict.snapindex bdf78f5e1..fc55d12c6 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_rebase_conflict.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_rebase_conflict.snap@@ -10,12 +10,16 @@ info:COLUMNS: "150"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_COUNT: "1"GIT_CONFIG_GLOBAL: /dev/null+ GIT_CONFIG_KEY_0: advice.mergeConflictGIT_CONFIG_SYSTEM: /dev/null+ GIT_CONFIG_VALUE_0: "false"+ GIT_EDITOR: ""LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpuWtNMC/test-config.toml+ WORKTRUNK_CONFIG_PATH: /tmp/.tmpScvSwv/test-config.toml---success: falseexit_code: 1@@ -28,8 +32,7 @@ exit_code: 1[40m [0m hint: "git add/rm <conflicted_files>", then run "git rebase --continue".[40m [0m hint: You can instead skip this commit: run "git rebase --skip".[40m [0m hint: To abort and get back to the state before "git rebase", run "git rebase --abort".-[40m [0m hint: Disable this message with "git config set advice.mergeConflict false"-[40m [0m Could not apply [SHA]... # Update shared.txt in feature+[40m [0m Could not apply [SHA]... Update shared.txt in feature----- stderr -----