# Regression tests for bug #554 — verifies that the DI container fix for
# session list command works correctly.  The @tdd_expected_fail tags have
# been removed now that the fix has landed.
Feature: Session list command handles missing database gracefully
  As a developer using the agents CLI
  I want "agents session list" to work after a fresh init
  So that I can view my sessions without a DI container error

  Background:
    Given a session-list-error CLI runner using the real DI path

  @tdd_issue @tdd_issue_554
  Scenario: Session list returns empty list when no sessions exist
    When I invoke session-list-error list with default format
    Then the session-list-error command should exit successfully
    And the session-list-error output should contain "No sessions found"
    And the session-list-error output should not contain "AttributeError"

  @tdd_issue @tdd_issue_554
  Scenario: Session list after init does not raise DI error
    When I invoke session-list-error list with default format
    Then the session-list-error command should exit successfully
    And the session-list-error output should not contain "AttributeError"
    And the session-list-error output should not contain "INTERNAL"

  @tdd_issue @tdd_issue_554
  Scenario: Session list returns sessions after creation via service
    Given a session-list-error service with a pre-populated session
    When I invoke session-list-error list with default format
    Then the session-list-error command should exit successfully
    And the session-list-error output should contain "Sessions"

  @tdd_issue @tdd_issue_554
  Scenario: Session list works with rich output format
    Given a session-list-error service with a pre-populated session
    When I invoke session-list-error list with format "rich"
    Then the session-list-error command should exit successfully
    And the session-list-error output should contain "Sessions"
    And the session-list-error output should not contain "AttributeError"

  @tdd_issue @tdd_issue_554
  Scenario: Session list works with JSON output format
    Given a session-list-error service with a pre-populated session
    When I invoke session-list-error list with format "json"
    Then the session-list-error command should exit successfully
    And the session-list-error output should be valid JSON containing "sessions"

  @tdd_issue @tdd_issue_554
  Scenario: Session list works with plain output format
    Given a session-list-error service with a pre-populated session
    When I invoke session-list-error list with format "plain"
    Then the session-list-error command should exit successfully
    And the session-list-error output should contain "total:"

  @tdd_issue @tdd_issue_554
  @tdd_issue @tdd_issue_4270 @tdd_expected_fail
  Scenario: Session list works with YAML output format
    Given a session-list-error service with a pre-populated session
    When I invoke session-list-error list with format "yaml"
    Then the session-list-error command should exit successfully
    And the session-list-error output should be valid YAML containing "sessions"

  # Empty-list format scenarios (F2/F3) — exercises the empty-list code path
  # with explicit output formats.  The production code currently bypasses
  # --format for empty lists, so these document the expected behaviour.

  @tdd_issue @tdd_issue_554
  Scenario: Empty session list with JSON format produces valid JSON
    When I invoke session-list-error list with format "json"
    Then the session-list-error command should exit successfully
    And the session-list-error output should be valid JSON containing "sessions"
    And the session-list-error output should not contain "AttributeError"

  @tdd_issue @tdd_issue_554
  @tdd_issue @tdd_issue_4270 @tdd_expected_fail
  Scenario: Empty session list with YAML format produces valid YAML
    When I invoke session-list-error list with format "yaml"
    Then the session-list-error command should exit successfully
    And the session-list-error output should be valid YAML containing "sessions"
    And the session-list-error output should not contain "AttributeError"

  @tdd_issue @tdd_issue_554
  Scenario: Empty session list with plain format does not error
    When I invoke session-list-error list with format "plain"
    Then the session-list-error command should exit successfully
    And the session-list-error output should contain "total: 0"
    And the session-list-error output should not contain "AttributeError"
