feat: 统一治理配置与通知责任人映射
This commit is contained in:
@@ -2,6 +2,7 @@ from agent_core.orchestrator import build_messages, run_agent
|
||||
from agent_core.rag.ingest import _split_text, ingest_document
|
||||
from agent_core.rag.retriever import retrieve
|
||||
from agent_core.schemas.outputs import SUPPORTED_OUTPUT_TYPES
|
||||
from django.test import override_settings
|
||||
|
||||
|
||||
def test_run_agent_returns_structured_result_from_llm_output():
|
||||
@@ -352,3 +353,110 @@ def test_registration_risk_report_builds_eight_business_nodes():
|
||||
assert result.node_results[5]["status"] == "已阻断"
|
||||
assert result.node_results[6]["status"] == "待处理"
|
||||
assert result.node_results[7]["status"] == "待处理"
|
||||
|
||||
|
||||
@override_settings(GOVERNANCE_CONFIG_PATH="")
|
||||
def test_registration_risk_payload_falls_back_to_governance_owner_mappings(tmp_path):
|
||||
config_path = tmp_path / "governance.yaml"
|
||||
config_path.write_text(
|
||||
"""
|
||||
owner_mappings:
|
||||
- owner_role: 法规负责人
|
||||
owner_name: 赵六
|
||||
department: 法规事务部
|
||||
chapter_scope: CH1
|
||||
risk_scope: 高风险缺失
|
||||
feishu_user_id: ou_governance_1
|
||||
feishu_open_id: on_governance_1
|
||||
feishu_name: 赵六
|
||||
notify_enabled: 是
|
||||
""".strip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
scenario = {
|
||||
"id": "document_review",
|
||||
"name": "注册审核智能体",
|
||||
"agent": {
|
||||
"role": "注册审核助手",
|
||||
"goal": "输出风险结果",
|
||||
"instructions": ["输出结构化风险结果"],
|
||||
},
|
||||
"rag": {"enabled": False},
|
||||
"tools": [],
|
||||
"output": {"type": "registration_risk_report"},
|
||||
}
|
||||
provider_response = """
|
||||
{
|
||||
"summary": "存在高风险项,需人工复核。",
|
||||
"highest_risk_level": "high",
|
||||
"pass_status": "blocked",
|
||||
"owner_roles": [],
|
||||
"notify_reason": "task_completed"
|
||||
}
|
||||
"""
|
||||
|
||||
class FakeProvider:
|
||||
def generate(self, messages, response_format=None):
|
||||
from agent_core.llm_provider import LLMResponse
|
||||
|
||||
return LLMResponse(content=provider_response, model_name="demo-model", success=True)
|
||||
|
||||
with override_settings(GOVERNANCE_CONFIG_PATH=config_path):
|
||||
result = run_agent(scenario, "请输出风险结果", options={"llm_provider": FakeProvider()})
|
||||
|
||||
owner = result.notification_payload["owners"][0]
|
||||
assert owner["owner_role"] == "法规负责人"
|
||||
assert owner["feishu_user_id"] == "ou_governance_1"
|
||||
assert result.notification_payload["notify_reason"] == "task_completed"
|
||||
|
||||
|
||||
@override_settings(GOVERNANCE_CONFIG_PATH="")
|
||||
def test_failed_agent_result_uses_governance_owner_mappings_for_failed_notification(tmp_path):
|
||||
config_path = tmp_path / "governance.yaml"
|
||||
config_path.write_text(
|
||||
"""
|
||||
owner_mappings:
|
||||
- owner_role: 注册资料负责人
|
||||
owner_name: 孙七
|
||||
department: 注册事务部
|
||||
chapter_scope: CH2
|
||||
risk_scope: 执行异常
|
||||
feishu_user_id: ou_failed_1
|
||||
feishu_open_id: on_failed_1
|
||||
feishu_name: 孙七
|
||||
notify_enabled: 是
|
||||
""".strip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
scenario = {
|
||||
"id": "document_review",
|
||||
"name": "注册审核智能体",
|
||||
"agent": {
|
||||
"role": "注册审核助手",
|
||||
"goal": "输出风险结果",
|
||||
"instructions": ["输出结构化风险结果"],
|
||||
},
|
||||
"rag": {"enabled": False},
|
||||
"tools": [],
|
||||
"output": {"type": "registration_risk_report"},
|
||||
}
|
||||
|
||||
class FailedProvider:
|
||||
def generate(self, messages, response_format=None):
|
||||
from agent_core.llm_provider import LLMResponse
|
||||
|
||||
return LLMResponse(
|
||||
content="",
|
||||
model_name="demo-model",
|
||||
success=False,
|
||||
error="provider down",
|
||||
)
|
||||
|
||||
with override_settings(GOVERNANCE_CONFIG_PATH=config_path):
|
||||
result = run_agent(scenario, "请输出风险结果", options={"llm_provider": FailedProvider()})
|
||||
|
||||
owner = result.notification_payload["owners"][0]
|
||||
assert result.status == "failed"
|
||||
assert result.notification_payload["notify_reason"] == "task_failed"
|
||||
assert owner["owner_name"] == "孙七"
|
||||
assert owner["feishu_open_id"] == "on_failed_1"
|
||||
|
||||
Reference in New Issue
Block a user