fix(shipping-notice): 有效订单值视图贯通履约链并补全行结案豁免

- 新增 effective_order_view:冻结快照+人工修正按(行position×field_id)对位叠加,整行替换后行级叠加保守跳过
- 库存匹配(order_field_purposes)、Excel值(export)、通知行物化(notice_line_service.line_overrides)统一消费有效值
- 行结案close_unfulfillable端到端豁免:聚合/match_completed/整单建通知/滚动导出四处剔除结案行(含有库存结案行)
- 结案决定落库后触发Gate重算(trigger=line_fulfillment_closed),对齐放行路径
- 兜底匹配分支切有效视图基线;全结案聚合口径与门禁一致(unfulfillable)
- 预约门禁断言更新为有效视图契约;文档同步technical.md/funclist(含结案时序规约)
This commit is contained in:
hugo committed 2026-09-18 01:46:47 +08:00
1 parent 0333d713e0
commit 051f80e1e9
17 files changed
+2212 -43

No files matched your search

+175
View File
@@ -0,0 +1,175 @@
"""
tests/test_effective_order_view.py
用途:验证「冻结快照 + 冻结后人工修正」的有效订单值视图。
依赖:pytest、effective_order_view、task_order_field_editor、订单 Schema/快照模型。
逻辑:覆盖行级修正对位叠加、快照不可变、整行替换后的保守跳过与 Notice 行事实投影。
"""
from __future__ import annotations
from decimal import Decimal
from types import SimpleNamespace
from app import db
from app.models import (
ShippingNotice,
ShippingOrderExtraction,
ShippingOrderFieldDecision,
ShippingOrderFieldValue,
ShippingOrderLine,
ShippingOrderSchema,
ShippingOrderSchemaVersion,
ShippingOrderSnapshot,
ShippingOrderSnapshotLine,
ShippingOrderTask,
User,
)
from app.services.shipping_notice.effective_order_view import (
effective_line_facts_for_notice,
effective_order_field_values,
)
from app.services.shipping_notice.order_field_purposes import task_line_purpose_values
from app.services.shipping_notice.task_order_field_editor import (
replace_current_line_field_value,
replace_current_line_fields,
)
def _seed_frozen_order():
"""最小冻结订单夹具:OT + accepted Extraction(两行三字段)+ 冻结快照。"""
user = User(username='eff-view-user', email='eff-view@test.local', role='user', status='active')
db.session.add(user)
schema = ShippingOrderSchema(schema_code='EFFVIEW', display_name='EffView')
db.session.add(schema)
db.session.flush()
version = ShippingOrderSchemaVersion(
schema_id=schema.id, version=1, status='published',
definition_json={'fields': [
{'field_id': 'f-part', 'field_code': 'part_number', 'scope': 'line', 'value_type': 'string', 'field_category': 'order_line', 'sequence': 1, 'enabled': True},
{'field_id': 'f-rsv', 'field_code': 'reservation_id', 'scope': 'line', 'value_type': 'string', 'field_category': 'order_line', 'sequence': 2, 'enabled': True},
{'field_id': 'f-qty', 'field_code': 'qty', 'scope': 'line', 'value_type': 'decimal', 'field_category': 'order_line', 'sequence': 3, 'enabled': True},
]},
)
db.session.add(version)
db.session.flush()
order = ShippingOrderTask(task_no='OT-EFFVIEW-1', source_type='direct_pdf', user_id=user.id)
db.session.add(order)
db.session.flush()
extraction = ShippingOrderExtraction(
task_id=order.id, schema_version_id=version.id, input_snapshot_hash='a' * 64, status='accepted',
)
db.session.add(extraction)
db.session.flush()
snapshot = ShippingOrderSnapshot(
task_id=order.id, extraction_id=extraction.id, schema_version_id=version.id,
order_data_version=1,
rule_versions_json={'fulfillment_rule': {'required_field_ids': {
'part_number': 'f-part', 'reservation_id': 'f-rsv', 'qty': 'f-qty',
}}},
header_values_json={},
)
db.session.add(snapshot)
db.session.flush()
snap_lines = []
for position, part in enumerate(('D4-A08AR12000002-', 'D4-B07BR07000001')):
line = ShippingOrderLine(extraction_id=extraction.id, position=position, line_no=position + 1)
db.session.add(line)
db.session.flush()
for field_id, value in (('f-part', part), ('f-rsv', f'RSV-{position + 1}'), ('f-qty', '10')):
decision = ShippingOrderFieldDecision(
extraction_id=extraction.id, line_id=line.id, field_id=field_id,
decision_status='accepted', resolved_value_json=value,
)
db.session.add(decision)
db.session.flush()
db.session.add(ShippingOrderFieldValue(
extraction_id=extraction.id, line_id=line.id, field_id=field_id, decision_id=decision.id,
value_text=str(value), value_json=value,
))
snap_line = ShippingOrderSnapshotLine(
snapshot_id=snapshot.id, position=position, line_no=position + 1,
part_number=part, reservation_id=f'RSV-{position + 1}', qty=Decimal('10'),
field_values_json={'f-part': part, 'f-rsv': f'RSV-{position + 1}', 'f-qty': '10'},
)
db.session.add(snap_line)
db.session.flush()
snap_lines.append(snap_line)
order.current_order_extraction_id = extraction.id
order.order_snapshot_id = snapshot.id
db.session.flush()
return SimpleNamespace(user=user, order=order, extraction=extraction, snapshot=snapshot, snap_lines=snap_lines)
def test_edited_part_number_flows_into_effective_values(app):
"""冻结后人工修正料号,有效视图必须返回修正值(匹配/Excel 的读取口径)。"""
with app.app_context():
fixture = _seed_frozen_order()
replace_current_line_field_value(
task=fixture.order, position=0, field_code='part_number', value='D4-A08AR12000002',
)
_header, lines = effective_order_field_values(fixture.order)
# 断言:第 0 行为修正值、第 1 行保持冻结值,证明对位叠加只影响被改行。
assert lines[0]['f-part'] == 'D4-A08AR12000002'
assert lines[1]['f-part'] == 'D4-B07BR07000001'
def test_snapshot_stays_frozen_after_edit(app):
"""有效视图不得回写快照:冻结事实仍是审计锚点。"""
with app.app_context():
fixture = _seed_frozen_order()
replace_current_line_field_value(
task=fixture.order, position=0, field_code='part_number', value='D4-A08AR12000002',
)
# 断言:快照强类型列与 field_values_json 均保持冻结原值。
assert fixture.snap_lines[0].part_number == 'D4-A08AR12000002-'
assert fixture.snap_lines[0].field_values_json['f-part'] == 'D4-A08AR12000002-'
def test_line_set_replacement_skips_line_overlay(app):
"""整行替换后 position 不再可比:行级叠加保守跳过,返回冻结行值。"""
with app.app_context():
fixture = _seed_frozen_order()
# 注:替换行不带 qty——编辑服务会把 decimal 字段归一为 Decimal 写入 JSON 列(SQLite/PG
# 默认 json.dumps 均不可序列化),此既有路径与本测试的行集替换守卫无关,故省略。
replace_current_line_fields(task=fixture.order, lines=[
{'part_number': 'D4-A08AR12000002', 'reservation_id': 'RSV-1'},
])
_header, lines = effective_order_field_values(fixture.order)
# 断言:行级叠加被守卫跳过(行集维度属后续特性),值仍来自冻结快照两行原样。
assert [row['f-part'] for row in lines] == ['D4-A08AR12000002-', 'D4-B07BR07000001']
def test_effective_line_facts_for_notice(app):
"""Notice 行物化事实按冻结规则映射强类型键并携带修正值。"""
with app.app_context():
fixture = _seed_frozen_order()
replace_current_line_field_value(
task=fixture.order, position=0, field_code='part_number', value='D4-A08AR12000002',
)
facts = effective_line_facts_for_notice(fixture.order)
first = facts[int(fixture.snap_lines[0].id)]
# 断言:料号为修正值,数量被安全转为 Decimal,字段值字典完整。
assert first['part_number'] == 'D4-A08AR12000002'
assert first['reservation_id'] == 'RSV-1'
assert first['qty'] == Decimal('10')
assert first['field_values']['f-rsv'] == 'RSV-1'
def test_matching_purpose_values_use_effective_view(app):
"""库存匹配用途投影必须读到修正后的料号(修复改值不进匹配的断层)。"""
with app.app_context():
fixture = _seed_frozen_order()
replace_current_line_field_value(
task=fixture.order, position=0, field_code='part_number', value='D4-A08AR12000002',
)
notice = ShippingNotice(
task_no='SN-EFFVIEW-1', source_type='manual', user_id=fixture.user.id,
order_task_id=fixture.order.id,
)
db.session.add(notice)
db.session.flush()
purpose_values = task_line_purpose_values(notice)
# 断言:第 0 行用途值为修正料号,第 1 行保持冻结值。
assert purpose_values[0]['part_number'] == 'D4-A08AR12000002'
assert purpose_values[1]['part_number'] == 'D4-B07BR07000001'
+65
View File
@@ -0,0 +1,65 @@
"""
tests/test_line_closure_export.py
用途:验证滚动导出资格对已结案行的剔除(含"有库存的结案行也不导出"边缘场景)。
依赖:pytest、reservation_service、fulfillment_workflow、核验/预约模型、行级履约决定。
逻辑:两行均有可用预约,结案其一后,导出资格集合只保留未结案行。
"""
from __future__ import annotations
from decimal import Decimal
from app import db
from app.models import (
ShippingInventoryVerification,
ShippingInventoryVerificationLine,
ShippingReservation,
)
from app.services.shipping_notice.fulfillment_workflow import exportable_snapshot_line_ids
from app.services.shipping_notice.reservation_service import current_available_snapshot_line_ids
from tests.test_effective_order_view import _seed_frozen_order
from tests.test_line_closure_fulfillment import _seed_close_decision
def _seed_available_reservations(fixture):
"""两行各建一条 available 预约 + 一轮 completed 核验。"""
verification = ShippingInventoryVerification(task_id=fixture.order.id, status='completed')
db.session.add(verification)
db.session.flush()
for index, snap_line in enumerate(fixture.snap_lines):
reservation = ShippingReservation(
task_id=fixture.order.id, snapshot_line_id=snap_line.id,
reservation_id=f'RSV-CLOSE-{index}', po_number_normalized='PO-CLOSE',
part_number=snap_line.part_number, required_qty=Decimal('10'), status='available',
)
db.session.add(reservation)
db.session.flush()
db.session.add(ShippingInventoryVerificationLine(
verification_id=verification.id, reservation_id=reservation.id,
required_qty=Decimal('10'), available_qty=Decimal('10'), status='available',
))
db.session.flush()
def test_closed_line_with_inventory_is_not_exportable(app):
"""结案行即使库存充足、核验 available 也不得进入导出资格集合。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_available_reservations(fixture)
_seed_close_decision(fixture, 1)
_verification, available = current_available_snapshot_line_ids(
fixture.order, closed_snapshot_line_ids={int(fixture.snap_lines[1].id)},
)
# 断言:仅未结案的第 0 行可导出。
assert available == {int(fixture.snap_lines[0].id)}
def test_exportable_snapshot_line_ids_excludes_closed(app):
"""滚动导出入口(exportable_snapshot_line_ids)自动剔除结案行。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_available_reservations(fixture)
_seed_close_decision(fixture, 1)
# 断言:导出集合不含结案行(该行预约仍 available,验证 closed 过滤优先)。
assert exportable_snapshot_line_ids(fixture.order) == {int(fixture.snap_lines[0].id)}
@@ -0,0 +1,141 @@
"""
tests/test_line_closure_fulfillment.py
用途:验证行结案(close_unfulfillable)在满足性聚合与整单门禁中的豁免语义。
依赖:pytest、fulfillment_workflow、行级履约决定模型、冻结订单夹具。
逻辑:两行订单关闭短缺行后整单应判定满足;全部行结案时整单不通过(无剩余履约内容)。
"""
from __future__ import annotations
from app import db
from app.models import (
ShippingNoticeLineInventoryMatch,
ShippingOrderReviewCase,
ShippingOrderReviewLineDecision,
)
from app.services.shipping_notice.fulfillment_workflow import (
_closed_snapshot_line_ids_for_task,
_recompute_task_match_aggregate,
match_completed,
)
from tests.test_effective_order_view import _seed_frozen_order
def _seed_match_facts(fixture):
"""第 0 行 matched+ready,第 1 行 not_found 短缺(历史阻塞点)。"""
for snap_line, result, shortage in (
(fixture.snap_lines[0], 'matched', '0'),
(fixture.snap_lines[1], 'not_found', '10'),
):
db.session.add(ShippingNoticeLineInventoryMatch(
task_id=fixture.order.id, snapshot_line_id=snap_line.id, line_no=snap_line.line_no,
line_index=snap_line.position, match_result=result, inventory_status='ready',
required_qty='10', available_qty='10' if result == 'matched' else '0',
shortage_qty=shortage, reservation_id=snap_line.reservation_id,
part_number=snap_line.part_number, is_current=True,
))
db.session.flush()
def _seed_close_decision(fixture, line_index, *, case_no='SNRC-CLOSE-1', version=1):
"""给已确认 Case 补一条活动结案决定(FK 不强制,挂哨兵父 id 即可)。"""
case = ShippingOrderReviewCase.query.filter_by(case_no=case_no).first()
if case is None:
case = ShippingOrderReviewCase(
case_no=case_no, run_id=901, unit_id=902, document_id=903,
owner_user_id=fixture.user.id, status='confirmed', confirmed_task_id=fixture.order.id,
)
db.session.add(case)
db.session.flush()
db.session.add(ShippingOrderReviewLineDecision(
review_case_id=case.id, draft_line_id=f'line-{line_index}', line_index=line_index,
decision_version=version, decision_code='close_unfulfillable', decision_source='user',
line_status='closed_unfulfillable', is_active=True, reason='该行不再发货',
actor_user_id=fixture.user.id, snapshot_json={},
))
db.session.flush()
def test_closed_line_ids_helper_mirrors_release_query(app):
"""结案行集合必须与放行同款:活动决定 + line_index 映射快照行。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_close_decision(fixture, 1)
# 断言:仅第 1 行(line_index=1)进入结案集合。
assert _closed_snapshot_line_ids_for_task(fixture.order) == {int(fixture.snap_lines[1].id)}
def test_aggregate_exempts_closed_shortage_line(app):
"""关闭短缺行后聚合应判满足:closed 行不阻断、不进缺货列表。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_match_facts(fixture)
_seed_close_decision(fixture, 1)
status, shortages = _recompute_task_match_aggregate(fixture.order)
payload = fixture.order.step_payload_json or {}
line_results = payload['current_match_projection']['line_results']
# 断言:整单满足、缺货列表为空、结案行状态为 closed 而非 shortage。
assert status == 'fulfillable'
assert shortages == []
assert line_results[1]['line_status'] == 'closed'
def test_match_completed_passes_with_closed_line(app):
"""整单满足性门禁对结案行豁免:一行 matched + 一行 closed 即通过。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_match_facts(fixture)
# 断言:结案前整单不通过(历史阻塞行为)。
assert match_completed(fixture.order) is False
_seed_close_decision(fixture, 1)
# 断言:结案后整单通过(本任务修复目标)。
assert match_completed(fixture.order) is True
def test_all_lines_closed_fails_match_completed(app):
"""全部行结案=无剩余履约内容:整单满足性不通过(此类单应走作废流程)。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_match_facts(fixture)
_seed_close_decision(fixture, 1, version=1)
_seed_close_decision(fixture, 0, version=1)
# 断言:无任何待履约行时 match_completed 返回 False,避免自动建空通知。
assert match_completed(fixture.order) is False
def test_all_lines_closed_aggregate_is_unfulfillable(app):
"""全结案聚合口径锁定:结案行不计满足 ⇒ 整单 unfulfillable(与 match_completed 一致)。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_match_facts(fixture)
_seed_close_decision(fixture, 1, version=1)
_seed_close_decision(fixture, 0, version=1)
status, shortages = _recompute_task_match_aggregate(fixture.order)
# 断言:无 ok 也无 block(无可履约内容)⇒ unfulfillable,且不产生缺货列表。
assert status == 'unfulfillable'
assert shortages == []
def test_closed_status_precedence_over_ok(app):
"""分类优先级锁定:matched+ready 行结案后记 closed(非 ok),且不再贡献整单满足。"""
with app.app_context():
fixture = _seed_frozen_order()
# 仅第 0 行有匹配事实(matched+ready)且已结案:聚合视角为单行订单。
snap_line = fixture.snap_lines[0]
db.session.add(ShippingNoticeLineInventoryMatch(
task_id=fixture.order.id, snapshot_line_id=snap_line.id, line_no=snap_line.line_no,
line_index=snap_line.position, match_result='matched', inventory_status='ready',
required_qty='10', available_qty='10', shortage_qty='0',
reservation_id=snap_line.reservation_id, part_number=snap_line.part_number,
is_current=True,
))
db.session.flush()
_seed_close_decision(fixture, 0)
status, shortages = _recompute_task_match_aggregate(fixture.order)
payload = fixture.order.step_payload_json or {}
line_results = payload['current_match_projection']['line_results']
# 断言:结案分类优先于匹配满足;无 ok 无 block ⇒ 整单 unfulfillable。
assert line_results[0]['line_status'] == 'closed'
assert status == 'unfulfillable'
assert shortages == []
@@ -0,0 +1,63 @@
"""
tests/test_line_closure_gate_sync.py
用途:验证结案决定落库后的 Gate 重算联动(对齐放行路径),含 trigger 透传。
依赖:pytest、order_review_fulfillment_decision_service、fulfillment_workflow、匹配事实夹具。
逻辑:结案使聚合转为满足后,_sync 必须重算任务履约态并以 line_fulfillment_closed 触发编排。
"""
from __future__ import annotations
from types import SimpleNamespace
from app import db
from app.models import ShippingProcessExecution
from app.services.shipping_notice.order_review_fulfillment_decision_service import (
_sync_confirmed_task_fulfillment_gates,
)
from tests.test_effective_order_view import _seed_frozen_order
from tests.test_line_closure_fulfillment import _seed_close_decision, _seed_match_facts
def test_close_decision_syncs_gates_with_closed_trigger(app, monkeypatch):
"""结案行豁免使整单满足后,Gate 同步须重算并以 line_fulfillment_closed 触发编排。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_match_facts(fixture)
_seed_close_decision(fixture, 1)
# 计划自审补齐:submit_auto_progress 仅在 OT 绑定活动 Execution 时触发,
# 冻结订单夹具默认不带执行实例,须按结案现场补一条 blocked 的最小执行。
execution = ShippingProcessExecution(
execution_no='EXE-CLOSE-GATE-SYNC', task_id=int(fixture.order.id),
status='blocked', current_gate_code='inventory_sufficiency', lock_version=1,
)
db.session.add(execution)
db.session.flush()
fixture.order.active_process_execution_id = int(execution.id)
db.session.flush()
calls = []
def _capture_progress(*args, **kwargs):
calls.append(('submit_auto_progress', kwargs.get('trigger')))
def _capture_enqueue(*args, **kwargs):
calls.append(('enqueue_post_ot_auto_fulfill_job', kwargs.get('trigger')))
# 拦截编排出口:函数内为局部 import,直接 patch 源模块属性即可生效。
monkeypatch.setattr(
'app.services.shipping_notice.auto_progress_controller.submit_auto_progress',
_capture_progress,
)
monkeypatch.setattr(
'app.services.shipping_notice.line_auto_fulfill_coordinator.enqueue_post_ot_auto_fulfill_job',
_capture_enqueue,
)
fake_case = SimpleNamespace(confirmed_task_id=fixture.order.id)
_sync_confirmed_task_fulfillment_gates(
case=fake_case, actor_id=fixture.user.id, trigger='line_fulfillment_closed',
)
payload = fixture.order.step_payload_json or {}
# 断言:任务履约态被重算为满足,且两个编排出口都带结案 trigger。
assert payload['current_match_projection']['match_status'] == 'fulfillable'
assert ('submit_auto_progress', 'line_fulfillment_closed') in calls
assert ('enqueue_post_ot_auto_fulfill_job', 'line_fulfillment_closed') in calls
@@ -0,0 +1,100 @@
"""
tests/test_shipping_notice_creation_effective.py
用途:验证正式通知行物化携带冻结后修正值,且整单建通知排除已结案行。
依赖:pytest、shipping_notice_creation_service、notice_line_service、行级履约决定模型。
逻辑:库存门禁通过(或行豁免)后建 Notice,断言 NoticeLine 的料号/数量来自有效视图,
结案行既不进门禁目标集也不物化为通知行。
"""
from __future__ import annotations
import pytest
from app import db
from app.core.errors import ConflictError
from app.models import (
ShippingCustomer,
ShippingNoticeLine,
ShippingNoticeLineInventoryMatch,
)
from app.services.shipping_notice.shipping_notice_creation_service import (
create_shipping_notice_after_inventory_gate,
)
from app.services.shipping_notice.task_order_field_editor import replace_current_line_field_value
from tests.test_effective_order_view import _seed_frozen_order
from tests.test_line_closure_fulfillment import _seed_close_decision
def _seed_customer(snapshot):
"""给快照挂一个 active 客户(建 Notice 门禁必填)。"""
customer = ShippingCustomer(standard_name='有效视图客户', short_code='EFFC', status='active')
db.session.add(customer)
db.session.flush()
snapshot.customer_id = customer.id
db.session.flush()
def _seed_match_row(order, snap_line, *, match_result='matched', shortage='0'):
"""给冻结行补一条当前匹配事实(matched+ready 表示门禁可过)。"""
db.session.add(ShippingNoticeLineInventoryMatch(
task_id=order.id, snapshot_line_id=snap_line.id, line_no=snap_line.line_no,
line_index=snap_line.position, match_result=match_result, inventory_status='ready',
required_qty='10', available_qty='10', shortage_qty=shortage,
reservation_id=snap_line.reservation_id, part_number=snap_line.part_number,
is_current=True,
))
db.session.flush()
def test_notice_lines_carry_corrected_part_number(app):
"""修正后的料号必须进入正式通知行(通知行会被 Excel/货代消费)。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_customer(fixture.snapshot)
replace_current_line_field_value(
task=fixture.order, position=0, field_code='part_number', value='D4-A08AR12000002',
)
_seed_match_row(fixture.order, fixture.snap_lines[0])
# 注:brief 原文为整单调用,但夹具第二行无匹配事实会触发门禁 ConflictError(经控制器确认),
# 改为仅选中第 0 行——与 Step 2 预期断言差异(单行)一致。
notice = create_shipping_notice_after_inventory_gate(
fixture.order, snapshot_line_ids={int(fixture.snap_lines[0].id)},
)
rows = ShippingNoticeLine.query.filter_by(notice_id=notice.id).all()
# 断言:通知行料号是修正值,而不是快照冻结的带尾巴旧值。
assert [row.part_number for row in rows] == ['D4-A08AR12000002']
def test_notice_creation_skips_closed_line(app):
"""一行 matched + 一行结案:整单建通知成功且通知行不含结案行。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_customer(fixture.snapshot)
_seed_match_row(fixture.order, fixture.snap_lines[0])
_seed_match_row(
fixture.order, fixture.snap_lines[1], match_result='not_found', shortage='10',
)
_seed_close_decision(fixture, 1)
notice = create_shipping_notice_after_inventory_gate(fixture.order)
rows = ShippingNoticeLine.query.filter_by(notice_id=notice.id).all()
# 断言:只有第 0 行进入通知;结案行既过门禁又被物化排除。
assert [row.snapshot_line_id for row in rows] == [int(fixture.snap_lines[0].id)]
def test_whole_order_notice_rejected_when_all_lines_closed(app):
"""全部行结案=无可履约内容:整单建 Notice 必须按门禁未通过拒绝,防止建空通知。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_customer(fixture.snapshot)
_seed_match_row(fixture.order, fixture.snap_lines[0])
_seed_match_row(
fixture.order, fixture.snap_lines[1], match_result='not_found', shortage='10',
)
_seed_close_decision(fixture, 1, version=1)
_seed_close_decision(fixture, 0, version=1)
# 断言:结案剔除后目标行集为空,整单调用走门禁未通过分支(与 match_completed 口径一致)。
with pytest.raises(ConflictError) as exc_info:
create_shipping_notice_after_inventory_gate(fixture.order)
assert exc_info.value.code == 'SHIPPING.INVENTORY_GATE_NOT_PASSED'
assert 'SHIPPING.INVENTORY_GATE_NOT_PASSED' in repr(exc_info.value)
@@ -1,9 +1,9 @@
"""
tests/test_shipping_order_field_purposes.py
用途:验证履约门禁只从冻结订单快照及其冻结策略读取预约单号。
依赖:订单 Schema service、冻结快照模型、reservation_gate。
逻辑:当前任务不得读取可变 FieldValue 或旧任务行投影;策略缺少能力时必须明确阻断。
用途:验证履约门禁按有效视图(冻结快照 + 冻结后人工修正)读取预约单号。
依赖:订单 Schema service、冻结快照模型、reservation_gate(内部经 effective_order_view 叠加修正)。
逻辑:冻结后人工修正的预约单必须进入门禁判定(修正值生效);策略缺少能力时仍明确阻断。
"""
from __future__ import annotations
@@ -87,15 +87,29 @@ def _task_with_reservation(value: str, *, include_reservation_capability: bool =
return task
def test_task_reservation_gate_uses_frozen_value_not_mutable_projection_or_field_value(app):
"""门禁以冻结预约单为准,后续 FieldValue 变化均不得重解释履约。"""
def test_task_reservation_gate_reads_effective_amendment_over_frozen_value(app):
"""有效视图契约:冻结后人工修正的预约单必须进入门禁判定(修正值生效)。"""
with app.app_context():
task = _task_with_reservation('3000000001')
# 模拟编辑窗的人工修正:当前 accepted Extraction 的 FieldValue 即修正事实,
# 经 effective_order_view 对位叠加后必须被门禁消费(区别于旧冻结-only 契约)。
value = ShippingOrderFieldValue.query.filter_by(extraction_id=task.current_order_extraction_id).one()
value.value_text = '3000000002'
value.value_json = '3000000002'
db.session.commit()
assert task_reservation_gate_issues(task) == []
def test_task_reservation_gate_rejects_invalid_effective_amendment(app):
"""有效视图契约:非法修正值同样进入门禁判定并被拦截(不再静默回退冻结值)。"""
with app.app_context():
task = _task_with_reservation('3000000001')
value = ShippingOrderFieldValue.query.filter_by(extraction_id=task.current_order_extraction_id).one()
value.value_text = 'INVALID'
value.value_json = 'INVALID'
db.session.commit()
assert task_reservation_gate_issues(task) == []
issues = task_reservation_gate_issues(task)
assert issues != []
def test_task_reservation_gate_blocks_snapshot_without_reservation_capability(app):