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

@@ -16,6 +16,54 @@ from app.services.shipping_notice.conversation_retry_auto_progress_service impor
)
def test_formal_trigger_failure_overrides_stale_automation(monkeypatch):
"""最新 Attempt 的 Trigger 缺失事实优先于历史 Job 的 needs_human 投影。"""
from app.services.shipping_notice import conversation_retry_auto_progress_service as service
task = type('Task', (), {'task_no': 'OT-TRIGGER', 'id': 1})()
class _Query:
def filter_by(self, **_kwargs):
return self
def first(self):
return task
monkeypatch.setattr(service.ShippingNotice, 'query', _Query(), raising=False)
monkeypatch.setattr(
'app.services.shipping_notice.task_retry_decision_service.summarize_inventory_rpa_latest_attempts',
lambda *_args, **_kwargs: {
'latest_attempts': {
'DSV360_AWSSL': {
'status': 'failed',
'error_code': 'trigger_not_claimed_missing',
},
},
},
)
assert service._formal_task_has_retryable_inventory_trigger_failure('OT-TRIGGER') is True
def test_failed_gate_job_does_not_count_as_active_attempt(monkeypatch):
"""Attempt 残留 queued 但正式 Job 已失败时,不得继续投影 already_running。"""
from app.services.shipping_notice import conversation_retry_auto_progress_service as service
task = type('Task', (), {'task_no': 'OT-STALE', 'id': 1})()
class _Query:
def filter_by(self, **_kwargs):
return self
def first(self):
return task
monkeypatch.setattr(service.ShippingNotice, 'query', _Query(), raising=False)
monkeypatch.setattr(
'app.services.shipping_notice.task_retry_decision_service.summarize_inventory_rpa_latest_attempts',
lambda *_args, **_kwargs: {'active_attempt_count': 0},
)
assert service._formal_task_has_active_attempt('OT-STALE') is False
def test_skip_reason_maps_queued_and_not_retryable():
"""queued → already_running;retryable=false → not_retryable。"""
assert _skip_reason_from_automation(
@@ -40,6 +88,42 @@ def test_manual_fallback_human_owner_still_retryable():
) is None
def test_inventory_needs_human_remains_retryable():
"""库存快照/RPA 暂态 needs_human 必须继续进入库存重试决策器。"""
assert _skip_reason_from_automation(
{
'status': 'needs_human',
'retryable': True,
'reason_code': 'inventory_snapshot_prepare_failed',
},
task_missing=False,
) is None
def test_missing_inventory_trigger_needs_human_remains_retryable():
"""Trigger 未被领取的技术失败必须继续触发正式 OT 库存重试。"""
assert _skip_reason_from_automation(
{
'status': 'needs_human',
'retryable': True,
'error_code': 'trigger_not_claimed_missing',
},
task_missing=False,
) is None
def test_business_needs_human_stays_skipped():
"""重复/短缺等业务裁决的 needs_human 不得触发库存 RPA。"""
assert _skip_reason_from_automation(
{
'status': 'needs_human',
'retryable': True,
'reason_code': 'inventory_shortage',
},
task_missing=False,
) == 'human_blocking'
def test_task_missing_always_skipped():
assert _skip_reason_from_automation(
{'status': 'failed', 'retryable': True},
@@ -54,7 +138,7 @@ def test_summarize_items_counts_outcomes():
{'outcome': 'skipped', 'reason_code': 'already_running'},
{'outcome': 'failed'},
])
assert summary == {'total': 4, 'retried': 2, 'skipped': 1, 'failed': 1}
assert summary == {'total': 4, 'retried': 2, 'skipped': 1, 'failed': 1, 'blocked': 0}
def test_project_conversation_allowed_actions_empty_without_conversation():