import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps" / "api"))

from app.api.routes.task_center import _humanize_task_error, _ingest_step

from packages.domain import IngestJob, IngestJobStatus


def test_humanize_task_error_for_media_failures():
    assert "MP4" in _humanize_task_error("ffmpeg invalid data found")
    assert "OSS" in _humanize_task_error("oss bucket read failed")
    assert "不存在" in _humanize_task_error("file not found")


def test_ingest_step_is_user_readable():
    job = IngestJob.create(
        project_id="project-1",
        library_id="library-1",
        storage_key="uploads/video.mp4",
    )
    job.status = IngestJobStatus.COMPLETED

    assert _ingest_step(job) == "导入完成"
