feat(shipping-notice): 落地 XFA 统一视觉拆分确认门禁与处理投影收敛
闭合拆分预览令牌单次消费、样本 checksum 绑定与确认审计;正式提取改为 bindings-only。 同步统一标注工作台交互,并补齐进度投影/任务中心与迁移文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d2b3d74def
commit
84a881b554
195 files changed
+20269
-3463
No files matched your search
@@ -1,18 +1,20 @@
|
||||
"""
|
||||
backend/tests/test_shipping_schema_edit_policy.py
|
||||
|
||||
用途:验收正式任务 Schema 编辑策略默认只读与显式放行。
|
||||
用途:验收正式任务 Schema 编辑策略默认只读与显式放行(无 legacy 绕过)。
|
||||
依赖:schema_edit_policy、pytest。
|
||||
逻辑:无 task_edit_policy → 不可编辑;显式 editable=True → 可编辑;
|
||||
excel_ready 截止后关闭。
|
||||
excel_ready 后全局关闭。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.services.shipping_notice.schema_edit_policy import (
|
||||
DEFAULT_EDITABLE_AFTER_TASK_CREATION,
|
||||
is_excel_ready_for_task,
|
||||
is_field_editable_for_formal_task,
|
||||
list_editable_formal_field_ids,
|
||||
sanitize_audit_field_value,
|
||||
)
|
||||
|
||||
|
||||
@@ -26,7 +28,7 @@ def test_default_formal_fields_are_readonly() -> None:
|
||||
|
||||
|
||||
def test_schema_explicit_editable_is_honored_until_excel_ready() -> None:
|
||||
"""Schema 显式放行字段在 Excel 就绪前可编辑。"""
|
||||
"""Schema 显式放行字段在 Excel 就绪前可编辑;就绪后全局关闭。"""
|
||||
field = {
|
||||
'field_id': 'reservation-id',
|
||||
'task_edit_policy': {
|
||||
@@ -38,3 +40,84 @@ def test_schema_explicit_editable_is_honored_until_excel_ready() -> None:
|
||||
assert is_field_editable_for_formal_task(field, excel_ready=False) is True
|
||||
assert is_field_editable_for_formal_task(field, excel_ready=True) is False
|
||||
assert list_editable_formal_field_ids([field], excel_ready=False) == ['reservation-id']
|
||||
assert list_editable_formal_field_ids([field], excel_ready=True) == []
|
||||
|
||||
|
||||
def test_excel_ready_freezes_even_without_editable_until() -> None:
|
||||
"""Excel ready 时即使未声明 editable_until 也全局禁写。"""
|
||||
field = {
|
||||
'field_id': 'po-id',
|
||||
'task_edit_policy': {'editable': True, 'change_effect': 'none'},
|
||||
}
|
||||
assert is_field_editable_for_formal_task(field, excel_ready=False) is True
|
||||
assert is_field_editable_for_formal_task(field, excel_ready=True) is False
|
||||
|
||||
|
||||
def test_sanitize_audit_field_value_truncates_long_text() -> None:
|
||||
"""审计前后值过长时截断。"""
|
||||
long_text = 'x' * 400
|
||||
sanitized = sanitize_audit_field_value(long_text)
|
||||
assert isinstance(sanitized, str)
|
||||
assert len(sanitized) < 400
|
||||
assert sanitized.endswith('…')
|
||||
|
||||
|
||||
def test_excel_ready_requires_ready_artifact(app) -> None:
|
||||
"""仅有 export_file_path、无 ready Artifact 时不得冻结(BE-09)。"""
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingExcelTemplate,
|
||||
ShippingExportArtifact,
|
||||
ShippingInventoryParsingProfile,
|
||||
ShippingOrderExtraction,
|
||||
ShippingOrderSchema,
|
||||
ShippingOrderSchemaVersion,
|
||||
ShippingNotice,
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
task = ShippingNotice(
|
||||
task_no='SN-EXCEL-READY-BE09',
|
||||
source_type='manual',
|
||||
process_status='matched',
|
||||
export_file_path='/tmp/be09.xlsx',
|
||||
export_file_name='be09.xlsx',
|
||||
order_data_version=1,
|
||||
order_lines_migration_status='pending',
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
assert is_excel_ready_for_task(task) is False
|
||||
|
||||
template = ShippingExcelTemplate(
|
||||
template_code='BE09', display_name='BE09', version=1, status='published',
|
||||
storage_bucket='test', storage_key='t.xlsx', original_filename='t.xlsx',
|
||||
file_checksum='a' * 64, definition_json={},
|
||||
)
|
||||
profile = ShippingInventoryParsingProfile(
|
||||
profile_code='BE09', display_name='BE09', version=1, status='published',
|
||||
file_format='xlsx', definition_json={},
|
||||
)
|
||||
schema = ShippingOrderSchema(schema_code='BE09', display_name='BE09')
|
||||
db.session.add_all([template, profile, schema])
|
||||
db.session.flush()
|
||||
version = ShippingOrderSchemaVersion(
|
||||
schema_id=schema.id, version=1, status='published', definition_json={},
|
||||
)
|
||||
db.session.add(version)
|
||||
db.session.flush()
|
||||
extraction = ShippingOrderExtraction(
|
||||
task_id=task.id, schema_version_id=version.id,
|
||||
input_snapshot_hash='b' * 64, status='accepted',
|
||||
)
|
||||
db.session.add(extraction)
|
||||
db.session.flush()
|
||||
db.session.add(ShippingExportArtifact(
|
||||
artifact_no='ART-BE09', task_id=task.id, template_id=template.id,
|
||||
order_schema_version_id=version.id, order_extraction_id=extraction.id,
|
||||
inventory_parsing_profile_id=profile.id, input_checksum='c' * 64,
|
||||
file_path='/tmp/be09.xlsx', file_name='be09.xlsx',
|
||||
file_checksum='d' * 64, file_size=1, status='ready',
|
||||
))
|
||||
db.session.commit()
|
||||
assert is_excel_ready_for_task(task) is True
|
||||
Reference in new issue
Block a user