feat: 报销审批流重构与管家计划全链路贯通
- 重构报销状态注册表、审批流路由与平台风险标记 - 完善管家意图规划器与模型计划构建器全链路 - 新增 OCR Worker 脚本、数据库会话管理与通知状态 - 优化文档中心、日志视图、预算中心与员工管理交互 - 增强工作台摘要、图标资源与全局主题样式 - 补充审批路由、状态注册、OCR 服务与管家规划器测试覆盖
This commit is contained in:
96
server/tests/test_steward_runtime_decision_agent.py
Normal file
96
server/tests/test_steward_runtime_decision_agent.py
Normal file
@@ -0,0 +1,96 @@
|
||||
from app.schemas.steward import StewardRuntimeDecisionRequest
|
||||
from app.services.steward_runtime_decision_agent import (
|
||||
STEWARD_RUNTIME_DECISION_FUNCTION_NAME,
|
||||
StewardRuntimeDecisionAgent,
|
||||
)
|
||||
|
||||
|
||||
class _FakeToolCall:
|
||||
def __init__(self, name, arguments):
|
||||
self.name = name
|
||||
self.arguments = arguments
|
||||
|
||||
|
||||
class _FakeRuntimeResult:
|
||||
def __init__(self, tool_call=None):
|
||||
self.tool_call = tool_call
|
||||
|
||||
def calls_as_dicts(self):
|
||||
return [{"tool": self.tool_call.name if self.tool_call else ""}]
|
||||
|
||||
|
||||
class _FakeRuntime:
|
||||
def __init__(self, payload):
|
||||
self.payload = payload
|
||||
self.last_messages = []
|
||||
self.last_tools = []
|
||||
self.last_tool_choice = None
|
||||
|
||||
def complete_with_tool_call(self, messages, tools, tool_choice, **kwargs):
|
||||
self.last_messages = messages
|
||||
self.last_tools = tools
|
||||
self.last_tool_choice = tool_choice
|
||||
if self.payload is None:
|
||||
return _FakeRuntimeResult()
|
||||
return _FakeRuntimeResult(_FakeToolCall(STEWARD_RUNTIME_DECISION_FUNCTION_NAME, self.payload))
|
||||
|
||||
|
||||
def test_steward_runtime_decision_uses_function_calling_context():
|
||||
runtime = _FakeRuntime(
|
||||
{
|
||||
"next_action": "submit_current_application",
|
||||
"target_task_id": "task-application-beijing",
|
||||
"target_message_id": "msg-application-preview",
|
||||
"field_key": "",
|
||||
"field_value": "",
|
||||
"confirmation_required": False,
|
||||
"question": "",
|
||||
"response_text": "",
|
||||
"rationale": "用户确认当前申请核对表无误。",
|
||||
}
|
||||
)
|
||||
|
||||
result = StewardRuntimeDecisionAgent(runtime).decide(
|
||||
StewardRuntimeDecisionRequest(
|
||||
user_message="确认",
|
||||
runtime_state={
|
||||
"waiting_for": "application_submit_confirmation",
|
||||
"pending_application": {
|
||||
"message_id": "msg-application-preview",
|
||||
"task_id": "task-application-beijing",
|
||||
"ready_to_submit": True,
|
||||
},
|
||||
"remaining_tasks": [
|
||||
{"task_id": "task-reimbursement-meal", "task_type": "reimbursement"}
|
||||
],
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
assert result.decision_source == "llm_function_call"
|
||||
assert result.next_action == "submit_current_application"
|
||||
assert result.target_message_id == "msg-application-preview"
|
||||
assert result.target_task_id == "task-application-beijing"
|
||||
assert runtime.last_tool_choice["function"]["name"] == STEWARD_RUNTIME_DECISION_FUNCTION_NAME
|
||||
assert "runtime_state" in runtime.last_messages[-1]["content"]
|
||||
|
||||
|
||||
def test_steward_runtime_decision_fallback_keeps_current_context():
|
||||
runtime = _FakeRuntime(None)
|
||||
|
||||
result = StewardRuntimeDecisionAgent(runtime).decide(
|
||||
StewardRuntimeDecisionRequest(
|
||||
user_message="确认",
|
||||
runtime_state={
|
||||
"pending_steward_action": {
|
||||
"message_id": "msg-next-task",
|
||||
"target_task_id": "task-reimbursement-meal",
|
||||
}
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
assert result.decision_source == "rule_fallback"
|
||||
assert result.next_action == "continue_next_task"
|
||||
assert result.target_message_id == "msg-next-task"
|
||||
assert result.target_task_id == "task-reimbursement-meal"
|
||||
Reference in New Issue
Block a user