"""Real Apple MPS discovery, selection, placement, and operation probe."""

from __future__ import annotations

import pytest
import torch

from obliteratus import device


pytestmark = pytest.mark.mps


def test_mps_discovery_selection_placement_and_operation():
    if not (hasattr(torch.backends, "mps") and torch.backends.mps.is_available()):
        pytest.skip("requires an Apple Silicon MPS runner with ENABLE_MPS_GATE=true")
    assert device.is_mps()
    assert device.get_device("auto") == "mps"
    assert device.default_dtype("mps") is torch.float16
    assert not device.supports_float64("mps")
    tensor = torch.arange(16, device="mps", dtype=torch.float32).reshape(4, 4)
    result = tensor @ tensor.T
    assert result.device.type == "mps"
    assert torch.isfinite(result).all().item()
