""" backend/tests/test_agent_registry_admin_schema.py 用途:Admin Agent Registry schema 组装单元测试。 依赖:admin_schema、catalog manifest。 逻辑:P3 验收 — build_agent_registry_schema 返回平台枚举、Catalog 扩展字段与 handler_config_schemas。 """ from __future__ import annotations from app.services.agent_registry.admin_schema import build_agent_registry_schema def test_build_agent_registry_schema_includes_platform_enums(): """platform 段应含 runtime_providers、conversation_modes 与 default_capabilities。""" schema = build_agent_registry_schema() platform = schema['platform'] assert 'dify' in platform['runtime_providers'] assert 'chat' in platform['conversation_modes'] assert platform['default_capabilities']['streaming'] is True assert platform['tool_run_progress_defaults']['poll_interval_seconds'] == 2 assert platform['tool_run_progress_defaults']['progress_type'] == 'file_check' def test_build_agent_registry_schema_agent_types_include_validation_rules(): """agent_types 每条应含 required_fields、default_capabilities、forced_capabilities 与 progress_contract。""" schema = build_agent_registry_schema() by_code = {item['agent_code']: item for item in schema['agent_types']} assert by_code['file_check']['required_fields'] == ['bound_schedule_task_id'] assert by_code['file_check']['forced_capabilities']['task_progress'] is True assert by_code['generic']['required_fields'] == [] file_check_contract = by_code['file_check']['progress_contract'] assert file_check_contract['data_source']['type'] == 'schedule_run' assert file_check_contract['binding']['requires_schedule_task'] is True shipping = by_code['shipping_notice'] assert shipping['default_capabilities']['file_upload'] is True assert shipping['default_capabilities']['task_progress'] is True assert shipping['forced_capabilities'] == { 'file_upload': True, 'task_progress': True, 'human_confirm': True, } assert shipping['progress_contract']['presentation']['layout'] == 'workspace' assert shipping['progress_contract']['binding']['requires_schedule_task'] is False assert 'erp_kb' not in shipping['forced_capabilities'] def test_build_agent_registry_schema_handler_config_schemas(): """handler_config_schemas 应按 agent_code 暴露 manifest schema。""" schema = build_agent_registry_schema() assert 'file_check' in schema['handler_config_schemas'] assert schema['handler_config_schemas']['file_check']['poll_interval_seconds']['maximum'] == 30 assert 'generic' in schema['handler_config_schemas']