File size: 2,004 Bytes
dfb775d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Coach API for hardware diagnostics."""
from __future__ import annotations

from fastapi.testclient import TestClient

from mindxtrain.operator.app import app

client = TestClient(app)


def test_diagnostics_returns_full_profile():
    """Endpoint returns the composite hardware profile."""
    r = client.get("/coach/api/diagnostics/hardware")
    assert r.status_code == 200
    data = r.json()
    # Shape contract: every consumer relies on these keys.
    assert "cpu" in data
    assert "amd" in data
    assert "nvidia" in data
    assert "recommended_lane" in data
    # CPU panel is always populated.
    assert data["cpu"]["available"] is True
    assert data["cpu"]["cores"] >= 1
    # Recommendation is always one of the known lanes.
    assert data["recommended_lane"] in {"trl_cpu", "trl_local", "axolotl_amd"}


def test_diagnostics_cpu_has_expected_fields():
    r = client.get("/coach/api/diagnostics/hardware")
    cpu = r.json()["cpu"]
    for key in ("model_name", "vendor", "is_ryzen", "cores", "threads",
                "ram_total_gb", "ram_available_gb"):
        assert key in cpu, f"missing CPU field: {key}"


def test_diagnostics_amd_panel_shape():
    r = client.get("/coach/api/diagnostics/hardware")
    amd = r.json()["amd"]
    assert "available" in amd
    assert "gpus" in amd
    assert isinstance(amd["gpus"], list)
    if amd["available"]:
        for gpu in amd["gpus"]:
            assert "name" in gpu
            assert "vram_gb" in gpu


def test_diagnostics_nvidia_panel_shape():
    r = client.get("/coach/api/diagnostics/hardware")
    nv = r.json()["nvidia"]
    assert "available" in nv
    assert "gpus" in nv


def test_diagnostics_is_jsonable():
    """The endpoint output must be JSON-serializable without further
    massaging (the Coach JS does JSON.parse straight to the renderer)."""
    import json
    r = client.get("/coach/api/diagnostics/hardware")
    body = r.text
    # Round-trip.
    parsed = json.loads(body)
    assert "cpu" in parsed