from __future__ import annotations

from pathlib import Path

from jarvis_gateway.adapters.autoshorts_probe import AutoShortsLocalProbeAdapter


def test_autoshorts_local_probe_reads_metadata_only(tmp_path: Path, monkeypatch) -> None:
    media = tmp_path / "prepared.mp4"
    media.write_bytes(b"BLOCKED_MEDIA_CONTENT")
    marker = tmp_path / "review.review"
    marker.write_text("SHOULD_NOT_BE_READ", encoding="utf-8")
    opened: list[str] = []
    original_open = Path.open

    def tracking_open(self: Path, *args, **kwargs):
        opened.append(str(self))
        return original_open(self, *args, **kwargs)

    monkeypatch.setattr(Path, "open", tracking_open)
    snap = AutoShortsLocalProbeAdapter(str(tmp_path)).get_snapshot()
    assert snap.source_health.source_type == "local_probe"
    assert snap.status in {"attention", "ok"}
    assert not any(str(tmp_path) in item for item in opened)
    text = str(snap.model_dump(mode="json"))
    assert "prepared.mp4" not in text
    assert "SHOULD_NOT_BE_READ" not in text


def test_autoshorts_local_probe_missing_runtime_is_safe() -> None:
    snap = AutoShortsLocalProbeAdapter("/tmp/does-not-exist-autoshorts").get_snapshot()
    assert snap.status == "degraded"
    assert snap.source_health.reachable is False
