"""T4.8 Agent 编排引擎测试。 测试 L1-L4 分级自治的 Agent 编排。 """ import pytest from app.services.agent_orchestrator import AUTONOMY_LEVELS, orchestrate_agent class TestOrchestrateAgent: """Agent 编排测试。""" async def test_l1_requires_approval(self): """L1 级别需要人工审核。""" result = await orchestrate_agent("test_agent", "L1", {"task": "测试任务"}) assert result["requires_approval"] is True assert result["status"] == "pending_approval" async def test_l2_requires_approval(self): """L2 级别需要人工确认。""" result = await orchestrate_agent("test_agent", "L2", {"task": "测试任务"}) assert result["requires_approval"] is True assert result["status"] == "pending_approval" async def test_l3_post_review(self): """L3 级别事后审核。""" result = await orchestrate_agent("test_agent", "L3", {"task": "测试任务"}) assert result["requires_approval"] is False assert result["requires_post_review"] is True assert result["status"] == "executed" async def test_l4_requires_approval(self): """L4 级别人工决策。""" result = await orchestrate_agent("test_agent", "L4", {"task": "测试任务"}) assert result["requires_approval"] is True async def test_unknown_level_defaults_l1(self): """未知级别默认 L1。""" result = await orchestrate_agent("test_agent", "L9", {"task": "测试任务"}) assert result["requires_approval"] is True async def test_input_summary_truncated(self): """输入摘要被截断。""" long_input = {"data": "x" * 500} result = await orchestrate_agent("test_agent", "L1", long_input) assert len(result["input_summary"]) <= 200 class TestAutonomyLevels: """自治级别配置测试。""" def test_all_levels_defined(self): """L1-L4 全部定义。""" assert "L1" in AUTONOMY_LEVELS assert "L2" in AUTONOMY_LEVELS assert "L3" in AUTONOMY_LEVELS assert "L4" in AUTONOMY_LEVELS def test_level_has_description(self): """每个级别有描述。""" for level, config in AUTONOMY_LEVELS.items(): assert "description" in config assert len(config["description"]) > 0