Skip to content

armgit / agtx

Public Imported from GitHub
0

πŸ„πŸΌβ€β™‚οΈ The blackboard for coding agents - agentic development environment for claude code, codex, cursor, opencode, grok and more.

chore: add worktree tests

fynnfluegge55b4420d30ae
diff --git a/CLAUDE.md b/CLAUDE.md
index 93fb599..d0cb429 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1,6 +1,6 @@
# AGTX - Terminal Kanban for Coding Agents
-A terminal-native kanban board for managing multiple coding agent sessions (Claude Code, Aider, etc.) with isolated git worktrees.
+A terminal-native kanban board for managing multiple coding agent sessions (Claude Code, Codex, etc.) with isolated git worktrees.
## Quick Start
@@ -20,6 +20,7 @@ cargo build --release
```
src/
β”œβ”€β”€ main.rs # Entry point, CLI arg parsing, AppMode enum
+β”œβ”€β”€ lib.rs # Module exports for integration tests
β”œβ”€β”€ tui/
β”‚ β”œβ”€β”€ mod.rs # Re-exports
β”‚ β”œβ”€β”€ app.rs # Main App struct, event loop, rendering (largest file)
@@ -36,8 +37,16 @@ src/
β”‚ └── worktree.rs # Git worktree create/remove/list
β”œβ”€β”€ agent/
β”‚ └── mod.rs # Agent definitions, detection, spawn args
-└── config/
- └── mod.rs # GlobalConfig, ProjectConfig, ThemeConfig, MergedConfig
+β”œβ”€β”€ config/
+β”‚ └── mod.rs # GlobalConfig, ProjectConfig, ThemeConfig
+└── operations.rs # Traits for tmux/git operations (for testing)
+
+tests/
+β”œβ”€β”€ db_tests.rs # Database and model tests
+β”œβ”€β”€ config_tests.rs # Configuration tests
+β”œβ”€β”€ board_tests.rs # Board navigation tests
+β”œβ”€β”€ git_tests.rs # Git worktree tests
+└── workflow_tests.rs # Task workflow tests
```
## Key Concepts
@@ -46,21 +55,21 @@ src/
```
Backlog β†’ Planning β†’ Running β†’ Review β†’ Done
↓ ↓ ↓ ↓
- worktree Claude PR opens cleanup
- + Claude working (can (keep
- planning resume) branch)
+ worktree Claude optional cleanup
+ + Claude working PR (keep
+ planning (resume) branch)
```
- **Backlog**: Task ideas, not started
- **Planning**: Creates git worktree at `.agtx/worktrees/{slug}`, starts Claude Code in planning mode
- **Running**: Claude is implementing (sends "proceed with implementation")
-- **Review**: PR is opened. Can move back to Running to address feedback (resumes Claude session)
-- **Done**: PR merged/closed, cleanup worktree + tmux (branch kept for potential reopen)
+- **Review**: Optionally create PR. Tmux window stays open. Can resume to address feedback
+- **Done**: Cleanup worktree + tmux window (branch kept locally)
-### Claude Session Resume
-- When Claude starts, session is renamed with `/rename {task_id}`
-- When resuming from Review β†’ Running, uses `claude --resume {task_id}`
-- This preserves full conversation context across task lifecycle
+### Session Persistence
+- Tmux window stays open when moving Running β†’ Review
+- Resume from Review simply changes status back to Running (window already exists)
+- No special Claude resume logic needed - the session just stays alive in tmux
### Database Storage
All databases stored centrally (not in project directories):
@@ -72,21 +81,46 @@ Structure:
- `projects/{hash}.db` - Per-project task database (hash of project path)
### Tmux Architecture
-- All agent sessions run in tmux server named `agtx` (`tmux -L agtx`)
-- Window naming: `{project}:task-{title_slug}`
+```
+β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
+β”‚ tmux server "agtx" β”‚
+β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
+β”‚ β”‚ Session: "my-project" β”‚ β”‚
+β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
+β”‚ β”‚ β”‚Window: β”‚ β”‚Window: β”‚ β”‚Window: β”‚ β”‚ β”‚
+β”‚ β”‚ β”‚task2 β”‚ β”‚task3 β”‚ β”‚task4 β”‚ β”‚ β”‚
+β”‚ β”‚ β”‚(Claude)β”‚ β”‚(Claude)β”‚ β”‚(Claude)β”‚ β”‚ β”‚
+β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
+β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
+β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
+β”‚ β”‚ Session: "other-project" β”‚ β”‚
+β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
+β”‚ β”‚ β”‚ Window: β”‚ β”‚ β”‚
+β”‚ β”‚ β”‚ some_other_task β”‚ β”‚ β”‚
+β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
+β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
+β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
+```
+
+- **Server**: Dedicated tmux server named `agtx` (`tmux -L agtx`)
+- **Sessions**: Each project gets its own session (named after project)
+- **Windows**: Each task gets its own window within the project's session
- Separate from user's regular tmux sessions
-- View sessions: `tmux -L agtx list-windows`
+- View sessions: `tmux -L agtx list-windows -a`
+- Attach: `tmux -L agtx attach`
### Theme Configuration
Colors configurable via `~/.config/agtx/config.toml`:
```toml
[theme]
-color_selected = "#FFFF99" # Selected elements (light yellow)
-color_normal = "#00FFFF" # Normal borders (cyan)
-color_dimmed = "#666666" # Inactive elements (gray)
-color_text = "#FFFFFF" # Text (white)
-color_accent = "#00FFFF" # Accents (cyan)
-color_description = "#E8909C" # Task descriptions (rose)
+color_selected = "#FFFF99" # Selected elements (light yellow)
+color_normal = "#00FFFF" # Normal borders (cyan)
+color_dimmed = "#666666" # Inactive elements (gray)
+color_text = "#FFFFFF" # Text (white)
+color_accent = "#00FFFF" # Accents (cyan)
+color_description = "#E8909C" # Task descriptions (rose)
+color_popup_border = "#00FF00" # Popup borders (green)
+color_popup_header = "#00FFFF" # Popup headers (cyan)
```
## Keyboard Shortcuts
@@ -97,9 +131,8 @@ color_description = "#E8909C" # Task descriptions (rose)
| `h/l` or arrows | Move between columns |
| `j/k` or arrows | Move between tasks |
| `o` | Create new task |
-| `Enter` | Open task popup (tmux view) |
-| `i` | Edit task (backlog only) |
-| `x` | Delete task |
+| `Enter` | Open task popup (tmux view) / Edit task (backlog) |
+| `x` | Delete task (with confirmation) |
| `d` | Show git diff for task |
| `m` | Move task forward (advance workflow) |
| `r` | Resume task (Review β†’ Running) |
@@ -110,9 +143,10 @@ color_description = "#E8909C" # Task descriptions (rose)
### Task Popup (tmux view)
| Key | Action |
|-----|--------|
-| `Ctrl+j/k` | Scroll up/down |
+| `Ctrl+j/k` or `Ctrl+n/p` | Scroll up/down |
+| `Ctrl+d/u` | Page down/up |
| `Ctrl+g` | Jump to bottom |
-| `Ctrl+q` | Close popup |
+| `Ctrl+q` or `Esc` | Close popup |
| Other keys | Forwarded to tmux/Claude |
### PR Creation Popup
@@ -122,6 +156,14 @@ color_description = "#E8909C" # Task descriptions (rose)
| `Ctrl+s` | Create PR and move to Review |
| `Esc` | Cancel |
+### Task Edit (Description)
+| Key | Action |
+|-----|--------|
+| `#` | Start file search (fuzzy find) |
+| `\` + Enter | Line continuation (multi-line) |
+| Arrow keys | Move cursor |
+| `Home/End` | Jump to start/end |
+
## Code Patterns
### Ratatui TUI
@@ -149,12 +191,18 @@ color_description = "#E8909C" # Task descriptions (rose)
### Claude Integration
- Uses `--dangerously-skip-permissions` flag
- Polls tmux pane for "Yes, I accept" prompt before sending acceptance
-- Sends `/rename {task_id}` after Claude starts for session resume capability
-## Building
+## Building & Testing
```bash
+# Build
cargo build --release
+
+# Run tests
+cargo test
+
+# Run tests with mock support
+cargo test --features test-mocks
```
Dependencies require:
@@ -165,12 +213,6 @@ Dependencies require:
- gh CLI (for PR operations)
- claude CLI (Claude Code)
-## Testing
-
-```bash
-cargo test
-```
-
## Common Tasks
### Adding a new task field
@@ -197,12 +239,20 @@ cargo test
### Adding a new popup
1. Add state struct (e.g., `MyPopup`) in app.rs
2. Add `Option<MyPopup>` field to `AppState`
-3. Add rendering in `draw_board()` function
-4. Add key handler function `handle_my_popup_key()`
-5. Add check in `handle_key()` to route to handler
+3. Initialize to `None` in `App::new()`
+4. Add rendering in `draw_board()` function
+5. Add key handler function `handle_my_popup_key()`
+6. Add check in `handle_key()` to route to handler
+
+## Planning Docs
+
+See `docs/planning/` for future enhancements:
+- `codex-cli-integration.md` - Plan for Codex CLI agent support
+- `dependency-injection-testing.md` - Plan for improved test coverage
+- `tmux-popup-focus-bug.md` - Known issue with tmux attachment
## Future Enhancements
- Auto-detect Claude idle status (show spinner when working)
- Reopen Done tasks (recreate worktree from preserved branch)
-- Support for additional agents (Aider, Codex)
+- Support for additional agents (Aider, Codex, GitHub Copilot CLI)
- Notification when Claude finishes work
diff --git a/src/agent/mod.rs b/src/agent/mod.rs
index c86f466..b7c26e6 100644
--- a/src/agent/mod.rs
+++ b/src/agent/mod.rs
@@ -1,4 +1,3 @@
-use anyhow::Result;
use serde::{Deserialize, Serialize};
/// Known coding agents that agtx can work with
@@ -111,28 +110,3 @@ pub fn build_spawn_args(agent: &Agent, prompt: &str, task_id: &str) -> Vec<Strin
args
}
-
-/// Build command for resuming an agent session
-pub fn build_resume_args(agent: &Agent, task_id: &str) -> Result<Vec<String>> {
- let mut args = agent.args.clone();
-
- match agent.name.as_str() {
- "claude" => {
- // Claude Code supports --resume
- args.extend([
- "--resume".to_string(),
- "--session".to_string(),
- task_id.to_string(),
- ]);
- }
- "aider" => {
- // Aider auto-resumes from .aider.chat.history.md in the directory
- // No special flags needed
- }
- _ => {
- anyhow::bail!("Agent '{}' does not support session resumption", agent.name);
- }
- }
-
- Ok(args)
-}
diff --git a/src/git/worktree.rs b/src/git/worktree.rs
index c156632..45d121b 100644
--- a/src/git/worktree.rs
+++ b/src/git/worktree.rs
@@ -197,18 +197,3 @@ impl WorktreeInfo {
})
}
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn test_worktree_path() {
- let project = PathBuf::from("/home/user/project");
- let path = worktree_path(&project, "task-123");
- assert_eq!(
- path,
- PathBuf::from("/home/user/project/.agtx/worktrees/task-123")
- );
- }
-}
diff --git a/src/tmux/mod.rs b/src/tmux/mod.rs
index e28c82d..275fd58 100644
--- a/src/tmux/mod.rs
+++ b/src/tmux/mod.rs
@@ -155,20 +155,3 @@ impl SessionInfo {
self.name.split("--").nth(1)
}
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn test_session_info_parsing() {
- let info = SessionInfo {
- name: "task-abc12345--my-project--fix-auth".to_string(),
- last_activity: 0,
- created: 0,
- };
-
- assert_eq!(info.task_id(), Some("abc12345"));
- assert_eq!(info.project_name(), Some("my-project"));
- }
-}
diff --git a/tests/git_tests.rs b/tests/git_tests.rs
new file mode 100644
index 0000000..b53fff6
--- /dev/null
+++ b/tests/git_tests.rs
@@ -0,0 +1,409 @@
+use agtx::git;
+use std::path::PathBuf;
+use std::process::Command;
+use tempfile::TempDir;
+
+// =============================================================================
+// Pure function tests (no git repo needed)
+// =============================================================================
+
+#[test]
+fn test_worktree_path() {
+ let project = PathBuf::from("/home/user/project");
+ let path = git::worktree_path(&project, "task-123");
+ assert_eq!(
+ path,
+ PathBuf::from("/home/user/project/.agtx/worktrees/task-123")
+ );
+}
+
+#[test]
+fn test_worktree_path_with_special_chars() {
+ let project = PathBuf::from("/home/user/my-project");
+ let path = git::worktree_path(&project, "fix-bug-456");
+ assert_eq!(
+ path,
+ PathBuf::from("/home/user/my-project/.agtx/worktrees/fix-bug-456")
+ );
+}
+
+#[test]
+fn test_worktree_path_nested_project() {
+ let project = PathBuf::from("/home/user/projects/rust/agtx");
+ let path = git::worktree_path(&project, "feature-abc");
+ assert_eq!(
+ path,
+ PathBuf::from("/home/user/projects/rust/agtx/.agtx/worktrees/feature-abc")
+ );
+}
+
+#[test]
+fn test_worktree_exists_false_for_nonexistent() {
+ let temp_dir = TempDir::new().unwrap();
+ assert!(!git::worktree_exists(temp_dir.path(), "nonexistent-task"));
+}
+
+#[test]
+fn test_worktree_info_task_id() {
+ let info = git::WorktreeInfo {
+ path: PathBuf::from("/project/.agtx/worktrees/task-123"),
+ branch: Some("task/task-123".to_string()),
+ is_bare: false,
+ };
+ assert_eq!(info.task_id(), Some("task-123"));
+}
+
+#[test]
+fn test_worktree_info_task_id_not_agtx_worktree() {
+ // A worktree not in the .agtx/worktrees directory should return None
+ let info = git::WorktreeInfo {
+ path: PathBuf::from("/project/other-worktree"),
+ branch: Some("feature-branch".to_string()),
+ is_bare: false,
+ };
+ assert_eq!(info.task_id(), None);
+}
+
+#[test]
+fn test_worktree_info_bare() {
+ let info = git::WorktreeInfo {
+ path: PathBuf::from("/project"),
+ branch: None,
+ is_bare: true,
+ };
+ assert!(info.is_bare);
+ assert!(info.branch.is_none());
+}
+
+// =============================================================================
+// Integration tests (require git)
+// =============================================================================
+
+fn setup_git_repo() -> TempDir {
+ let temp_dir = TempDir::new().unwrap();
+
+ // Initialize git repo
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["init"])
+ .output()
+ .expect("Failed to init git repo");
+
+ // Configure git user for commits
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["config", "user.email", "[email protected]"])
+ .output()
+ .expect("Failed to config git email");
+
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["config", "user.name", "Test User"])
+ .output()
+ .expect("Failed to config git name");
+
+ // Create initial commit (needed for worktrees)
+ std::fs::write(temp_dir.path().join("README.md"), "# Test").unwrap();
+
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["add", "."])
+ .output()
+ .expect("Failed to add files");
+
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["commit", "-m", "Initial commit"])
+ .output()
+ .expect("Failed to commit");
+
+ // Rename branch to main (in case default is master)
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["branch", "-M", "main"])
+ .output()
+ .expect("Failed to rename branch");
+
+ temp_dir
+}
+
+#[test]
+fn test_is_git_repo_true() {
+ let temp_dir = setup_git_repo();
+ assert!(git::is_git_repo(temp_dir.path()));
+}
+
+#[test]
+fn test_is_git_repo_false() {
+ let temp_dir = TempDir::new().unwrap();
+ assert!(!git::is_git_repo(temp_dir.path()));
+}
+
+#[test]
+fn test_repo_root() {
+ let temp_dir = setup_git_repo();
+ let root = git::repo_root(temp_dir.path()).unwrap();
+ // Canonicalize both paths to handle macOS /var -> /private/var symlink
+ let expected = temp_dir.path().canonicalize().unwrap();
+ let actual = root.canonicalize().unwrap();
+ assert_eq!(actual, expected);
+}
+
+#[test]
+fn test_current_branch() {
+ let temp_dir = setup_git_repo();
+ let branch = git::current_branch(temp_dir.path()).unwrap();
+ assert_eq!(branch, "main");
+}
+
+#[test]
+fn test_create_and_remove_worktree() {
+ let temp_dir = setup_git_repo();
+
+ // Create worktree
+ let worktree_path = git::create_worktree(temp_dir.path(), "test-task").unwrap();
+
+ // Verify it exists
+ assert!(worktree_path.exists());
+ assert!(worktree_path.join(".git").exists());
+ assert!(git::worktree_exists(temp_dir.path(), "test-task"));
+
+ // List worktrees should include it
+ let worktrees = git::list_worktrees(temp_dir.path()).unwrap();
+ assert!(worktrees.len() >= 2); // main + our worktree
+
+ // Canonicalize paths to handle macOS /var -> /private/var symlink
+ let worktree_path_canonical = worktree_path.canonicalize().unwrap();
+ let task_worktree = worktrees.iter().find(|w| {
+ w.path.canonicalize().ok() == Some(worktree_path_canonical.clone())
+ });
+ assert!(task_worktree.is_some());
+ assert_eq!(task_worktree.unwrap().branch, Some("task/test-task".to_string()));
+
+ // Remove worktree
+ git::remove_worktree(temp_dir.path(), "test-task").unwrap();
+
+ // Verify it's gone
+ assert!(!worktree_path.exists());
+}
+
+#[test]
+fn test_create_worktree_idempotent() {
+ let temp_dir = setup_git_repo();
+
+ // Create worktree twice - should succeed both times
+ let path1 = git::create_worktree(temp_dir.path(), "idempotent-task").unwrap();
+ let path2 = git::create_worktree(temp_dir.path(), "idempotent-task").unwrap();
+
+ assert_eq!(path1, path2);
+ assert!(path1.exists());
+}
+
+#[test]
+fn test_list_worktrees_empty_repo() {
+ let temp_dir = setup_git_repo();
+
+ // Should have at least the main worktree
+ let worktrees = git::list_worktrees(temp_dir.path()).unwrap();
+ assert!(!worktrees.is_empty());
+
+ // Main worktree should have branch "main"
+ let main_worktree = worktrees.iter().find(|w| w.branch == Some("main".to_string()));
+ assert!(main_worktree.is_some());
+}
+
+// =============================================================================
+// Error case tests
+// =============================================================================
+
+/// Setup a git repo with "master" as the default branch (instead of "main")
+fn setup_git_repo_with_master() -> TempDir {
+ let temp_dir = TempDir::new().unwrap();
+
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["init"])
+ .output()
+ .expect("Failed to init git repo");
+
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["config", "user.email", "[email protected]"])
+ .output()
+ .expect("Failed to config git email");
+
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["config", "user.name", "Test User"])
+ .output()
+ .expect("Failed to config git name");
+
+ std::fs::write(temp_dir.path().join("README.md"), "# Test").unwrap();
+
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["add", "."])
+ .output()
+ .expect("Failed to add files");
+
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["commit", "-m", "Initial commit"])
+ .output()
+ .expect("Failed to commit");
+
+ // Rename branch to master (not main)
+ Command::new("git")
+ .current_dir(temp_dir.path())
+ .args(["branch", "-M", "master"])
+ .output()
+ .expect("Failed to rename branch");
+
+ temp_dir
+}
+
+#[test]
+fn test_create_worktree_with_master_branch() {
+ let temp_dir = setup_git_repo_with_master();
+
+ // Should detect master and create worktree from it
+ let worktree_path = git::create_worktree(temp_dir.path(), "master-task").unwrap();
+
+ assert!(worktree_path.exists());
+ assert!(worktree_path.join(".git").exists());
+
+ // Verify branch was created
+ let worktrees = git::list_worktrees(temp_dir.path()).unwrap();
+ let task_worktree = worktrees.iter().find(|w| {
+ w.branch == Some("task/master-task".to_string())
+ });
+ assert!(task_worktree.is_some());
+}
+
+#[test]
+fn test_create_worktree_on_non_git_directory() {
+ let temp_dir = TempDir::new().unwrap();
+ // Don't initialize git - just a plain directory
+
+ let result = git::create_worktree(temp_dir.path(), "should-fail");
+
+ assert!(result.is_err());
+}
+
+#[test]
+fn test_remove_worktree_nonexistent() {
+ let temp_dir = setup_git_repo();
+
+ // Removing a non-existent worktree should not panic
+ // (it may return Ok or Err depending on git version, but shouldn't crash)
+ let result = git::remove_worktree(temp_dir.path(), "does-not-exist");
+
+ // The function should complete without panicking
+ // We don't assert success/failure since behavior may vary
+ let _ = result;
+}
+
+#[test]
+fn test_list_worktrees_on_non_git_directory() {
+ let temp_dir = TempDir::new().unwrap();
+ // Don't initialize git
+
+ let result = git::list_worktrees(temp_dir.path());
+
+ // Should return error or empty list, not panic
+ assert!(result.is_err() || result.unwrap().is_empty());
+}
+
+#[test]
+fn test_is_git_repo_nonexistent_path() {
+ let path = PathBuf::from("/nonexistent/path/that/does/not/exist");
+ assert!(!git::is_git_repo(&path));
+}
+
+#[test]
+fn test_current_branch_non_git_directory() {
+ let temp_dir = TempDir::new().unwrap();
+ // Don't initialize git
+
+ let result = git::current_branch(temp_dir.path());
+
+ // Should return error, not panic
+ // Note: git returns empty string for non-git dirs, which might be Ok("")
+ // So we just verify it doesn't panic
+ let _ = result;
+}
+
+#[test]
+fn test_create_multiple_worktrees() {
+ let temp_dir = setup_git_repo();
+
+ // Create multiple worktrees
+ let path1 = git::create_worktree(temp_dir.path(), "task-1").unwrap();
+ let path2 = git::create_worktree(temp_dir.path(), "task-2").unwrap();
+ let path3 = git::create_worktree(temp_dir.path(), "task-3").unwrap();
+
+ assert!(path1.exists());
+ assert!(path2.exists());
+ assert!(path3.exists());
+
+ // All should be different paths
+ assert_ne!(path1, path2);
+ assert_ne!(path2, path3);
+ assert_ne!(path1, path3);
+
+ // List should show all of them
+ let worktrees = git::list_worktrees(temp_dir.path()).unwrap();
+ assert!(worktrees.len() >= 4); // main + 3 tasks
+
+ // Clean up
+ git::remove_worktree(temp_dir.path(), "task-1").unwrap();
+ git::remove_worktree(temp_dir.path(), "task-2").unwrap();
+ git::remove_worktree(temp_dir.path(), "task-3").unwrap();
+
+ assert!(!path1.exists());
+ assert!(!path2.exists());
+ assert!(!path3.exists());
+}
+
+#[test]
+fn test_worktree_with_uncommitted_changes() {
+ let temp_dir = setup_git_repo();
+
+ // Create worktree
+ let worktree_path = git::create_worktree(temp_dir.path(), "dirty-task").unwrap();
+
+ // Make uncommitted changes in the worktree
+ std::fs::write(worktree_path.join("dirty-file.txt"), "uncommitted content").unwrap();
+
+ // Remove should still work (with --force)
+ let result = git::remove_worktree(temp_dir.path(), "dirty-task");
+ assert!(result.is_ok());
+}
+
+#[test]
+fn test_worktree_info_task_id_edge_cases() {
+ // Test with path that has "worktrees" but not ".agtx"
+ let info = git::WorktreeInfo {
+ path: PathBuf::from("/project/worktrees/task-123"),
+ branch: Some("task/task-123".to_string()),
+ is_bare: false,
+ };
+ // Parent is "worktrees" so it should match
+ assert_eq!(info.task_id(), Some("task-123"));
+
+ // Test with deeply nested path
+ let info2 = git::WorktreeInfo {
+ path: PathBuf::from("/a/b/c/.agtx/worktrees/deep-task"),
+ branch: None,
+ is_bare: false,
+ };
+ assert_eq!(info2.task_id(), Some("deep-task"));
+
+ // Test with root path
+ let info3 = git::WorktreeInfo {
+ path: PathBuf::from("/"),
+ branch: None,
+ is_bare: false,
+ };
+ assert_eq!(info3.task_id(), None);
+}