Feature: Repository indexing CLI commands
  As a developer
  I want to index repository resources via the CLI
  So that I can manage repository indexing through agents repo commands

  Background:
    Given a fresh in-memory repo indexing environment

  # ---- agents repo index ----

  Scenario: Index a valid repository resource
    Given a registered git-checkout resource "local/test-repo" with a temp directory
    When I run repo index on resource "local/test-repo"
    Then the repo command should succeed
    And the repo output should contain "complete"
    And the repo output should contain "local/test-repo"

  Scenario: Index with --full forces full re-index
    Given a registered git-checkout resource "local/full-repo" with a temp directory
    When I run repo full-index on resource "local/full-repo"
    Then the repo command should succeed
    And the repo output should contain "Full index complete"

  Scenario: Incremental re-index after initial index
    Given a registered git-checkout resource "local/incr-repo" with a temp directory
    And I have already indexed "local/incr-repo"
    When I run repo index on resource "local/incr-repo"
    Then the repo command should succeed
    And the repo output should contain "Incremental refresh complete"

  @tdd_issue @tdd_issue_4259 @tdd_expected_fail
  Scenario: Index with JSON output format
    Given a registered git-checkout resource "local/json-repo" with a temp directory
    When I run repo index-json on resource "local/json-repo"
    Then the repo command should succeed
    And the repo output should be valid JSON
    And the repo JSON output should contain key "status"
    And the repo JSON output should contain key "file_count"
    And the repo JSON output should contain key "primary_language"

  Scenario: Index with non-existent resource shows error
    When I run repo index on resource "local/nonexistent-resource"
    Then the repo command should fail
    And the repo output should contain "Resource not found"

  # ---- agents repo status ----

  Scenario: Status for an indexed resource
    Given a registered git-checkout resource "local/status-repo" with a temp directory
    And I have already indexed "local/status-repo"
    When I run repo status on resource "local/status-repo"
    Then the repo command should succeed
    And the repo output should contain "Status"
    And the repo output should contain "Files"
    And the repo output should contain "Tokens"

  Scenario: Status with no index shows appropriate message
    Given a registered git-checkout resource "local/noindex-repo" with a temp directory
    When I run repo status on resource "local/noindex-repo"
    Then the repo command should succeed
    And the repo output should contain "No index found"

  @tdd_issue @tdd_issue_4259 @tdd_expected_fail
  Scenario: Status with JSON output format
    Given a registered git-checkout resource "local/json-status-repo" with a temp directory
    And I have already indexed "local/json-status-repo"
    When I run repo status-json on resource "local/json-status-repo"
    Then the repo command should succeed
    And the repo output should be valid JSON
    And the repo JSON output should contain key "status"
    And the repo JSON output should contain key "file_count"
    And the repo JSON output should contain key "token_estimate"

  Scenario: Status for non-existent resource shows error
    When I run repo status on resource "local/missing-resource"
    Then the repo command should fail
    And the repo output should contain "Resource not found"

  @tdd_issue @tdd_issue_4259 @tdd_expected_fail
  Scenario: Status with no index in JSON format
    Given a registered git-checkout resource "local/noindex-json" with a temp directory
    When I run repo status-json on resource "local/noindex-json"
    Then the repo command should succeed
    And the repo output should be valid JSON
    And the repo JSON output should contain key "status"
    And the repo JSON output field "status" should equal "not_indexed"

  # ---- edge cases for coverage ----

  Scenario: Index resource with no filesystem path shows error
    Given a registered resource "local/no-path" with no location
    When I run repo index on resource "local/no-path"
    Then the repo command should fail
    And the repo output should contain "no filesystem path"

  Scenario: Index resource with path only in properties
    Given a registered resource "local/prop-path" with path in properties only
    When I run repo index on resource "local/prop-path"
    Then the repo command should succeed
    And the repo output should contain "complete"

  Scenario: Index with missing root path shows error
    Given a registered resource "local/bad-path" with nonexistent path
    When I run repo index on resource "local/bad-path"
    Then the repo command should fail
    And the repo output should contain "Error"
