"""Step definitions for Robot smoke alignment scenarios in session model tests.

These steps mirror the expectations enforced by the Robot Framework smoke
suite in ``robot/session_model.robot`` so that Behave and Robot stay in sync.
"""

from behave import then
from behave.runner import Context


@then("the export dict keys should be in expected serialization order")
def session_model_check_export_key_order(context: Context) -> None:
    """Verify export dict keys follow the canonical serialization order."""
    expected_order = [
        "schema_version",
        "session_id",
        "actor_name",
        "namespace",
        "messages",
        "linked_plan_ids",
        "token_usage",
        "metadata",
        "created_at",
        "updated_at",
        "checksum",
    ]
    actual_keys = list(context.session_export_dict.keys())
    assert actual_keys == expected_order, (
        f"Expected export key order {expected_order}, got {actual_keys}"
    )


@then("the export dict messages should be ordered by sequence")
def session_model_check_export_messages_sequence_order(context: Context) -> None:
    """Verify messages in the export dict are ordered by sequence."""
    messages = context.session_export_dict["messages"]
    sequences = [m["sequence"] for m in messages]
    assert sequences == sorted(sequences), (
        f"Export messages not ordered by sequence: {sequences}"
    )
