Tighten Matrix agent registry validation

This commit is contained in:
Mikhail Putilovskij 2026-04-24 13:02:19 +03:00
parent b53523ad6c
commit e801225220
4 changed files with 142 additions and 3 deletions

View file

@ -47,3 +47,73 @@ def test_load_agent_registry_rejects_non_mapping_entries(tmp_path: Path):
with pytest.raises(AgentRegistryError, match="each agent entry requires id and label"):
load_agent_registry(path)
@pytest.mark.parametrize(
"content",
[
"",
"agents: []\n",
"agents: agent-1\n",
"foo: bar\n",
],
)
def test_load_agent_registry_rejects_missing_non_list_and_empty_agents(
tmp_path: Path, content: str
):
path = tmp_path / "agents.yaml"
path.write_text(content, encoding="utf-8")
with pytest.raises(AgentRegistryError, match="agents registry must contain a non-empty agents list"):
load_agent_registry(path)
@pytest.mark.parametrize(
"content, expected",
[
(
"agents:\n"
" - label: Analyst\n",
"each agent entry requires id and label",
),
(
"agents:\n"
" - id: agent-1\n",
"each agent entry requires id and label",
),
],
)
def test_load_agent_registry_rejects_missing_id_or_label(tmp_path: Path, content: str, expected: str):
path = tmp_path / "agents.yaml"
path.write_text(content, encoding="utf-8")
with pytest.raises(AgentRegistryError, match=expected):
load_agent_registry(path)
def test_load_agent_registry_rejects_invalid_top_level_yaml(tmp_path: Path):
path = tmp_path / "agents.yaml"
path.write_text(
"- id: agent-1\n"
" label: Analyst\n",
encoding="utf-8",
)
with pytest.raises(AgentRegistryError, match="agent registry must be a mapping with an agents list"):
load_agent_registry(path)
def test_load_agent_registry_rejects_malformed_yaml(tmp_path: Path):
path = tmp_path / "agents.yaml"
path.write_text(
"agents:\n"
" - id: agent-1\n"
" label: Analyst\n"
" - id: agent-2\n"
" label: Research\n"
" - [\n",
encoding="utf-8",
)
with pytest.raises(AgentRegistryError, match="invalid agent registry YAML"):
load_agent_registry(path)