Feature: Context service new coverage
  As a developer
  I want ContextService LangGraph analysis methods thoroughly tested
  So that context analysis, streaming, and vector search stay stable

  Scenario: _get_current_plan returns None for project without id
    Given a context service with mocked dependencies
    And a project without an id
    When I get the current plan
    Then the context result should be None

  Scenario: _build_langsmith_config returns empty dict when disabled
    Given a context service with mocked dependencies
    And a project with id 1
    When I build langsmith config with langsmith disabled
    Then the config should be an empty dict

  Scenario: _build_langsmith_config returns config when enabled
    Given a context service with langsmith enabled
    And a project with id 1
    When I build langsmith config with langsmith enabled
    Then the config should contain metadata and tags

  Scenario: _prepare_analysis_config adds thread_id
    Given a context service with mocked dependencies
    And a project with id 1
    When I prepare analysis config
    Then the config should have a configurable thread_id

  Scenario: _vector_store_available returns False when no store
    Given a context service with no vector store
    When I check vector store availability
    Then the vector store check should return False

  Scenario: _refresh_vector_index is a no-op when store unavailable
    Given a context service with no vector store
    When I refresh vector index for plan 1
    Then no exception should be raised

  Scenario: _refresh_vector_index handles ConfigurationError gracefully
    Given a context service with a failing vector store
    When I refresh vector index for plan 1
    Then no exception should be raised

  Scenario: _get_context_agent returns a ContextAnalysisAgent
    Given a context service with mocked dependencies
    When I get the context agent
    Then the context agent should be a ContextAnalysisAgent instance

  Scenario: analyze_context returns empty analysis for empty context
    Given a context service with mocked dependencies
    And a project that has no context files
    When I analyze context
    Then the result summary should indicate no files

  Scenario: analyze_context runs full analysis for project with files
    Given a context service with mocked dependencies
    And a project with context files
    When I analyze context
    Then the result should have documents and summary

  Scenario: get_context_summary returns summary string
    Given a context service with mocked dependencies
    And a project with context files
    When I retrieve the context summary
    Then the context summary should be a nonempty string

  Scenario: get_context_dependencies returns dependencies dict
    Given a context service with mocked dependencies
    And a project with context files
    When I get context dependencies
    Then the context deps result should be a dict

  Scenario: get_relevant_files filters by threshold
    Given a context service with mocked dependencies
    And a project with context files
    When I fetch relevant files above threshold 0.5
    Then the relevant files should be a list of tuples

  Scenario: search_context returns empty for blank query
    Given a context service with mocked dependencies
    And a project with id 1
    When I search context with empty query
    Then the context search result should be an empty list

  Scenario: search_context returns empty when no plan
    Given a context service with mocked dependencies
    And a project with id 1 but no current plan
    When I search context with query "test"
    Then the context search result should be an empty list

  Scenario: search_context returns empty when vector store unavailable
    Given a context service with no vector store
    And a project with id 1 and a current plan
    When I search context with query "test"
    Then the context search result should be an empty list

  Scenario: search_context delegates to vector store
    Given a context service with a working vector store
    And a project with id 1 and a current plan
    When I search context with query "test"
    Then the vector store search should be called

  Scenario: search_context handles ConfigurationError from vector store
    Given a context service with a vector store that raises ConfigurationError
    And a project with id 1 and a current plan
    When I search context with query "test"
    Then the context search result should be an empty list

  Scenario: analyze_context_streaming yields complete for empty context
    Given a context service with mocked dependencies
    And a project that has no context files
    When I stream analyze context
    Then the first event should indicate no files

  Scenario: analyze_context_streaming yields events for project with files
    Given a context service with mocked dependencies
    And a project with context files
    When I stream analyze context
    Then at least one streaming event should be yielded
