from __future__ import annotations

from types import SimpleNamespace

from recoil.execution.providers import fal_transport
from recoil.execution.providers.fal_transport import (
    FAL_SUBSCRIBE_TIMEOUT_S,
    FalTransport,
)


def test_subscribe_blocking_passes_client_timeout(monkeypatch):
    calls = {}

    def fake_subscribe(model_path, *, arguments, client_timeout):
        calls["model_path"] = model_path
        calls["arguments"] = arguments
        calls["client_timeout"] = client_timeout
        return {"video": {"url": "https://example.test/out.mp4"}}

    monkeypatch.setattr(fal_transport, "_HAS_FAL", True)
    monkeypatch.setattr(
        fal_transport,
        "_fal_client",
        SimpleNamespace(subscribe=fake_subscribe),
    )

    result = FalTransport().subscribe_blocking("fal-ai/wan/v2.7/image-to-video", {"x": 1})

    assert result["video"]["url"].endswith("out.mp4")
    assert calls == {
        "model_path": "fal-ai/wan/v2.7/image-to-video",
        "arguments": {"x": 1},
        "client_timeout": FAL_SUBSCRIBE_TIMEOUT_S,
    }
