@tdd_issue @tdd_issue_4741
Feature: TDD: suggestions() query extraction in on_input_submitted uses correct @token text
  Regression test for issue #4741.
  The on_input_submitted handler must extract only the @token text (without the @
  sign and without surrounding non-reference words) as the query passed to
  suggestions(). Previously, text.replace("@", "").strip() was used, which
  corrupted the query by including all non-reference words from the prompt.

  Background:
    Given the TUI app module is imported with mocked Textual for issue 4741

  @tdd_issue @tdd_issue_4741
  Scenario: Single @token in multi-word prompt uses only the token text as query
    Given a mock command router and persona state for issue 4741
    When I instantiate the TUI app for issue 4741
    And I call on_mount on the app for issue 4741
    And I submit "analyse @proj" to the app for issue 4741 and capture the suggestions query
    Then the suggestions query should be "proj" not "analyse proj"

  @tdd_issue @tdd_issue_4741
  Scenario: @token with category prefix passes only the suffix as query
    Given a mock command router and persona state for issue 4741
    When I instantiate the TUI app for issue 4741
    And I call on_mount on the app for issue 4741
    And I submit "show @resource:src/main.py" to the app for issue 4741 and capture the suggestions query
    Then the suggestions query should be "resource:src/main.py" not "show resource:src/main.py"

  @tdd_issue @tdd_issue_4741
  Scenario: Multiple @tokens in prompt uses the last token as query
    Given a mock command router and persona state for issue 4741
    When I instantiate the TUI app for issue 4741
    And I call on_mount on the app for issue 4741
    And I submit "compare @plan1 with @plan2" to the app for issue 4741 and capture the suggestions query
    Then the suggestions query should be "plan2" not "compare plan1 with plan2"

  @tdd_issue @tdd_issue_4741
  Scenario: Standalone @token at start of prompt uses only the token text as query
    Given a mock command router and persona state for issue 4741
    When I instantiate the TUI app for issue 4741
    And I call on_mount on the app for issue 4741
    And I submit "@actor:local/dev" to the app for issue 4741 and capture the suggestions query
    Then the suggestions query should be "actor:local/dev" not "@actor:local/dev"

  @tdd_issue @tdd_issue_4741
  Scenario: Prompt with no @token does not call suggestions
    Given a mock command router and persona state for issue 4741
    When I instantiate the TUI app for issue 4741
    And I call on_mount on the app for issue 4741
    And I submit "analyse the codebase" to the app for issue 4741 and capture the suggestions query
    Then suggestions was not called for issue 4741
