fix max-bot, add tests
This commit is contained in:
parent
7abbaf7e7a
commit
2ad1438e1c
17 changed files with 1621 additions and 494 deletions
88
tests/adapter/max/test_agent_registry.py
Normal file
88
tests/adapter/max/test_agent_registry.py
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
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")
|
||||
Loading…
Add table
Add a link
Reference in a new issue