fix(shipping-notice): 修复抽取失败摘要卡死与 PO scope 持久化校验
sync 仅对 auto poll 提前 complete,retry_inventory_preparation 交外层统一收口,防止 Attempt already finished 误成技术失败
This commit is contained in:
1 parent
a2931e0095
commit
76729df27c
9 files changed
+287
-25
No files matched your search
@@ -86,6 +86,20 @@ def test_approved_pdf_keeps_one_order_when_only_one_po_is_proven():
|
||||
assert len(orders or []) == 1
|
||||
|
||||
|
||||
def test_approved_pdf_promotes_unique_po_to_header_and_strips_line_copies():
|
||||
"""唯一 PO 提升到 Header 后,明细行不得残留同 field_id,否则持久化会因 scope 失败。"""
|
||||
orders, reason = _build_approved_profile_order_result(
|
||||
unit=SimpleNamespace(document_id=9), intake={'intake_no': 'SNI-1'}, schema=SCHEMA,
|
||||
definition=DEFINITION, table={'rows': [_row('PO-1', 'P-1'), _row('PO-1', 'P-2')]},
|
||||
)
|
||||
assert reason is None
|
||||
order = (orders or [])[0]
|
||||
assert any(item['field_id'] == 'po' for item in order['header_fields'])
|
||||
for line in order['lines']:
|
||||
assert not any(item['field_id'] == 'po' for item in line['fields'])
|
||||
assert {item['field_id'] for item in order['lines'][0]['fields']} == {'part', 'qty'}
|
||||
|
||||
|
||||
def test_approved_pdf_writes_unnumbered_reservation_to_header_and_line_value_to_its_row():
|
||||
"""同一证据区可同时提供整单默认 Reservation 与指定行覆盖值。"""
|
||||
orders, reason = _build_approved_profile_order_result(
|
||||
|
||||
@@ -2689,6 +2689,12 @@ def test_final_order_extraction_job_failure_marks_queued_run_failed(app):
|
||||
assert failed_run.error_code == 'SHIPPING_NOTICE.ORDER_EXTRACTION_JOB_FAILED'
|
||||
assert event.job_id == job.id
|
||||
assert intake.order_extraction_status == 'failed'
|
||||
# 关键断言:附件 Document 必须同步 failed,否则首屏摘要仍投影为「系统处理中」。
|
||||
document = ShippingOrderDocument.query.filter_by(intake_id=intake.id).filter(
|
||||
ShippingOrderDocument.document_type != 'email_body',
|
||||
).one()
|
||||
assert document.order_extraction_status == 'failed'
|
||||
assert document.order_extraction_error_code == 'SHIPPING_NOTICE.ORDER_EXTRACTION_JOB_FAILED'
|
||||
|
||||
|
||||
def test_failed_run_retry_reuses_snapshot_and_execution_result(app):
|
||||
|
||||
@@ -631,6 +631,110 @@ def test_business_sync_reuses_same_gate_active_attempt(app):
|
||||
assert ShippingProcessGateAttempt.query.filter_by(gate_id=int(gate.id)).count() == 1
|
||||
|
||||
|
||||
def test_inventory_ready_sync_leaves_retry_preparation_attempt_for_outer_complete(app):
|
||||
"""库存已就绪时,sync 不得提前收口 retry_inventory_preparation Attempt。
|
||||
|
||||
回归:OT 自动推进复用 ready 快照后,handler 内 sync 见 has_inventory_lines=True
|
||||
若提前 complete,外层 execute_queued_attempt 再 complete 会抛
|
||||
Attempt already finished,Job rollback 后收成 technical_failure_present,
|
||||
界面卡在获取库存(真实单 OT-20260908-95514841)。
|
||||
|
||||
契约:非 poll 的活动准备 Attempt 由外层统一 complete;sync 只返回、不收口。
|
||||
"""
|
||||
from app.services.shipping_notice.process_gate_service import (
|
||||
complete_gate_attempt,
|
||||
mark_attempt_running,
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
_user, review_case_id, task_id = _seed_workflow_version(suffix='invreadyouter')
|
||||
execution = ensure_execution_for_workflow_version(
|
||||
review_case_id=review_case_id,
|
||||
task_id=task_id,
|
||||
)
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
trigger_type='auto',
|
||||
actor_type='system',
|
||||
actor_id=None,
|
||||
idempotency_key='inv-ready-outer-complete',
|
||||
input_snapshot={
|
||||
'action_code': 'retry_inventory_preparation',
|
||||
'payload': {'trigger': 'gate_attempt_passed'},
|
||||
},
|
||||
)
|
||||
mark_attempt_running(attempt_id=int(attempt.id), worker_id='inv-ready-outer')
|
||||
|
||||
gate = sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
passed=True,
|
||||
effective_result_json={
|
||||
'findings': [],
|
||||
'has_inventory_lines': True,
|
||||
'derived_fulfillment_status': 'inventory_ready',
|
||||
},
|
||||
idempotency_key='inv-ready-must-not-early-complete',
|
||||
)
|
||||
|
||||
db.session.refresh(attempt)
|
||||
assert gate.status == 'running'
|
||||
assert attempt.status == 'running'
|
||||
assert ShippingProcessGateAttempt.query.filter_by(gate_id=int(gate.id)).count() == 1
|
||||
|
||||
# [断言] 外层唯一收口可成功;不得再抛 Attempt already finished。
|
||||
completed = complete_gate_attempt(
|
||||
attempt_id=int(attempt.id),
|
||||
outcome='passed',
|
||||
effective_result_json={'findings': [], 'tool_status': 'ok'},
|
||||
output_snapshot={'action_code': 'retry_inventory_preparation'},
|
||||
)
|
||||
assert completed.status == 'passed'
|
||||
db.session.refresh(attempt)
|
||||
assert attempt.status == 'succeeded'
|
||||
|
||||
|
||||
def test_inventory_ready_sync_still_completes_auto_poll_attempt(app):
|
||||
"""poll_inventory_preparation 无外层 complete,sync 在库存就绪时仍须收口。"""
|
||||
from app.services.shipping_notice.process_gate_service import mark_attempt_running
|
||||
|
||||
with app.app_context():
|
||||
_user, review_case_id, task_id = _seed_workflow_version(suffix='invreadypoll')
|
||||
execution = ensure_execution_for_workflow_version(
|
||||
review_case_id=review_case_id,
|
||||
task_id=task_id,
|
||||
)
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
trigger_type='auto',
|
||||
actor_type='system',
|
||||
actor_id='external-wait-poll',
|
||||
idempotency_key='inv-ready-poll-complete',
|
||||
input_snapshot={
|
||||
'action_code': 'poll_inventory_preparation',
|
||||
'payload': {'poll': True},
|
||||
},
|
||||
)
|
||||
mark_attempt_running(attempt_id=int(attempt.id), worker_id='inv-ready-poll')
|
||||
|
||||
gate = sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
passed=True,
|
||||
effective_result_json={
|
||||
'findings': [],
|
||||
'has_inventory_lines': True,
|
||||
},
|
||||
idempotency_key='inv-ready-poll-must-complete',
|
||||
)
|
||||
|
||||
db.session.refresh(attempt)
|
||||
assert gate.status == 'passed'
|
||||
assert attempt.status == 'succeeded'
|
||||
|
||||
|
||||
def test_business_sync_does_not_swallow_passed_when_gate_has_active_user_attempt(app):
|
||||
"""活动 Attempt 不得吞掉 sync 的 passed 结论。
|
||||
|
||||
|
||||
@@ -396,7 +396,14 @@ def test_failed_run_overrides_stale_unit_review_stage_for_eml_leaf(app) -> None:
|
||||
|
||||
assert leaves[0]['user_status'] == 'failed'
|
||||
assert leaves[0]['user_stage'] == 'document_parsing'
|
||||
assert leaves[0]['primary_action'] is None
|
||||
# Run 已失败且无 Case 时必须授权重解析,不能只标失败却无恢复入口。
|
||||
assert leaves[0]['primary_action'] == {
|
||||
'code': 'reparse',
|
||||
'variant': 'primary',
|
||||
'label_key': 'shipping.actions.reparse',
|
||||
}
|
||||
assert leaves[0]['available_actions'] == ['reparse']
|
||||
assert leaves[0]['run_no'] == run.run_no
|
||||
|
||||
|
||||
def test_eml_leaf_preserves_case_business_action_instead_of_replacing_it_with_navigation(app) -> None:
|
||||
@@ -1346,19 +1353,28 @@ def test_summary_includes_the_same_file_status_counts_used_by_batch_overview(app
|
||||
"""首屏摘要必须下发四个文件状态数,避免概览总数与状态数来自不同合同。"""
|
||||
with app.app_context():
|
||||
from tests.test_shipping_order_extraction_runs import _seed_run_input
|
||||
from app.services.shipping_notice.order_extraction_run_service import create_order_extraction_run
|
||||
|
||||
user, _agent, session, intake, document = _seed_run_input(
|
||||
suffix='SUMMARY-FILE-STATUS-COUNTS',
|
||||
)
|
||||
intake.source_type = 'eml'
|
||||
run, _ = create_order_extraction_run(
|
||||
user=user,
|
||||
agent_id=_agent.id,
|
||||
conversation_id=session.session_id,
|
||||
intake_nos=[intake.intake_no],
|
||||
)
|
||||
# 模拟 Unit/Run 失败后 Document 已回写 failed(首屏摘要的权威输入)。
|
||||
document.order_extraction_status = 'failed'
|
||||
document.order_extraction_error_code = 'processing_failed'
|
||||
db.session.commit()
|
||||
|
||||
summary = project_conversation_processing_summary(
|
||||
projection = project_conversation_processing_summary(
|
||||
user_id=user.id,
|
||||
conversation_id=session.session_id,
|
||||
)['conversation_processing']['summary']
|
||||
)['conversation_processing']
|
||||
summary = projection['summary']
|
||||
|
||||
# 关键断言:总文件与四个互斥状态数同源,批次概览不能因缺字段降为全 0。
|
||||
assert summary['total_files'] == 1
|
||||
@@ -1366,6 +1382,9 @@ def test_summary_includes_the_same_file_status_counts_used_by_batch_overview(app
|
||||
assert summary['waiting_human_files'] == 0
|
||||
assert summary['processing_files'] == 0
|
||||
assert summary['completed_files'] == 0
|
||||
failed_leaf = projection['status_groups']['failed'][0]['aggregate_children'][0]
|
||||
assert failed_leaf['run_no'] == run.run_no
|
||||
assert failed_leaf['ui_state']['primary_action']['code'] == 'reparse'
|
||||
|
||||
|
||||
def test_summary_splits_mixed_eml_leaves_and_counts_each_file_status(app) -> None:
|
||||
|
||||
Reference in new issue
Block a user