from src.services.incident_timeline_service import STAGE_DEFS, format_ascii_timeline


def _stages(status_by_stage: dict[str, str]) -> list[dict]:
    return [
        {"stage": stage, "status": status_by_stage.get(stage, "skipped")}
        for stage, _label in STAGE_DEFS
    ]


def test_format_ascii_timeline_skips_unrecorded_stages() -> None:
    stages = _stages({
        "webhook": "completed",
        "ai_router": "success",
        "executor": "error",
        "km": "pending",
    })

    assert format_ascii_timeline(stages) == (
        "webhook:ok > ai_router:ok > executor:fail > km:wait"
    )


def test_format_ascii_timeline_has_empty_fallback() -> None:
    assert format_ascii_timeline(_stages({})) == "webhook:skip > ai:skip > executor:skip"
