feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -9,11 +9,17 @@ tests/test_shipping_process_gate_api.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from app import db
|
||||
from app.core.auth.jwt import issue_local_access_token
|
||||
from app.models import Agent, ShippingProcessGate, ShippingProcessGateAttempt, User
|
||||
from app.services.shipping_notice.process_gate_bridge import apply_gate_outcome
|
||||
from app.services.shipping_notice.order_extraction_plan import ensure_order_extraction_plan
|
||||
from app.services.shipping_notice.order_extraction_run_service import create_order_extraction_run
|
||||
from app.services.shipping_notice.order_review_service import ensure_run_review_cases
|
||||
from app.services.shipping_notice.process_gate_service import ensure_execution_for_workflow_version
|
||||
from tests.test_shipping_order_extraction_runs import _seed_run_input
|
||||
from tests.test_shipping_process_gate_service import _seed_workflow_version
|
||||
|
||||
|
||||
@@ -24,20 +30,19 @@ def _auth_headers(user: User) -> dict[str, str]:
|
||||
|
||||
def _seed_blocked_execution(owner: User | None = None):
|
||||
"""
|
||||
创建属主 WorkflowItem + Execution,并将 order_freeze_readiness 置为 blocked_manual。
|
||||
创建属主 Task + Execution,并将 order_freeze_readiness 置为 blocked_manual。
|
||||
|
||||
Args:
|
||||
owner: 可选属主;非空时 Task 绑定该用户。
|
||||
|
||||
Returns:
|
||||
(owner, execution, gate)
|
||||
"""
|
||||
suffix = f'api{owner.id if owner else "x"}'[:24]
|
||||
user, item, version = _seed_workflow_version(suffix=suffix)
|
||||
if owner is not None:
|
||||
item.owner_user_id = int(owner.id)
|
||||
db.session.flush()
|
||||
user = owner
|
||||
user, _review_case_id, task_id = _seed_workflow_version(suffix=suffix, owner=owner)
|
||||
execution = ensure_execution_for_workflow_version(
|
||||
workflow_item_id=int(item.id),
|
||||
workflow_item_version_id=int(version.id),
|
||||
review_case_id=None,
|
||||
task_id=task_id,
|
||||
actor_type='system',
|
||||
actor_id=int(user.id),
|
||||
)
|
||||
@@ -58,6 +63,54 @@ def _seed_blocked_execution(owner: User | None = None):
|
||||
return user, execution, gate
|
||||
|
||||
|
||||
def _seed_blocked_execution_for_agent_readonly():
|
||||
"""
|
||||
创建带 ReviewCase 的 Execution,供同 Run.owner_agent 授权人员只读验收。
|
||||
|
||||
核心逻辑:ensure_run_review_cases 物化 Case → Execution 绑定 review_case_id。
|
||||
|
||||
Returns:
|
||||
(owner, execution, gate, agent)
|
||||
"""
|
||||
user, agent, session, intake, _document = _seed_run_input(suffix='API-AGENT-GATE')
|
||||
with patch(
|
||||
'app.services.shipping_notice.order_extraction_run_service.schedule_order_extraction_layouts',
|
||||
return_value=True,
|
||||
):
|
||||
run, _ = create_order_extraction_run(
|
||||
user=user,
|
||||
agent_id=agent.id,
|
||||
conversation_id=session.session_id,
|
||||
intake_nos=[intake.intake_no],
|
||||
keep_input_open=True,
|
||||
)
|
||||
ensure_order_extraction_plan(run)
|
||||
cases = ensure_run_review_cases(run=run)
|
||||
assert cases, 'review case required for agent authorization path'
|
||||
case = cases[0]
|
||||
execution = ensure_execution_for_workflow_version(
|
||||
review_case_id=int(case.id),
|
||||
task_id=None,
|
||||
actor_type='system',
|
||||
actor_id=int(user.id),
|
||||
)
|
||||
apply_gate_outcome(
|
||||
execution=execution,
|
||||
gate_code='order_freeze_readiness',
|
||||
passed=False,
|
||||
blocking_reason_code='auto_freeze_not_enabled',
|
||||
effective_result={'findings': []},
|
||||
force=True,
|
||||
idempotency_key=f'api-freeze-agent-{execution.execution_no}',
|
||||
)
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=int(execution.id),
|
||||
gate_code='order_freeze_readiness',
|
||||
).first()
|
||||
db.session.commit()
|
||||
return user, execution, gate, agent
|
||||
|
||||
|
||||
def test_workspace_get_execution_owner_ok_other_forbidden(app, client):
|
||||
"""属主可 GET Execution;未授权他人返回 403。"""
|
||||
with app.app_context():
|
||||
@@ -89,26 +142,14 @@ def test_workspace_get_execution_owner_ok_other_forbidden(app, client):
|
||||
def test_workspace_agent_authorized_readonly_cannot_write(app, client):
|
||||
"""同 Agent 授权人员可 GET,但 POST 恢复仍 403。"""
|
||||
with app.app_context():
|
||||
owner, execution, gate = _seed_blocked_execution()
|
||||
agent = Agent(
|
||||
name='Gate Readonly Agent',
|
||||
agent_code='gate_readonly_agent',
|
||||
dify_app_id='gate-readonly-app',
|
||||
dify_api_key='test-key',
|
||||
)
|
||||
owner, execution, gate, agent = _seed_blocked_execution_for_agent_readonly()
|
||||
viewer = User(username='gate-api-viewer', email='gate-api-viewer@example.com', password_hash='x')
|
||||
db.session.add_all([agent, viewer])
|
||||
db.session.add(viewer)
|
||||
db.session.flush()
|
||||
from app.models import ShippingNoticeWorkflow, ShippingNoticeWorkflowItem
|
||||
|
||||
item = db.session.get(ShippingNoticeWorkflowItem, int(execution.workflow_item_id))
|
||||
assert item is not None
|
||||
workflow = db.session.get(ShippingNoticeWorkflow, int(item.workflow_id))
|
||||
assert workflow is not None
|
||||
workflow.owner_agent_id = int(agent.id)
|
||||
viewer.agents = [agent]
|
||||
db.session.commit()
|
||||
execution_no = execution.execution_no
|
||||
assert execution.review_case_id is not None
|
||||
|
||||
read_ok = client.get(
|
||||
f'/api/workspace/shipping-notice/process-executions/{execution_no}',
|
||||
|
||||
Reference in new issue
Block a user