test: add unit tests for load_user_agent_catalog function

- test_user_agent_catalog_file_exists_and_has_required_fields: verifies catalog file exists with correct structure
- test_load_user_agent_catalog_raises_on_invalid_structure: verifies invalid YAML is properly rejected
This commit is contained in:
qzl
2026-03-02 16:05:30 +08:00
parent 4afc67b7a8
commit 971ba30032
@@ -141,3 +141,48 @@ async def test_initialize_data_rolls_back_on_invalid_factory_mapping(
Base.metadata.remove(users_table)
await engine.dispose()
def test_user_agent_catalog_file_exists_and_has_required_fields() -> None:
catalog_path = (
Path(__file__).resolve().parents[3]
/ "src"
/ "core"
/ "config"
/ "static"
/ "database"
/ "user_agent_catalog.yaml"
)
assert catalog_path.exists(), f"Catalog file not found: {catalog_path}"
catalog = init_data.load_user_agent_catalog(catalog_path)
assert "agents" in catalog
assert isinstance(catalog["agents"], list)
assert len(catalog["agents"]) == 3
for agent in catalog["agents"]:
assert "agent_type" in agent
assert "llm_model_code" in agent
assert "status" in agent
assert "config" in agent
assert isinstance(agent["config"], dict)
def test_load_user_agent_catalog_raises_on_invalid_structure(
tmp_path: Path,
) -> None:
catalog_path = tmp_path / "user_agent_catalog.yaml"
catalog_path.write_text(
"""
agents:
- agent_type: TEST
llm_model_code: test-model
status: ACTIVE
""".strip(),
encoding="utf-8",
)
with pytest.raises(ValueError, match="Invalid user agent catalog"):
init_data.load_user_agent_catalog(catalog_path)