refactor(shipping-inventory): 统一库存准备事实来源与门禁状态

This commit is contained in:
hugo committed 2026-09-04 20:23:00 +08:00
1 parent 761a06e21a
commit eb55f407ae
62 files changed
+4242 -1471

No files matched your search

@@ -82,14 +82,18 @@ def test_gate_action_contract_rejects_inventory_reroute_for_excel_gate():
) is True
def test_inventory_preparation_allows_reload_existing_result_without_rpa():
"""RPA 超时后可重读已有库存结果;该动作仅属于库存准备 Gate。"""
def test_inventory_preparation_timeout_prefers_merged_rematch_without_standalone_reload():
"""RPA 超时后主恢复已合并为 retry_inventory_matching(复用快照重匹配,无则 RPA);
reload_inventory_result 不再作为独立主动作。retry_inventory_matching 现属库存准备/匹配/充足性 Gate。"""
assert action_belongs_to_gate(
gate_code='inventory_preparation', action_code='reload_inventory_result',
gate_code='inventory_preparation', action_code='retry_inventory_matching',
) is True
assert action_belongs_to_gate(
gate_code='inventory_matching', action_code='reload_inventory_result',
) is False
gate_code='inventory_matching', action_code='retry_inventory_matching',
) is True
assert action_belongs_to_gate(
gate_code='inventory_sufficiency', action_code='retry_inventory_matching',
) is True
def test_inventory_sufficiency_actions_keep_business_specific_labels():
@@ -233,8 +237,10 @@ def test_inventory_matching_recovery_keeps_review_entry_when_primary_is_technica
assert summary['next_action_code'] == 'open_inventory_match_review'
assert summary['owner_type'] == 'human'
assert summary['technical_auto_only'] is False
# 侧路动作(override_line_inventory_source,方案 3·放开)先于 RecoveryPlan 复核入口。
assert summary['allowed_actions'] == [
'open_inventory_match_review',
'override_line_inventory_source',
'retry_inventory_from_preparation',
]
@@ -275,6 +281,7 @@ def test_formal_inventory_matching_uses_only_executable_retries(app, monkeypatch
assert summary['next_action_code'] == 'retry_inventory_matching'
assert summary['allowed_actions'] == [
'retry_inventory_matching',
'override_line_inventory_source',
'retry_inventory_from_preparation',
]
assert summary['recovery_targets'] == [
@@ -287,7 +294,7 @@ def test_inventory_shortage_with_active_snapshot_projects_rematch_and_rpa_refres
from app import db
from app.models import (
ShippingInventoryFile,
ShippingNotice,
ShippingOrderTask,
ShippingProcessExecution,
ShippingProcessGate,
ShippingTaskInventoryLink,
@@ -296,10 +303,7 @@ def test_inventory_shortage_with_active_snapshot_projects_rematch_and_rpa_refres
inventory_path = tmp_path / 'active-inventory.xlsx'
inventory_path.write_bytes(b'confirmed inventory')
task = ShippingNotice(
task_no='SN-SUFFICIENCY-ACTIVE-SNAPSHOT',
inventory_lines_json=[{'part_number': 'P-1', 'available_qty': 2}],
)
task = ShippingOrderTask(task_no='OT-SUFFICIENCY-ACTIVE-SNAPSHOT', user_id=1)
inventory_file = ShippingInventoryFile(
inventory_file_no='SIF-SUFFICIENCY-ACTIVE-SNAPSHOT',
storage_path=str(inventory_path),
@@ -440,11 +444,16 @@ def test_inventory_preparation_exposes_only_rpa_retry(app, monkeypatch):
assert summary['next_action_code'] == 'retry_inventory_preparation'
assert summary['primary_action']['code'] == 'retry_inventory_preparation'
assert summary['allowed_actions'] == ['retry_inventory_preparation']
# 库存准备不再提供库存文件上传旁路;主线仅重试 RPA,并保留行级库存源人工覆写(方案 3·放开)。
assert summary['allowed_actions'] == [
'retry_inventory_preparation',
'override_line_inventory_source',
]
def test_inventory_rpa_timeout_prefers_reload_existing_result(app, monkeypatch):
"""RPA 超时先重读已落盘结果,不能把主按钮直接指向新的 RPA 请求。"""
def test_inventory_rpa_timeout_prefers_merged_rematch(app, monkeypatch):
"""RPA 超时主恢复已合并为 retry_inventory_matching(复用快照重匹配,无则 RPA),
不再直接指向孤立的 reload_inventory_result 或新 RPA 请求。"""
from types import SimpleNamespace
from app.services.shipping_notice import process_gate_projection as projection
@@ -472,11 +481,14 @@ def test_inventory_rpa_timeout_prefers_reload_existing_result(app, monkeypatch):
summary = projection.project_user_gate_summary(execution)
assert summary['next_action_code'] == 'reload_inventory_result'
assert summary['primary_action']['code'] == 'reload_inventory_result'
assert summary['next_action_code'] == 'retry_inventory_matching'
assert summary['primary_action']['code'] == 'retry_inventory_matching'
# 主动作=复用快照重匹配(无则 RPA);侧路保留 retry_inventory_preparation(显式 RPA 重试)与
# override_line_inventory_source(行级库存源人工覆写,方案 3·放开)。
assert summary['allowed_actions'] == [
'reload_inventory_result',
'retry_inventory_matching',
'retry_inventory_preparation',
'override_line_inventory_source',
]
@@ -614,7 +626,7 @@ def test_inventory_source_gate_summary_exposes_no_manual_selection_action(app, m
summary = projection.project_user_gate_summary(execution)
assert summary['allowed_actions'] == []
assert summary['allowed_actions'] == ['override_line_inventory_source']
def test_process_gate_dependency_integrity_and_excel_only_scope():