refactor(agent, shipping): 简化代理模型并完善订单抽取业务
- 移除 Agent 的 exposure_mode 与 internal_executor 相关逻辑,清理关联的过滤、序列化代码 - 删除废弃的 AgentRuntimeBinding 模型及其依赖 - 新增订单抽取上传批次、请求快照等数据库迁移与业务逻辑 - 修复附件完整性检测、订单抽取状态映射问题 - 更新多语言错误文案与前端单元测试配置 - 清理平台配置中不再使用的暴露模式配置
This commit is contained in:
1 parent
1f3ecb87b7
commit
61ac6403c4
159 files changed
+12883
-5099
No files matched your search
@@ -7,7 +7,7 @@ import pytest
|
||||
|
||||
from app import db
|
||||
from app.core.errors import NotFoundError, ValidationError
|
||||
from app.models import Agent, AgentRuntimeBinding, User
|
||||
from app.models import Agent, User
|
||||
from app.services.admin import agent_service
|
||||
|
||||
|
||||
@@ -85,87 +85,6 @@ def test_update_agent_clears_handler_config_when_explicit_null(app):
|
||||
assert refreshed.handler_config is None
|
||||
|
||||
|
||||
def test_create_agent_and_runtime_binding_are_atomic(app):
|
||||
"""创建货代 Agent 时绑定校验失败必须回滚 Agent,不能留下半配置入口。"""
|
||||
with app.app_context():
|
||||
provider = Agent(
|
||||
name='Invalid Chatflow Provider',
|
||||
agent_code='generic',
|
||||
runtime_provider='dify',
|
||||
dify_app_type='chatflow',
|
||||
exposure_mode='workspace',
|
||||
dify_app_id='invalid-create-provider',
|
||||
dify_api_key='sk-test',
|
||||
api_base_url='http://dify.example/v1',
|
||||
is_active=True,
|
||||
)
|
||||
db.session.add(provider)
|
||||
db.session.commit()
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
agent_service.create_agent({
|
||||
'name': 'Atomic Shipping Create',
|
||||
'agent_code': 'shipping_notice',
|
||||
'runtime_provider': 'hybrid',
|
||||
'conversation_mode': 'task_chat',
|
||||
'dify_app_id': 'atomic-shipping-create',
|
||||
'dify_api_key': 'sk-test',
|
||||
'api_base_url': 'http://dify.example/v1',
|
||||
'order_extraction_runtime_binding': {
|
||||
'provider_agent_id': provider.id,
|
||||
'enabled': True,
|
||||
'config': {'timeout_seconds': 900, 'max_attempts': 3},
|
||||
},
|
||||
})
|
||||
db.session.rollback()
|
||||
|
||||
assert Agent.query.filter_by(name='Atomic Shipping Create').count() == 0
|
||||
assert AgentRuntimeBinding.query.count() == 0
|
||||
|
||||
|
||||
def test_update_agent_and_runtime_binding_are_atomic(app):
|
||||
"""更新 Agent 时绑定校验失败必须回滚 Agent 字段,避免配置只保存一半。"""
|
||||
with app.app_context():
|
||||
owner = Agent(
|
||||
name='Atomic Shipping Update',
|
||||
description='before',
|
||||
agent_code='shipping_notice',
|
||||
runtime_provider='hybrid',
|
||||
conversation_mode='task_chat',
|
||||
dify_app_id='atomic-shipping-update',
|
||||
dify_api_key='sk-test',
|
||||
api_base_url='http://dify.example/v1',
|
||||
is_active=True,
|
||||
)
|
||||
provider = Agent(
|
||||
name='Invalid Update Provider',
|
||||
agent_code='generic',
|
||||
runtime_provider='dify',
|
||||
dify_app_type='chatflow',
|
||||
exposure_mode='workspace',
|
||||
dify_app_id='invalid-update-provider',
|
||||
dify_api_key='sk-test',
|
||||
api_base_url='http://dify.example/v1',
|
||||
is_active=True,
|
||||
)
|
||||
db.session.add_all([owner, provider])
|
||||
db.session.commit()
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
agent_service.update_agent(owner.id, {
|
||||
'description': 'after',
|
||||
'order_extraction_runtime_binding': {
|
||||
'provider_agent_id': provider.id,
|
||||
'enabled': True,
|
||||
'config': {'timeout_seconds': 900, 'max_attempts': 3},
|
||||
},
|
||||
})
|
||||
db.session.rollback()
|
||||
|
||||
assert db.session.get(Agent, owner.id).description == 'before'
|
||||
assert AgentRuntimeBinding.query.filter_by(owner_agent_id=owner.id).count() == 0
|
||||
|
||||
|
||||
def test_update_agent_permissions(app):
|
||||
with app.app_context():
|
||||
agent = Agent(
|
||||
|
||||
Reference in new issue
Block a user