""" tests/test_shipping_process_gate_contract.py 用途:锁定全门禁中断恢复 Phase 1/1.5 契约与依赖图完整性(编码、动作、失效范围、原因归属)。 依赖:process_gate_contract、process_gate_dependency。 逻辑:调用 assert_*_integrity;断言 20 个唯一门禁(含 freight_upload_rpa)、 原因码唯一 owning_gate、字段阻断资格与 Excel 仅重生失效范围。 """ from __future__ import annotations from app.services.shipping_notice.process_gate_contract import ( AUTO_BUILD_LEGACY_GATE_OWNING_MAP, PROCESS_GATE_CODES, PROCESS_GATE_CODE_SET, PROCESS_GATE_DEFINITIONS, PROCESS_GATE_REASON_OWNING_GATE, action_belongs_to_gate, assert_process_gate_contract_integrity, action_presentation, field_quality_may_block, owning_gate_for_reason, primary_next_action_for_gate, ) from app.services.shipping_notice.process_gate_dependency import ( PROCESS_GATE_INVALIDATION_RULES, assert_process_gate_dependency_integrity, compute_invalidated_gates, ) def test_process_gate_contract_integrity(): """ 校验门禁契约无重复编码、序号连续且动作/状态闭环。 核心逻辑:直接调用契约自检;再断言恰好 20 个唯一 gate_code。 """ # [STEP 1] 契约自检(重复码 / 序号 / 动作归属) assert_process_gate_contract_integrity() # [STEP 2] 冻结规模:20 门禁(含 freight_upload_rpa)且集合与有序列表一致 assert len(PROCESS_GATE_DEFINITIONS) == 20 assert len(PROCESS_GATE_CODES) == 20 assert len(PROCESS_GATE_CODE_SET) == 20 assert set(PROCESS_GATE_CODES) == PROCESS_GATE_CODE_SET assert 'freight_upload_rpa' in PROCESS_GATE_CODE_SET assert owning_gate_for_reason('upload_rpa_pending') == 'freight_upload_rpa' assert owning_gate_for_reason('manual_upload_pending') == 'manual_upload_handoff' def test_inventory_source_routing_primary_retry_action(): """ 库存源路由在 blocked_retryable 时主恢复动作必须为按最新规则重试。 核心逻辑:primary_next_action_for_gate 禁止前端本地推导。 """ action = primary_next_action_for_gate( gate_code='inventory_source_routing', status='blocked_retryable', ) assert action == 'retry_with_latest_rules' assert primary_next_action_for_gate( gate_code='inventory_source_routing', status='blocked_manual', ) == 'retry_with_latest_rules' assert action_belongs_to_gate( gate_code='inventory_source_routing', action_code='open_inventory_source_review', ) is False assert action_belongs_to_gate( gate_code='inventory_field_mapping', action_code='confirm_inventory_field_mapping', ) is False def test_gate_action_contract_rejects_inventory_reroute_for_excel_gate(): """库存源重路由动作绝不能被 Excel Gate 自动入队。""" assert action_belongs_to_gate( gate_code='excel_readiness', action_code='retry_with_latest_rules', ) is False assert action_belongs_to_gate( gate_code='excel_readiness', action_code='recheck_excel_readiness', ) is True 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='retry_inventory_matching', ) is True assert action_belongs_to_gate( 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(): """库存缺口恢复必须保留精确业务动作,禁止客户端降级为统一“重试”。""" assert action_presentation('open_shortage_review') == { 'code': 'open_shortage_review', 'label_key': 'workspace.shippingNotice.processGate.actionCodes.open_shortage_review', 'kind': 'current_gate', 'dispatch': 'navigation', 'ui_handler': 'shortage_review', } assert action_presentation('retry_inventory_from_matching') == { 'code': 'retry_inventory_from_matching', 'label_key': 'workspace.shippingNotice.processGate.actionCodes.retry_inventory_from_matching', 'kind': 'recovery', 'dispatch': 'mutation', } def test_fulfillment_action_presentation_declares_lifecycle_surface(): """动作位置必须继承当前 Gate,而非维护 action_code 到位置的映射。""" assert action_presentation( 'regenerate_excel_artifact', gate_code='artifact_generation', )['target_surface'] == 'fulfillment_prep' assert action_presentation( 'retry_freight_upload_rpa', gate_code='freight_upload_rpa', )['target_surface'] == 'freight_upload' assert action_presentation( 'regenerate_manual_upload_todo', gate_code='manual_upload_handoff', )['target_surface'] == 'freight_upload' assert action_presentation( 'mark_manual_uploaded', gate_code='manual_upload_handoff', )['target_surface'] == 'freight_upload' def test_manual_upload_handoff_authorizes_excel_regeneration_at_artifact_anchor(): """已到人工上传交接时,Excel 重生仍须由当前 Gate 合法授权并回到产物位置。""" from app.services.shipping_notice.recovery_plan_contract import recovery_plan_for_action assert action_belongs_to_gate( gate_code='manual_upload_handoff', action_code='regenerate_excel_artifact', ) is True plan = recovery_plan_for_action( current_gate='manual_upload_handoff', action_code='regenerate_excel_artifact', ) assert plan['ui_placement'] == { 'target_surface': 'fulfillment_prep', 'target_anchor': 'excel_artifact', } def test_gate_action_presentation_declares_ui_dispatch_without_frontend_action_code_inference(): """非 mutation 动作必须由合同明确其页面宿主能力。""" assert action_presentation('mark_manual_uploaded') == { 'code': 'mark_manual_uploaded', 'label_key': 'workspace.shippingNotice.processGate.actionCodes.mark_manual_uploaded', 'kind': 'current_gate', 'dispatch': 'dialog', 'ui_handler': 'manual_upload_confirmation', } assert action_presentation('confirm_customer') == { 'code': 'confirm_customer', 'label_key': 'workspace.shippingNotice.processGate.actionCodes.confirm_customer', 'kind': 'current_gate', 'dispatch': 'navigation', 'ui_handler': 'customer_resolution', } def test_every_gate_declares_a_surface_and_anchor_for_its_actions(): """所有 Gate 的动作位置必须在 Gate 定义处声明,避免前端或动作码映射猜测。""" for gate in PROCESS_GATE_DEFINITIONS: placement = gate['ui_placement'] for action in (gate.get('default_next_actions') or {}).values(): if action: presentation = action_presentation(action, gate_code=gate['gate_code']) assert presentation is not None assert presentation['target_surface'] == placement['target_surface'] assert presentation['target_anchor'] == placement['target_anchor'] def test_process_gate_reason_ownership_is_unique(): """ 每个阻断原因码恰好映射一个 owning_gate,覆盖率 100%。 核心逻辑:契约自检 + 显式抽查自动冻结与字段完整性归属。 """ assert_process_gate_contract_integrity() assert owning_gate_for_reason('profile_manual_confirmation_required') == 'order_freeze_readiness' assert owning_gate_for_reason('required_field_missing') == 'field_completeness' assert owning_gate_for_reason('customer_unresolved') == 'customer_resolution' assert owning_gate_for_reason('evidence_missing') == 'order_field_extraction' # 旧五门禁键不得再各自成为用户阻断真相。 assert AUTO_BUILD_LEGACY_GATE_OWNING_MAP['quality_gate_passed'] == 'order_freeze_readiness' assert AUTO_BUILD_LEGACY_GATE_OWNING_MAP['approved_template'] == 'order_freeze_readiness' assert len(PROCESS_GATE_REASON_OWNING_GATE) == len(set(PROCESS_GATE_REASON_OWNING_GATE.keys())) def test_field_quality_block_eligibility(): """仅 required 或 auto_create_key_field 可因字段质量阻断。""" assert field_quality_may_block(required=True, auto_create_key_field=False) is True assert field_quality_may_block(required=False, auto_create_key_field=True) is True assert field_quality_may_block(required=False, auto_create_key_field=False) is False def test_inventory_matching_recovery_keeps_review_entry_when_primary_is_technical(app, monkeypatch): """库存匹配技术重试被隐藏时,跨阶段 RecoveryPlan 仍必须保留人工复核入口。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-INV-1', status='blocked', current_gate_code='inventory_matching', primary_next_action_code='retry_inventory_matching', responsible_party='worker', lock_version=1, review_case_id=None, task_id=None, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-INV-1', 'status': 'blocked', 'primary_next_action_code': 'retry_inventory_matching', 'responsible_party': 'worker', 'current_gate': { 'gate_code': 'inventory_matching', 'status': 'blocked_manual', 'blocking_reason_code': 'inventory_match_incomplete', 'next_action_code': 'retry_inventory_matching', }, 'recovery_targets': [ {'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'}, ], 'gates': [], 'active_recovery_plans': [], }, ) summary = projection.project_user_gate_summary(execution) assert summary['current_blocking_gate']['gate_code'] == 'inventory_matching' 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', ] def test_formal_inventory_matching_uses_only_executable_retries(app, monkeypatch): """正式 OT 库存匹配阻断不得投影无写操作的复核入口。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-INV-OT-1', status='blocked', current_gate_code='inventory_matching', primary_next_action_code='open_inventory_match_review', responsible_party='worker', lock_version=1, review_case_id=None, task_id=99, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-INV-OT-1', 'status': 'blocked', 'primary_next_action_code': 'open_inventory_match_review', 'responsible_party': 'worker', 'current_gate': { 'gate_code': 'inventory_matching', 'status': 'blocked_manual', 'blocking_reason_code': 'inventory_match_incomplete', 'next_action_code': 'open_inventory_match_review', }, 'recovery_targets': [ {'action_code': 'open_inventory_match_review', 'target_gate': 'inventory_matching'}, {'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'}, ], 'gates': [], 'active_recovery_plans': [], }, ) summary = projection.project_user_gate_summary(execution) 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'] == [ {'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'}, ] def test_inventory_shortage_with_active_snapshot_projects_rematch_and_rpa_refresh(app, tmp_path): """库存不足时,已确认的活动 Excel 必须可重匹配;重新获取库存才是第二入口。""" from app import db from app.models import ( ShippingInventoryFile, ShippingOrderTask, ShippingProcessExecution, ShippingProcessGate, ShippingTaskInventoryLink, ) from app.services.shipping_notice.process_gate_projection import project_user_gate_summary inventory_path = tmp_path / 'active-inventory.xlsx' inventory_path.write_bytes(b'confirmed inventory') 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), snapshot_status='ready', mapping_confirmed=True, inventory_lines_json=[{'part_number': 'P-1', 'available_qty': 2}], line_count=1, ) db.session.add_all([task, inventory_file]) db.session.flush() db.session.add(ShippingTaskInventoryLink( task_id=int(task.id), inventory_file_id=int(inventory_file.id), is_active=True, )) execution = ShippingProcessExecution( execution_no='EXE-SUFFICIENCY-ACTIVE-SNAPSHOT', task_id=int(task.id), status='blocked', current_gate_code='inventory_sufficiency', lock_version=1, ) db.session.add(execution) db.session.flush() db.session.add(ShippingProcessGate( execution_id=int(execution.id), gate_code='inventory_sufficiency', sequence_no=16, status='blocked_manual', evaluation_version=1, blocking_reason_code='inventory_insufficient', next_action_code='open_shortage_review', )) db.session.flush() summary = project_user_gate_summary(execution) # 有效 Excel 是匹配的输入事实;缺口只阻断履约决定,不能迫使用户再次抓取文件。 assert summary['next_action_code'] == 'retry_inventory_matching' assert summary['allowed_actions'] == [ 'retry_inventory_matching', 'retry_inventory_preparation', ] assert [item['action_code'] for item in summary['recovery_targets']] == [ 'retry_inventory_preparation', ] def test_user_gate_summary_exposes_sanitized_failure_detail_for_any_gate(app, monkeypatch): """所有 Gate 均应把当前 Attempt 的脱敏失败详情投影给用户,而非只显示泛化原因。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-FAIL-1', status='blocked', current_gate_code='artifact_generation', primary_next_action_code='regenerate_excel_artifact', responsible_party='system', lock_version=1, review_case_id=None, task_id=None, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-FAIL-1', 'status': 'blocked', 'primary_next_action_code': 'regenerate_excel_artifact', 'responsible_party': 'system', 'recovery_targets': [], 'gates': [], 'active_recovery_plans': [], 'current_gate': { 'gate_code': 'artifact_generation', 'status': 'blocked_retryable', 'blocking_reason_code': 'artifact_generation_failed', 'next_action_code': 'regenerate_excel_artifact', 'latest_attempt': { 'attempt_no': 7, 'status': 'failed', 'error_code': 'SHIPPING.EXCEL_ARTIFACT_WRITE_FAILED', 'error_summary': r'Excel 写入失败 at C:\worker\output.xlsx password=secret', }, }, }, ) summary = projection.project_user_gate_summary(execution) assert summary['failure_detail'] is not None assert 'Excel 写入失败' in summary['failure_detail'] assert '[path]' in summary['failure_detail'] assert 'secret' not in summary['failure_detail'] def test_user_gate_summary_repairs_stale_rpa_action_for_gate19(app, monkeypatch): """历史 Gate 19 即使持久化了人工待办动作,也必须投影为 RPA 重试。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-RPA-STALE', status='blocked', current_gate_code='freight_upload_rpa', primary_next_action_code='regenerate_manual_upload_todo', responsible_party='worker', lock_version=1, review_case_id=None, task_id=None, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-RPA-STALE', 'status': 'blocked', 'primary_next_action_code': 'regenerate_manual_upload_todo', 'responsible_party': 'worker', 'recovery_targets': [], 'active_recovery_plans': [], 'gates': [], 'current_gate': { 'gate_code': 'freight_upload_rpa', 'status': 'blocked_manual', 'blocking_reason_code': 'upload_platform_rejected', 'next_action_code': 'regenerate_manual_upload_todo', }, }, ) summary = projection.project_user_gate_summary(execution) assert summary['next_action_code'] == 'retry_freight_upload_rpa' assert summary['owner_type'] == 'human' def test_inventory_preparation_exposes_only_rpa_retry(app, monkeypatch): """库存准备不再提供库存文件上传旁路,仅允许重试 RPA。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-INVENTORY-1', status='blocked', current_gate_code='inventory_preparation', primary_next_action_code='retry_inventory_preparation', responsible_party='worker', lock_version=1, review_case_id=None, task_id=99, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-INVENTORY-1', 'status': 'blocked', 'primary_next_action_code': 'retry_inventory_preparation', 'responsible_party': 'worker', 'recovery_targets': [], 'active_recovery_plans': [], 'gates': [], 'current_gate': { 'gate_code': 'inventory_preparation', 'status': 'blocked_manual', 'blocking_reason_code': 'inventory_file_empty', 'next_action_code': 'retry_inventory_preparation', 'evaluation_version': 3, }, }, ) summary = projection.project_user_gate_summary(execution) assert summary['next_action_code'] == 'retry_inventory_preparation' assert summary['primary_action']['code'] == 'retry_inventory_preparation' # 库存准备不再提供库存文件上传旁路;主线仅重试 RPA,并保留行级库存源人工覆写(方案 3·放开)。 assert summary['allowed_actions'] == [ 'retry_inventory_preparation', 'override_line_inventory_source', ] 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 execution = SimpleNamespace( id=1, execution_no='EXE-INVENTORY-TIMEOUT', status='blocked', current_gate_code='inventory_preparation', primary_next_action_code='retry_inventory_preparation', responsible_party='worker', lock_version=1, review_case_id=None, task_id=99, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-INVENTORY-TIMEOUT', 'status': 'blocked', 'primary_next_action_code': 'retry_inventory_preparation', 'responsible_party': 'worker', 'recovery_targets': [], 'active_recovery_plans': [], 'gates': [], 'current_gate': { 'gate_code': 'inventory_preparation', 'status': 'blocked_retryable', 'blocking_reason_code': 'inventory_rpa_timeout', 'next_action_code': 'retry_inventory_preparation', 'evaluation_version': 3, }, }, ) summary = projection.project_user_gate_summary(execution) 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'] == [ 'retry_inventory_matching', 'retry_inventory_preparation', 'override_line_inventory_source', ] def test_user_gate_summary_exposes_manual_gate_evidence_and_rpa_retry(app, monkeypatch): """Gate 20 保持凭据登记主动作,并显式下发可选 RPA 重试。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-MANUAL-RPA', status='blocked', current_gate_code='manual_upload_handoff', primary_next_action_code='regenerate_manual_upload_todo', responsible_party='owner', lock_version=1, review_case_id=None, task_id=None, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-MANUAL-RPA', 'status': 'blocked', 'primary_next_action_code': 'regenerate_manual_upload_todo', 'responsible_party': 'owner', 'recovery_targets': [], 'active_recovery_plans': [], 'gates': [], 'current_gate': { 'gate_code': 'manual_upload_handoff', 'status': 'blocked_manual', 'blocking_reason_code': 'manual_upload_pending', 'next_action_code': 'regenerate_manual_upload_todo', }, }, ) summary = projection.project_user_gate_summary(execution) assert summary['next_action_code'] == 'mark_manual_uploaded' assert summary['allowed_actions'] == [ 'mark_manual_uploaded', 'retry_freight_upload_rpa', ] assert summary['owner_type'] == 'human' def test_manual_upload_handoff_projects_evidence_confirmation_as_primary_action(app, monkeypatch): """Gate 20 必须引导受控凭据登记,不得再重生待办或直接声称上传完成。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-MANUAL-CONFIRM', status='blocked', current_gate_code='manual_upload_handoff', primary_next_action_code='regenerate_manual_upload_todo', responsible_party='owner', lock_version=1, review_case_id=None, task_id=99, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-MANUAL-CONFIRM', 'status': 'blocked', 'primary_next_action_code': 'regenerate_manual_upload_todo', 'responsible_party': 'owner', 'recovery_targets': [], 'active_recovery_plans': [], 'gates': [], 'current_gate': { 'gate_code': 'manual_upload_handoff', 'status': 'blocked_manual', 'blocking_reason_code': 'manual_upload_pending', 'next_action_code': 'regenerate_manual_upload_todo', 'evaluation_version': 3, }, }, ) summary = projection.project_user_gate_summary(execution) assert summary['next_action_code'] == 'mark_manual_uploaded' assert summary['allowed_actions'] == [ 'mark_manual_uploaded', 'retry_freight_upload_rpa', ] assert summary['primary_action']['target_surface'] == 'freight_upload' assert summary['primary_action']['target_anchor'] == 'manual_upload' def test_manual_upload_handoff_hides_excel_regeneration_for_single_notice(app, monkeypatch): """同一 Notice 只能有一个 Excel,上传阶段不得投影重生入口。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-MANUAL-EXCEL', status='blocked', current_gate_code='manual_upload_handoff', primary_next_action_code='regenerate_manual_upload_todo', responsible_party='owner', lock_version=1, review_case_id=None, task_id=99, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-MANUAL-EXCEL', 'status': 'blocked', 'primary_next_action_code': 'regenerate_manual_upload_todo', 'responsible_party': 'owner', 'active_recovery_plans': [], 'gates': [], 'recovery_targets': [{'action_code': 'regenerate_excel_artifact'}], 'current_gate': { 'gate_code': 'manual_upload_handoff', 'status': 'blocked_manual', 'blocking_reason_code': 'manual_upload_pending', 'next_action_code': 'regenerate_manual_upload_todo', 'evaluation_version': 3, }, }, ) summary = projection.project_user_gate_summary(execution) assert 'regenerate_excel_artifact' not in summary['allowed_actions'] assert all(item['code'] != 'regenerate_excel_artifact' for item in summary['action_presentation']) def test_inventory_source_gate_summary_exposes_no_manual_selection_action(app, monkeypatch): """库存源路由只允许自动重算,Gate 卡不得暴露人工选源或确认。""" from types import SimpleNamespace from app.services.shipping_notice import process_gate_projection as projection execution = SimpleNamespace( id=1, execution_no='EXE-ROUTING', status='blocked', current_gate_code='inventory_source_routing', primary_next_action_code='retry_with_latest_rules', responsible_party='system', lock_version=1, review_case_id=None, task_id=99, ) monkeypatch.setattr( projection, 'serialize_process_execution', lambda _execution, include_diagnostics=False: { 'execution_no': 'EXE-ROUTING', 'status': 'blocked', 'primary_next_action_code': 'retry_with_latest_rules', 'responsible_party': 'system', 'recovery_targets': [], 'active_recovery_plans': [], 'gates': [], 'current_gate': { 'gate_code': 'inventory_source_routing', 'status': 'blocked_manual', 'blocking_reason_code': 'no_inventory_source_candidates', 'next_action_code': 'retry_with_latest_rules', 'evaluation_version': 3, }, }, ) summary = projection.project_user_gate_summary(execution) assert summary['allowed_actions'] == ['override_line_inventory_source'] def test_process_gate_dependency_integrity_and_excel_only_scope(): """ 校验依赖图完整性,并锁定「仅重生 Excel」不得失效库存匹配。 核心逻辑:依赖自检 + excel_regeneration_only 显式排除 inventory_matching。 """ # [STEP 1] 前置依赖与失效规则仅引用已知门禁 assert_process_gate_dependency_integrity() # [STEP 2] 仅重生 Excel:失效 artifact + 人工上传,不碰库存匹配 excel_only = compute_invalidated_gates('excel_regeneration_only') assert 'inventory_matching' not in excel_only assert 'artifact_generation' in excel_only assert 'freight_upload_rpa' in excel_only assert 'manual_upload_handoff' in excel_only assert set(excel_only) == set(PROCESS_GATE_INVALIDATION_RULES['excel_regeneration_only'])