Feature: Consolidated Context
  Combined scenarios from: context_analysis_agent_coverage, context_manager_coverage, context_service_analysis, context_vector_search, project_context_policy

  # ============================================================
  # Originally from: context_analysis_agent_coverage.feature
  # Feature: Context Analysis Agent Coverage
  # ============================================================

  # ============================================================
  # Originally from: context_manager_coverage.feature
  # Feature: Context manager coverage
  # ============================================================

  @coverage
  Scenario: Load stored context JSON files
    Given a context manager storage directory with valid JSON files
    When I initialize the context manager from that directory
    Then the stored context data should be loaded


  @coverage
  Scenario: Ignore invalid JSON files for context storage
    Given a context manager storage directory with invalid JSON files
    When I initialize the context manager from that directory
    Then invalid context files should load as empty defaults


  @coverage
  Scenario: Use default home context path and delete
    Given a temporary home directory for the context manager
    When I initialize the context manager without a context directory
    Then the context manager should use the default home context path
    And deleting the context should remove the directory


  @coverage
  Scenario: Update state and metadata and report existence
    Given a context manager for state and metadata updates
    When I update state and metadata in the context manager
    Then the context manager should return the updated values
    And the context should report it exists on disk


  @coverage
  Scenario: Return last messages and clear context
    Given a context manager with stored messages
    When I request the last message and clear the context
    Then the last message should be returned and the context reset


  @coverage
  Scenario: Export and import a context snapshot
    Given a context manager with exportable data
    When I export and import the context
    Then the imported context should match the exported data


  # ============================================================
  # Originally from: context_service_analysis.feature
  # Feature: Context Service Analysis Integration
  # ============================================================

  # ============================================================
  # Originally from: context_vector_search.feature
  # Feature: Context Vector Search
  # ============================================================

  # ============================================================
  # Originally from: project_context_policy.feature
  # Feature: Project Context Policy Domain Model
  # ============================================================

  Scenario: Empty policy defaults to including everything
    When I create an empty project context policy
    Then the default view should include all resources
    And the default view should include all paths
    And the default view should have no file size limit
    And the default view should have no total size limit

    # ---- View inheritance ----


  Scenario: Strategize inherits from default when not overridden
    Given a policy with only a default view
    When I resolve the view for phase "strategize"
    Then the resolved view should be the default view


  Scenario: Execute inherits from strategize when not overridden
    Given a policy with default and strategize views
    When I resolve the view for phase "execute"
    Then the resolved view should be the strategize view


  Scenario: Apply inherits from execute when not overridden
    Given a policy with default strategize and execute views
    When I resolve the view for phase "apply"
    Then the resolved view should be the execute view


  Scenario: Execute inherits from default when strategize is None
    Given a policy with only a default view
    When I resolve the view for phase "execute"
    Then the resolved view should be the default view


  Scenario: Apply falls through to default when all overrides are None
    Given a policy with only a default view
    When I resolve the view for phase "apply"
    Then the resolved view should be the default view


  Scenario: Resolve default phase returns default view
    Given a policy with only a default view
    When I resolve the view for phase "default"
    Then the resolved view should be the default view

    # ---- Override isolation ----


  Scenario: Override at execute level does not affect strategize
    Given a policy with a custom execute view
    When I resolve the view for phase "strategize"
    Then the resolved view should be the default view


  Scenario: Override at execute returns execute view
    Given a policy with a custom execute view
    When I resolve the view for phase "execute"
    Then the resolved view should be the execute view

    # ---- Invalid phase name ----


  Scenario: Invalid phase name raises error
    Given a policy with only a default view
    When I try to resolve the view for phase "invalid_phase"
    Then a context policy error should be raised
    And the context policy error should mention "Invalid phase"


  Scenario: Unknown phase name raises error
    Given a policy with only a default view
    When I try to resolve the view for phase "plan"
    Then a context policy error should be raised
    And the context policy error should mention "Invalid phase"

    # ---- Include/exclude resource patterns ----


  Scenario: Include resources filters correctly
    When I create a context view with include resources "db-*,cache-*"
    Then the context view should have 2 include resources


  Scenario: Exclude resources filters correctly
    When I create a context view with exclude resources "temp-*"
    Then the context view should have 1 exclude resource


  Scenario: Combined include and exclude resources
    When I create a context view with include "db-*" and exclude "db-test"
    Then the context view should have 1 include resource
    And the context view should have 1 exclude resource

    # ---- Include/exclude path globs ----


  Scenario: Include paths accepts globs
    When I create a context view with include paths "src/**/*.py,tests/**"
    Then the context view should have 2 include paths


  Scenario: Exclude paths accepts globs
    When I create a context view with exclude paths "*.pyc,__pycache__/**"
    Then the context view should have 2 exclude paths

    # ---- Size limit validation ----


  Scenario: Valid max file size is accepted
    When I create a context view with max file size 1048576
    Then the context view max file size should be 1048576


  Scenario: None max file size means no limit
    When I create a context view with no file size limit
    Then the context view max file size should be None


  Scenario: Zero max file size raises error
    When I try to create a context view with max file size 0
    Then a context policy error should be raised
    And the context policy error should mention "positive integer"


  Scenario: Negative max file size raises error
    When I try to create a context view with max file size -100
    Then a context policy error should be raised
    And the context policy error should mention "positive integer"


  Scenario: Valid max total size is accepted
    When I create a context view with max total size 10485760
    Then the context view max total size should be 10485760


  Scenario: Zero max total size raises error
    When I try to create a context view with max total size 0
    Then a context policy error should be raised
    And the context policy error should mention "positive integer"


  Scenario: Negative max total size raises error
    When I try to create a context view with max total size -50
    Then a context policy error should be raised
    And the context policy error should mention "positive integer"

    # ---- Serialization round-trip ----


  Scenario: Policy survives JSON round-trip
    Given a fully populated context policy
    When I serialize and deserialize the policy
    Then the deserialized policy should match the original

    # ---- ContextView model_dump ----


  Scenario: ContextView model_dump has expected keys
    When I create a context view with defaults
    Then the context view dump should have key "include_resources"
    And the context view dump should have key "exclude_resources"
    And the context view dump should have key "include_paths"
    And the context view dump should have key "exclude_paths"
    And the context view dump should have key "max_file_size"
    And the context view dump should have key "max_total_size"
