"""Tests for orchestration error formatting and emission."""

from __future__ import annotations

from lattice.shell.error_handler import (
    build_step_not_found_escalation,
    emit_escalation,
)


def test_build_step_not_found_escalation_includes_context() -> None:
    """Escalation text includes workflow, phase, and step context."""
    message = build_step_not_found_escalation(
        workflow_id="wf-10",
        step_id="phase.missing",
        phase="phase",
        reason="No fallback",
        attempted_actions=["Checked fallback registry"],
    )

    assert "ESCALATION REQUIRED" in message
    assert "Workflow: wf-10" in message
    assert "Phase: phase" in message
    assert "Missing step: phase.missing" in message
    assert "Checked fallback registry" in message


def test_build_step_not_found_escalation_includes_none_when_no_actions() -> None:
    """Escalation text is explicit when no actions were attempted."""
    message = build_step_not_found_escalation(
        workflow_id="wf-11",
        step_id="phase.missing",
        phase="phase",
        reason="No fallback",
        attempted_actions=[],
    )

    assert "Actions attempted:" in message
    assert "- none" in message


def test_emit_escalation_uses_custom_sink() -> None:
    """Emitter writes exactly one message to sink."""
    sink_calls: list[str] = []

    emit_escalation("hello", sink_calls.append)

    assert sink_calls == ["hello"]
