Milestone 2.1: Implement git_worktree_create tool (#4) #17

Merged
david merged 2 commits from issue-4 into main 2026-07-24 20:50:46 +00:00
Owner

Summary

Implements the git_worktree_create tool with full validation and error handling per issue #4 acceptance criteria.

Changes

  • New pi-worktree-create.ts module with pure, testable functions (no pi SDK deps)
  • validateCreateWorktreeInput() — validates path and branch name parameters
  • validatePathDoesNotExist() — refuses if target path exists (injectable for testing)
  • isCurrentBranch() — prevents creating worktree on current branch
  • buildWorktreeAddCommand() — builds correct git command with -b flag support
  • Integrated all helpers into createCreateWorktreeTool() in main extension
  • 17 new tests covering all validation paths and edge cases (29 total, all passing)

Testing

  • All 29 tests pass (bun test .pi/extensions/*.test.ts)
  • Full test suite run with no regressions
  • Manual verification (requires pi runtime)

Checklist

  • Self-reviewed the diff
  • Code follows project conventions
  • Descriptive naming (no single-character variables)
  • Documentation updated (JSDoc on all new functions)
## Summary Implements the `git_worktree_create` tool with full validation and error handling per issue #4 acceptance criteria. ## Changes - New `pi-worktree-create.ts` module with pure, testable functions (no pi SDK deps) - `validateCreateWorktreeInput()` — validates path and branch name parameters - `validatePathDoesNotExist()` — refuses if target path exists (injectable for testing) - `isCurrentBranch()` — prevents creating worktree on current branch - `buildWorktreeAddCommand()` — builds correct git command with `-b` flag support - Integrated all helpers into `createCreateWorktreeTool()` in main extension - 17 new tests covering all validation paths and edge cases (29 total, all passing) ## Testing - [x] All 29 tests pass (`bun test .pi/extensions/*.test.ts`) - [x] Full test suite run with no regressions - [ ] Manual verification (requires pi runtime) ## Checklist - [x] Self-reviewed the diff - [x] Code follows project conventions - [x] Descriptive naming (no single-character variables) - [x] Documentation updated (JSDoc on all new functions)
david added 1 commit 2026-07-24 13:19:12 +00:00
- Add pi-worktree-create.ts with pure validation/command-building functions
- validateCreateWorktreeInput: checks path and branch name validity
- validatePathDoesNotExist: refuses if target path exists (injectable for testing)
- isCurrentBranch: prevents creating worktree on current branch
- buildWorktreeAddCommand: builds correct git command with -b flag support
- Full error messages match issue acceptance criteria exactly
- 17 new tests covering all validation paths and edge cases
david added 1 commit 2026-07-24 20:49:56 +00:00
Critical fixes:
- Align create_branch schema description with runtime default (true)
- Add ^ and . to branch name start-of-name validation regex

Major fixes:
- Move dynamic import('node:fs/promises') to static top-level import
- Add integration tests for git_worktree_create execute flow
- Use WorktreeError + formatValidationError for current-branch error

Minor fixes:
- Replace fragile .toContain() assertions with specific strings
- Add 14 new tests for branch name start/end and dangerous char validation
- Document resolveWorktreeTarget as dead code until switch/remove tools ship

Suggestions implemented:
- Reject leading dot in branch names (git compliance)
- Extract formatSuccessResponse() helper for consistency
david merged commit a18e6fe64a into main 2026-07-24 20:50:46 +00:00
david deleted branch issue-4 2026-07-24 20:50:46 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: david/pi-worktrees#17
No description provided.