88 lines
2.5 KiB
Python
88 lines
2.5 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from adapter.max.agent_registry import AgentRegistryError, load_agent_registry
|
|
|
|
|
|
def test_load_agent_registry_reads_yaml(tmp_path: Path):
|
|
path = tmp_path / "max.yaml"
|
|
path.write_text(
|
|
"agents:\n"
|
|
" - id: agent-1\n"
|
|
" label: One\n"
|
|
" base_url: http://localhost:8000/a1/\n"
|
|
" workspace_path: /agents/1\n",
|
|
encoding="utf-8",
|
|
)
|
|
reg = load_agent_registry(path)
|
|
assert [a.agent_id for a in reg.agents] == ["agent-1"]
|
|
a = reg.get("agent-1")
|
|
assert a.label == "One"
|
|
assert a.base_url == "http://localhost:8000/a1/"
|
|
assert a.workspace_path == "/agents/1"
|
|
|
|
|
|
def test_user_agents_resolve(tmp_path: Path):
|
|
path = tmp_path / "max.yaml"
|
|
path.write_text(
|
|
"user_agents:\n"
|
|
' "42": agent-1\n'
|
|
"agents:\n"
|
|
" - id: agent-1\n"
|
|
" label: One\n"
|
|
" - id: agent-2\n"
|
|
" label: Two\n",
|
|
encoding="utf-8",
|
|
)
|
|
reg = load_agent_registry(path)
|
|
assert reg.resolve_agent_for_user("42").agent_id == "agent-1"
|
|
assert reg.resolve_agent_for_user("42").source == "configured"
|
|
assert reg.resolve_agent_for_user("999").agent_id == "agent-1"
|
|
assert reg.resolve_agent_for_user("999").source == "default"
|
|
|
|
|
|
def test_duplicate_ids_rejected(tmp_path: Path):
|
|
path = tmp_path / "max.yaml"
|
|
path.write_text(
|
|
"agents:\n"
|
|
" - id: a\n"
|
|
" label: A\n"
|
|
" - id: a\n"
|
|
" label: B\n",
|
|
encoding="utf-8",
|
|
)
|
|
with pytest.raises(AgentRegistryError, match="duplicate agent id"):
|
|
load_agent_registry(path)
|
|
|
|
|
|
def test_empty_agents_rejected(tmp_path: Path):
|
|
path = tmp_path / "max.yaml"
|
|
path.write_text("agents: []\n", encoding="utf-8")
|
|
with pytest.raises(AgentRegistryError, match="non-empty"):
|
|
load_agent_registry(path)
|
|
|
|
|
|
def test_user_agents_must_be_strings(tmp_path: Path):
|
|
path = tmp_path / "max.yaml"
|
|
path.write_text(
|
|
"user_agents:\n"
|
|
" 42: agent-1\n"
|
|
"agents:\n"
|
|
" - id: agent-1\n"
|
|
" label: One\n",
|
|
encoding="utf-8",
|
|
)
|
|
with pytest.raises(AgentRegistryError, match="user_agents"):
|
|
load_agent_registry(path)
|
|
|
|
|
|
def test_unknown_agent_raises(tmp_path: Path):
|
|
path = tmp_path / "max.yaml"
|
|
path.write_text(
|
|
"agents:\n - id: a\n label: A\n",
|
|
encoding="utf-8",
|
|
)
|
|
reg = load_agent_registry(path)
|
|
with pytest.raises(AgentRegistryError, match="unknown agent id"):
|
|
reg.get("missing")
|