fix(cleanup): invalidate sandbox_dirs_cache after purge (#7527)

Adds SandboxDirsCache to track filesystem paths of sandbox-created directories indexed by plan_id. Cache is purged in cleanup_all(), cleanup_abandoned(), clear_sandbox_dirs_cache(), and the at-exit handler matching the existing clear_boundary_cache() invalidation.
This commit is contained in:
HAL9000
2026-05-09 12:39:08 +00:00
committed by Forgejo
parent e716b6015c
commit 9801d34cad
6 changed files with 406 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
@sandbox-dirs-cache
Feature: Sandbox directories cache tracking and invalidation (#7527)
Verifies that the SandboxDirsCache correctly records, tracks, and purges
sandbox directory paths by plan_id.
Scenario: Record a sandbox directory path for a plan
Given an empty sandbox dirs cache
When I record dir "/tmp/sandboxes/worktree-abc123" for plan "plan-001"
Then the cache should contain one path for plan "plan-001"
And the total tracked plan count should be 1
Scenario: Record multiple directories for the same plan
Given an empty sandbox dirs cache
When I record dir "/tmp/sandboxes/worktree-abc" for plan "plan-002"
And I record dir "/tmp/sandboxes/overlay-def456" for plan "plan-002"
Then the cache should contain two paths for plan "plan-002"
And the total tracked path count should be 2
Scenario: Record directories for different plans
Given an empty sandbox dirs cache
When I record dir "/tmp/sandboxes/plan-a-dir" for plan "plan-a"
And I record dir "/tmp/sandboxes/plan-b-dir" for plan "plan-b"
Then the cache should contain two distinct plans
And the total tracked plan count should be 2
Scenario: Purge a single plan invalidates all its dirs
Given a sandbox dirs cache with one path "/tmp/sandboxes/worktree-x" for plan "plan-purge"
When I purge sandbox dirs for plan "plan-purge"
Then the cache should contain no paths for plan "plan-purge"
And the total tracked plan count should be 0
Scenario: Purge non-existent plan returns empty list
Given an empty sandbox dirs cache
When I purge sandbox dirs for plan "nonexistent-plan"
Then the purged path count should be 0
And no plans should be removed from tracking
Scenario: Check membership for recorded path
Given a sandbox dirs cache with one path "/tmp/sandboxes/abc" for plan "plan-check"
When I check if dir "/tmp/sandboxes/abc" belongs to plan "plan-check"
Then the result should be True
Scenario: Check membership for non-recorded path returns False
Given a sandbox dirs cache with one path "/tmp/sandboxes/xyz" for plan "plan-wrong"
When I check if dir "/tmp/sandboxes/missing" belongs to plan "plan-wrong"
Then the result should be False
Scenario: Check membership after purge returns False
Given a sandbox dirs cache with one path "/tmp/sandboxes/cached-dir" for plan "plan-expired"
When I purge sandbox dirs for plan "plan-expired"
And I check if dir "/tmp/sandboxes/cached-dir" belongs to plan "plan-expired"
Then the result should be False
Scenario: Clear all entries empties the cache
Given a sandbox dirs cache with paths for plans "plan-clear-1" and "plan-clear-2"
When I clear all entries from the sandbox dirs cache
Then no plans should remain tracked
And total tracked path count should be 0
Scenario: Duplicate directory recording is idempotent
Given a sandbox dirs cache with one path "/tmp/sandboxes/uniq-dir" for plan "plan-uniq"
When I record dir "/tmp/sandboxes/uniq-dir" for plan "plan-uniq" again
Then the cache should still contain exactly one path for plan "plan-uniq"