diff --git a/adapter/matrix/agent_registry.py b/adapter/matrix/agent_registry.py index 28bfbed..bac84a9 100644 --- a/adapter/matrix/agent_registry.py +++ b/adapter/matrix/agent_registry.py @@ -31,9 +31,9 @@ class AgentRegistry: def _required_text(entry: Mapping[str, object], key: str) -> str: value = entry.get(key) - if value is None: + if not isinstance(value, str): raise AgentRegistryError("each agent entry requires id and label") - text = str(value).strip() + text = value.strip() if not text: raise AgentRegistryError("each agent entry requires id and label") return text diff --git a/tests/adapter/matrix/test_agent_registry.py b/tests/adapter/matrix/test_agent_registry.py index e48a4a5..a918f84 100644 --- a/tests/adapter/matrix/test_agent_registry.py +++ b/tests/adapter/matrix/test_agent_registry.py @@ -172,3 +172,28 @@ def test_load_agent_registry_rejects_blank_id_or_label(tmp_path: Path, content: with pytest.raises(AgentRegistryError, match="each agent entry requires id and label"): load_agent_registry(path) + + +@pytest.mark.parametrize( + "content", + [ + "agents:\n" + " - id: 123\n" + " label: Analyst\n", + "agents:\n" + " - id: agent-1\n" + " label: 456\n", + "agents:\n" + " - id: true\n" + " label: Analyst\n", + "agents:\n" + " - id: agent-1\n" + " label: false\n", + ], +) +def test_load_agent_registry_rejects_non_string_id_or_label(tmp_path: Path, content: str): + path = tmp_path / "agents.yaml" + path.write_text(content, encoding="utf-8") + + with pytest.raises(AgentRegistryError, match="each agent entry requires id and label"): + load_agent_registry(path)