@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 dir membership 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 dir membership 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 dir membership 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"
