"""Step definitions for tui_slash_overlay_descriptions.feature.

These steps verify that SlashCommandOverlay.set_commands() renders
command descriptions alongside command names per ADR-046.
"""

from __future__ import annotations

from behave import then, when

from cleveragents.tui.slash_catalog import SLASH_COMMAND_SPECS


@when("I initialise the overlay with real slash command specs")
def step_init_with_real_specs(context):
    """Call set_commands with the real SLASH_COMMAND_SPECS from the catalog."""
    context.overlay.set_commands("", list(SLASH_COMMAND_SPECS))


@then("the overlay text should contain description for {command!r}")
def step_overlay_contains_description(context, command):
    """Verify the overlay text contains the description for the given command."""
    from cleveragents.tui.slash_catalog import SLASH_COMMAND_SPECS

    spec = next((s for s in SLASH_COMMAND_SPECS if s.command == command), None)
    assert spec is not None, f"Command {command!r} not found in SLASH_COMMAND_SPECS"
    assert spec.description in context.overlay._text, (
        f"Expected description '{spec.description}' in:\n{context.overlay._text}"
    )
