Files
cleveragents-core/features/cancel_worktree_cleanup.feature
hamza.khyari b907ccd9f8 fix(plan): clean up worktree sandbox on plan cancel
When a user cancels a plan after execute, the git worktree branch and
directory created during execute are not cleaned up, causing resource
leaks (dangling worktrees accumulate over time).

Add GitWorktreeSandbox.cleanup_stale() classmethod in the
infrastructure layer with idempotent error handling.
_cleanup_sandbox_for_plan() in the CLI layer resolves the plan's
linked git-checkout resource and delegates to cleanup_stale().
Called after service.cancel_plan() in the cancel CLI handler.

ISSUES CLOSED: #9230
2026-04-20 13:54:28 +00:00

18 lines
1015 B
Gherkin

@cancel-worktree-cleanup
Feature: Plan cancel cleans up worktree sandbox (#9230)
Verifies that cancelling a plan after execute removes the
git worktree branch and directory to prevent resource leaks.
Scenario: _cleanup_sandbox_for_plan removes worktree for cancelled plan for cwc
Given a temp git project with a worktree sandbox for plan "01TESTCANCEL000000000000" for cwc
And a mocked service that resolves the project for cwc
When I call _cleanup_sandbox_for_plan for plan "01TESTCANCEL000000000000" for cwc
Then the branch "cleveragents/plan-01TESTCANCEL000000000000" should not exist for cwc
And the worktree directory should not exist for cwc
Scenario: _cleanup_sandbox_for_plan is a no-op when no sandbox exists for cwc
Given a temp git project without any worktree for cwc
And a mocked service with no linked resources for cwc
When I call _cleanup_sandbox_for_plan for plan "01TESTNOSANDBOX0000000000" for cwc
Then the call should complete without error for cwc