from __future__ import annotations

def test_get_cluster_available_sums_resources(monkeypatch):
    from argus.service import ray_resources

    monkeypatch.setattr(ray_resources.ray._private.state, "available_resources_per_node", lambda: {  # type: ignore[attr-defined]
        "n1": {"GPU": 1, "NPU": 2},
        "n2": {"GPU": 0.5},
        "bad": "nope",
    })

    avail = ray_resources.get_cluster_available()
    assert avail.total_available_gpus == 1.5
    assert avail.total_available_npus == 2.0


def test_get_cluster_available_returns_zero_on_exception(monkeypatch):
    from argus.service import ray_resources

    def _boom() -> dict[str, object]:
        raise RuntimeError("boom")

    monkeypatch.setattr(ray_resources.ray._private.state, "available_resources_per_node", _boom)  # type: ignore[attr-defined]
    avail = ray_resources.get_cluster_available()
    assert avail.total_available_gpus == 0.0
