fix(shipping-notice): 跨模板发布检查排除同模板族旧版
新草稿发布时旧 published 会被 retire,不必与自身 v1/v2 比唯一性,避免误报冲突。
This commit is contained in:
1 parent
3040e3123d
commit
9d82eafcc9
4 files changed
+83
-15
No files matched your search
@@ -7,8 +7,13 @@ tests/test_order_document_profile_overlap_summary.py
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from app.services.shipping_notice.order_document_profile_validation_service import build_cross_template_overlap_summary
|
||||
from app.services.shipping_notice.order_document_profile_validation_service import _evaluate_self_sample_match
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.services.shipping_notice.order_document_profile_validation_service import (
|
||||
build_cross_template_overlap_summary,
|
||||
published_rival_snapshots_for_overlap,
|
||||
_evaluate_self_sample_match,
|
||||
)
|
||||
from app.services.shipping_notice.document_layout.order_profile_matcher import (
|
||||
ProfileMatchCandidate,
|
||||
ProfileMatchResult,
|
||||
@@ -75,3 +80,24 @@ def test_overlap_ignores_ineligible_candidate_when_unique_match_has_no_eligible_
|
||||
assert outcome['self_unique'] is True
|
||||
assert outcome['margin'] == 1.0
|
||||
assert outcome['margin_ok'] is True
|
||||
|
||||
|
||||
def test_published_rival_snapshots_exclude_same_profile_code(monkeypatch):
|
||||
"""同模板族旧 published 版不得进入跨模板冲突候选池。"""
|
||||
from app.services.shipping_notice import order_document_profile_service as profile_service
|
||||
|
||||
monkeypatch.setattr(
|
||||
profile_service,
|
||||
'published_snapshots_for_schema',
|
||||
lambda _schema_id: [
|
||||
{'profile_code': 'ODP-SELF', 'version': 1},
|
||||
{'profile_code': 'ODP-SELF', 'version': 2},
|
||||
{'profile_code': 'ODP-OTHER', 'version': 1},
|
||||
],
|
||||
)
|
||||
profile = SimpleNamespace(profile_code='ODP-SELF', schema_version_id=1, version=3)
|
||||
|
||||
rivals = published_rival_snapshots_for_overlap(profile)
|
||||
|
||||
assert [item['profile_code'] for item in rivals] == ['ODP-OTHER']
|
||||
assert all(item['profile_code'] != 'ODP-SELF' for item in rivals)
|
||||
@@ -85,7 +85,6 @@ def test_datasets_blind_cross_check_reports_shared_ocr_mismatch():
|
||||
|
||||
def test_datasets_overlap_reuses_common_visual_evidence_then_appends_identity_conflict(monkeypatch):
|
||||
"""关键断言:跨模板 overlap 先走共同 matcher,datasets 只能追加末端身份冲突。"""
|
||||
from app.services.shipping_notice import order_document_profile_service as profile_service
|
||||
from app.services.shipping_notice import order_document_profile_validation_service as validation_service
|
||||
from app.services.shipping_notice.order_profile_value_adapters import xfa_dataset
|
||||
|
||||
@@ -100,9 +99,9 @@ def test_datasets_overlap_reuses_common_visual_evidence_then_appends_identity_co
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
profile_service,
|
||||
'published_snapshots_for_schema',
|
||||
lambda _schema_id: [{
|
||||
validation_service,
|
||||
'published_rival_snapshots_for_overlap',
|
||||
lambda _profile: [{
|
||||
'profile_code': 'XFA-OTHER', 'version': 3, 'checksum': 'other',
|
||||
'definition': {'source_contract': {
|
||||
'template_packet_checksum': 'template',
|
||||
@@ -135,6 +134,41 @@ def test_datasets_overlap_reuses_common_visual_evidence_then_appends_identity_co
|
||||
assert snapshot['conflict_profiles'][1]['reason_codes'] == ['value_source_exact_identity_conflict']
|
||||
|
||||
|
||||
def test_datasets_overlap_skips_same_profile_code_identity_rival(monkeypatch):
|
||||
"""datasets 身份冲突也不得拿同模板族旧版跟自己比。"""
|
||||
from app.services.shipping_notice import order_document_profile_validation_service as validation_service
|
||||
from app.services.shipping_notice.order_profile_value_adapters import xfa_dataset
|
||||
|
||||
monkeypatch.setattr(
|
||||
validation_service,
|
||||
'_build_coordinate_overlap_evidence',
|
||||
lambda **_kwargs: ('passed', {'false_hit_other_count': 0}, {'conflict_profiles': []}),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
validation_service,
|
||||
'published_rival_snapshots_for_overlap',
|
||||
lambda _profile: [],
|
||||
)
|
||||
profile = SimpleNamespace(
|
||||
profile_code='XFA-CURRENT', version=2, schema_version_id=9,
|
||||
definition_json={'source_contract': {
|
||||
'template_packet_checksum': 'template',
|
||||
'dataset_structure_fingerprint': 'structure',
|
||||
}},
|
||||
)
|
||||
|
||||
status, summary, snapshot = xfa_dataset.build_overlap_evidence(
|
||||
profile=profile,
|
||||
signature_run=SimpleNamespace(id=1),
|
||||
training_samples=[],
|
||||
blind_samples=[],
|
||||
)
|
||||
|
||||
assert status == 'passed'
|
||||
assert summary['value_source_identity_conflict_count'] == 0
|
||||
assert snapshot['conflict_profiles'] == []
|
||||
|
||||
|
||||
def test_datasets_overlap_parse_result_uses_formal_datasets_extraction(monkeypatch):
|
||||
"""XFA overlap 解析门禁必须消费 datasets 抽取结果,不能误用坐标字段覆盖。"""
|
||||
from app.services.shipping_notice.order_profile_value_adapters import xfa_dataset
|
||||
|
||||
Reference in new issue
Block a user