feat(shipping-notice): 完成货代发货通知全门禁恢复MVP收口

完成全门禁恢复MVP版本交付:调整自动上传与重试配置,重构正式执行链路;修复多处代码bug,新增测试与审计工具;更新全流程文档与契约规范。
This commit is contained in:
hugo committed 2026-08-11 14:04:39 +08:00
1 parent 8e0bbf7a81
commit c94d173f92
181 files changed
+12947 -1724

No files matched your search

@@ -59,6 +59,10 @@ def _seed_blocked_execution(owner: User | None = None):
execution_id=int(execution.id),
gate_code='order_freeze_readiness',
).first()
# 夹具显式将阻断 Gate 设为 Execution.current_gate,覆盖前置 Gate 默认初始状态,
# 以便 API 测试验证当前 Gate 的统一写校验。
execution.current_gate_code = gate.gate_code
execution.primary_next_action_code = gate.next_action_code
db.session.commit()
return user, execution, gate
@@ -86,6 +90,19 @@ def _seed_blocked_execution_for_agent_readonly():
)
ensure_order_extraction_plan(run)
cases = ensure_run_review_cases(run=run)
if not cases:
# 当前最小 API 夹具可能没有完整 Worker Candidate;仍创建只读授权所需的
# 正式 Case 绑定,测试只验证权限边界,不把缺失 Candidate 伪装成业务成功。
from app.models import ShippingOrderReviewCase
unit = run.extraction_plan.units[0] if run.extraction_plan and run.extraction_plan.units else None
if unit is not None and unit.document_id:
case = ShippingOrderReviewCase(
case_no=f'SORC-API-FALLBACK-{run.id}', run_id=int(run.id), unit_id=int(unit.id),
document_id=int(unit.document_id), owner_user_id=int(user.id), status='draft',
)
db.session.add(case)
db.session.flush()
cases = [case]
assert cases, 'review case required for agent authorization path'
case = cases[0]
execution = ensure_execution_for_workflow_version(
@@ -224,6 +241,51 @@ def test_workspace_post_action_idempotent(app, client):
assert ShippingProcessGateAttempt.query.filter_by(idempotency_key='api-idempotent-1').count() == 1
def test_workspace_post_action_rejects_non_current_gate_for_all_gate_actions(app, client):
"""所有阶段统一禁止绕过 current_gate 写入其他 Gate。"""
with app.app_context():
owner, execution, gate = _seed_blocked_execution()
# order_freeze_readiness 是当前阻断;请求另一个正式 Gate 必须 fail-closed。
other_gate = ShippingProcessGate.query.filter_by(
execution_id=int(execution.id), gate_code='inventory_matching',
).first()
assert other_gate is not None
resp = client.post(
f'/api/workspace/shipping-notice/process-executions/{execution.execution_no}'
'/gates/inventory_matching/actions',
headers=_auth_headers(owner),
json={
'action_code': 'open_inventory_match_review',
'expected_gate_version': int(other_gate.evaluation_version),
'idempotency_key': 'api-non-current-gate-1',
},
)
assert resp.status_code == 400
assert resp.get_json().get('error', {}).get('code') == 'SHIPPING.PROCESS_GATE_NOT_CURRENT'
def test_workspace_post_action_rejects_terminal_execution_for_all_gate_actions(app, client):
"""所有阶段统一禁止 completed/cancelled Execution 写动作。"""
with app.app_context():
owner, execution, gate = _seed_blocked_execution()
execution.status = 'completed'
db.session.commit()
resp = client.post(
f'/api/workspace/shipping-notice/process-executions/{execution.execution_no}'
f'/gates/{gate.gate_code}/actions',
headers=_auth_headers(owner),
json={
'action_code': 'open_order_review',
'expected_gate_version': int(gate.evaluation_version),
'idempotency_key': 'api-terminal-execution-1',
},
)
assert resp.status_code == 400
assert resp.get_json().get('error', {}).get('code') == 'SHIPPING.PROCESS_EXECUTION_TERMINAL'
def test_workspace_get_missing_execution_404(app, client):
"""不存在的 execution_no 返回 404。"""
with app.app_context():