feat(shipping-notice): 添加订单文档 Profile 盲测集和样本管理功能,支持创建、执行和批准盲测,增强订单冻结和库存核验功能

This commit is contained in:
hugo committed 2026-07-23 00:15:34 +08:00
1 parent c35223d49d
commit abd8fc1e16
98 files changed
+4629 -528

No files matched your search

+11 -6
View File
@@ -1,5 +1,5 @@
"""
用途:验证发货 Excel 批次 ZIP 的权限、最新 Artifact、重名、校验和与 manifest 契约。
用途:验证发货 Excel 批次 ZIP 的权限、全部有效 Artifact、重名、校验和与 manifest 契约。
依赖:export_archive、ShippingBatch/Task/ExportArtifact、zipfile。
逻辑:构造同批次有效、缺失及损坏产物,断言 ZIP 仅包含可信文件并完整列出排除原因。
"""
@@ -59,7 +59,7 @@ def _artifact(task, path, dependencies, *, no: str, checksum: str | None = None)
def test_batch_archive_manifest_and_duplicate_names(app, tmp_path):
"""有效同名文件均进入 ZIP,缺失/损坏任务只进入 manifest 并带明确状态。"""
"""同一任务多轮有效 Excel 都进入 ZIP,缺失/损坏 Artifact 保留明确审计状态。"""
with app.app_context():
user = User(username='zip-owner', email='zip@example.com', role='user', status='approved')
batch = ShippingBatch(batch_no='SB-ZIP', user_id=None, file_count=4)
@@ -67,10 +67,12 @@ def test_batch_archive_manifest_and_duplicate_names(app, tmp_path):
tasks = [ShippingTask(task_no=f'TASK-{index}', user_id=user.id, batch_id=batch.id, batch_index=index, batch_total=4) for index in range(1, 5)]
db.session.add_all(tasks); db.session.flush()
first = tmp_path / 'first.xlsx'; first.write_bytes(b'first')
first_second_round = tmp_path / 'first-second-round.xlsx'; first_second_round.write_bytes(b'first-second-round')
second = tmp_path / 'second.xlsx'; second.write_bytes(b'second')
corrupt = tmp_path / 'corrupt.xlsx'; corrupt.write_bytes(b'changed')
dependencies = _seed_artifact_dependencies()
_artifact(tasks[0], first, dependencies, no='EXP-1')
_artifact(tasks[0], first_second_round, dependencies, no='EXP-1-SECOND')
_artifact(tasks[1], second, dependencies, no='EXP-2')
_artifact(tasks[2], tmp_path / 'missing.xlsx', dependencies, no='EXP-3')
_artifact(tasks[3], corrupt, dependencies, no='EXP-4', checksum='0' * 64)
@@ -81,11 +83,12 @@ def test_batch_archive_manifest_and_duplicate_names(app, tmp_path):
names = archive.namelist()
assert 'shipment.xlsx' in names
assert 'shipment_TASK-2.xlsx' in names # 同名按任务号消歧,避免覆盖。
assert 'shipment_TASK-1.xlsx' in names # 同一任务第二轮滚动 Artifact 不得遗漏。
archived_manifest = json.loads(archive.read('manifest.json'))
assert filename.startswith('shipping_exports_SB-ZIP_')
assert archived_manifest['included_count'] == 2
assert archived_manifest['included_count'] == 3
assert [entry['status'] for entry in manifest['entries']] == [
'included', 'included', 'missing_file', 'checksum_mismatch',
'included', 'included', 'included', 'missing_file', 'checksum_mismatch',
]
@@ -104,8 +107,8 @@ def test_archive_rejects_foreign_task_and_invalid_selection(app):
build_export_archive(user_id=owner.id, batch_no='SB', task_nos=[task.task_no])
def test_archive_excludes_artifact_after_task_export_is_invalidated(app, tmp_path):
"""任务纠错清空当前导出引用后,旧 ready Artifact 不得继续进入下载包。"""
def test_archive_excludes_superseded_artifact_after_task_export_is_invalidated(app, tmp_path):
"""任务纠错必须显式作废旧 Artifact;仅清空旧 Task 指针不能影响滚动履约历史。"""
with app.app_context():
user = User(username='archive-reset', email='archive-reset@example.com', role='user', status='approved')
batch = ShippingBatch(batch_no='SB-RESET', user_id=None, file_count=1)
@@ -114,6 +117,8 @@ def test_archive_excludes_artifact_after_task_export_is_invalidated(app, tmp_pat
db.session.add(task); db.session.flush()
path = tmp_path / 'old.xlsx'; path.write_bytes(b'old')
_artifact(task, path, _seed_artifact_dependencies(), no='EXP-OLD')
artifact = ShippingExportArtifact.query.filter_by(artifact_no='EXP-OLD').one()
artifact.status = 'superseded'
task.export_file_path = None
task.export_file_name = None
db.session.commit()