Reject non-mapping agent registry entries

This commit is contained in:
Mikhail Putilovskij 2026-04-24 12:57:00 +03:00
parent 37f7ce27a2
commit b53523ad6c
2 changed files with 15 additions and 0 deletions

View file

@ -1,6 +1,7 @@
from __future__ import annotations
from dataclasses import dataclass
from collections.abc import Mapping
from pathlib import Path
import yaml
@ -37,6 +38,8 @@ def load_agent_registry(path: str | Path) -> AgentRegistry:
agents: list[AgentDefinition] = []
seen: set[str] = set()
for entry in entries:
if not isinstance(entry, Mapping):
raise AgentRegistryError("each agent entry requires id and label")
agent_id = str(entry.get("id", "")).strip()
label = str(entry.get("label", "")).strip()
if not agent_id or not label:

View file

@ -35,3 +35,15 @@ def test_load_agent_registry_rejects_duplicate_ids(tmp_path: Path):
with pytest.raises(AgentRegistryError, match="duplicate agent id"):
load_agent_registry(path)
def test_load_agent_registry_rejects_non_mapping_entries(tmp_path: Path):
path = tmp_path / "agents.yaml"
path.write_text(
"agents:\n"
" - agent-1\n",
encoding="utf-8",
)
with pytest.raises(AgentRegistryError, match="each agent entry requires id and label"):
load_agent_registry(path)