From b53523ad6cacb7731c21426cc5043a4ce5831d87 Mon Sep 17 00:00:00 2001 From: Mikhail Putilovskij Date: Fri, 24 Apr 2026 12:57:00 +0300 Subject: [PATCH] Reject non-mapping agent registry entries --- adapter/matrix/agent_registry.py | 3 +++ tests/adapter/matrix/test_agent_registry.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/adapter/matrix/agent_registry.py b/adapter/matrix/agent_registry.py index 2955daf..6a54f4a 100644 --- a/adapter/matrix/agent_registry.py +++ b/adapter/matrix/agent_registry.py @@ -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: diff --git a/tests/adapter/matrix/test_agent_registry.py b/tests/adapter/matrix/test_agent_registry.py index dfa9050..2c3a705 100644 --- a/tests/adapter/matrix/test_agent_registry.py +++ b/tests/adapter/matrix/test_agent_registry.py @@ -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)