Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ This file defines how coding agents should work in this repository.
- Direct JSON-RPC and MCP tool `start_keep` requests with explicit `gpu_ids`
must also reject IDs missing from a non-empty validated `list_gpus()` response
as public invalid-parameter/tool errors before controller startup.
- MCP/REST tests that assert exact `start_keep` GPU-selection errors must stub
`KeepGPUServer.list_gpus()` explicitly. Do not let those assertions depend on
whether the host running pytest has a real visible GPU.
- Keep GPU listing platform precedence aligned with controller platform
detection: HIP/ROCm torch builds must prefer ROCm listing over NVML CUDA
listing, and must not fall back to NVML CUDA records when torch's active
Expand Down
4 changes: 4 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ expectations so you can get productive quickly and avoid surprises in CI.
pytest tests/mcp tests/utilities/test_gpu_info.py
```
- Avoid enabling `large_memory` in CI.
- MCP/REST tests that assert exact `start_keep` GPU-selection errors should
stub `KeepGPUServer.list_gpus()` instead of relying on the host's visible GPU
state; real CUDA/ROCm machines can otherwise take the listed-GPU validation
path while CPU-only machines take the controller fallback path.
- Keep broad validation matrices with the utility or controller that owns the
contract; interface tests should use representative smoke cases plus
side-effect guards instead of repeating every edge case.
Expand Down
56 changes: 21 additions & 35 deletions tests/mcp/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ def make_server() -> KeepGPUServer:
return KeepGPUServer(controller_factory=cast(Any, dummy_factory))


def _gpu_record(gpu_id: int) -> dict[str, Any]:
return {
"id": gpu_id,
"visible_id": gpu_id,
"platform": "cuda",
"name": f"visible {gpu_id}",
"memory_total": None,
"memory_used": None,
"utilization": None,
}


def _listed_gpus(*gpu_ids: int) -> dict[str, list[dict[str, Any]]]:
return {"gpus": [_gpu_record(gpu_id) for gpu_id in gpu_ids]}


def _failing_after_work_factory(message, controllers=None):
class FailsAfterWorkController(DummyController):
def keep(self):
Expand Down Expand Up @@ -922,6 +938,7 @@ def test_jsonrpc_start_keep_out_of_range_gpu_ids_returns_invalid_params(monkeypa
monkeypatch.setattr(pm, "_cached_platform", pm.ComputingPlatform.CUDA)
monkeypatch.setattr(torch.cuda, "device_count", lambda: 1)
server = KeepGPUServer()
monkeypatch.setattr(server, "list_gpus", lambda: _listed_gpus())
req = {
"id": 1,
"method": "start_keep",
Expand Down Expand Up @@ -950,7 +967,7 @@ def test_jsonrpc_start_keep_explicit_gpu_ids_with_zero_visible_devices_is_startu
monkeypatch.setattr(pm, "_cached_platform", pm.ComputingPlatform.CUDA)
monkeypatch.setattr(torch.cuda, "device_count", lambda: 0)
server = KeepGPUServer()
monkeypatch.setattr(server, "list_gpus", lambda: {"gpus": []})
monkeypatch.setattr(server, "list_gpus", lambda: _listed_gpus())
req = {
"id": 1,
"method": "start_keep",
Expand All @@ -973,23 +990,7 @@ def fail_factory(**_kwargs):
raise AssertionError("controller should not start for unlisted gpu_ids")

server = KeepGPUServer(controller_factory=cast(Any, fail_factory))
monkeypatch.setattr(
server,
"list_gpus",
lambda: {
"gpus": [
{
"id": 0,
"visible_id": 0,
"platform": "cuda",
"name": "visible 0",
"memory_total": None,
"memory_used": None,
"utilization": None,
}
]
},
)
monkeypatch.setattr(server, "list_gpus", lambda: _listed_gpus(0))
req = {
"id": 1,
"method": "start_keep",
Expand Down Expand Up @@ -1769,6 +1770,7 @@ def test_mcp_tools_call_out_of_range_gpu_ids_returns_tool_error(monkeypatch):
monkeypatch.setattr(pm, "_cached_platform", pm.ComputingPlatform.CUDA)
monkeypatch.setattr(torch.cuda, "device_count", lambda: 1)
server = KeepGPUServer()
monkeypatch.setattr(server, "list_gpus", lambda: _listed_gpus())
req = {
"jsonrpc": "2.0",
"id": 5,
Expand Down Expand Up @@ -1801,23 +1803,7 @@ def fail_factory(**_kwargs):
raise AssertionError("controller should not start for unlisted gpu_ids")

server = KeepGPUServer(controller_factory=cast(Any, fail_factory))
monkeypatch.setattr(
server,
"list_gpus",
lambda: {
"gpus": [
{
"id": 0,
"visible_id": 0,
"platform": "cuda",
"name": "visible 0",
"memory_total": None,
"memory_used": None,
"utilization": None,
}
]
},
)
monkeypatch.setattr(server, "list_gpus", lambda: _listed_gpus(0))
req = {
"jsonrpc": "2.0",
"id": 5,
Expand Down