feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -0,0 +1,97 @@
|
||||
"""
|
||||
backend/tests/test_shipping_workflow_recovery.py
|
||||
|
||||
用途:验收订单抽取 Job 超时回收后 WorkflowItem 从 layout_parsing/extracting 迁出。
|
||||
依赖:app fixture、_seed_run_input、workflow_ledger、sync_workflow_items_after_extraction_job_recovery。
|
||||
逻辑:模拟 Job queued/failed 回收,断言 Item 分别进入 queued / failed,不依赖完整 recover_stale_jobs。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from app import db
|
||||
from app.services.shipping_notice.order_extraction_run_service import (
|
||||
create_order_extraction_run,
|
||||
ensure_workflow_items_for_run,
|
||||
sync_workflow_items_after_extraction_job_recovery,
|
||||
)
|
||||
from app.services.shipping_notice.workflow_ledger_service import (
|
||||
ensure_workflow_item_for_document,
|
||||
transition_item_status,
|
||||
)
|
||||
from tests.test_shipping_order_extraction_runs import _seed_run_input
|
||||
|
||||
|
||||
def test_sync_workflow_items_after_extraction_recovery_to_queued(app):
|
||||
"""Job 回收为 queued 时,layout_parsing/extracting Item 回到 queued。"""
|
||||
with app.app_context():
|
||||
user, agent, session, intake, document = _seed_run_input(suffix='WFR-Q')
|
||||
with patch(
|
||||
'app.services.shipping_notice.order_extraction_run_service.schedule_order_extraction_layouts',
|
||||
return_value=False,
|
||||
):
|
||||
run, _ = create_order_extraction_run(
|
||||
user=user,
|
||||
agent_id=agent.id,
|
||||
conversation_id=session.session_id,
|
||||
intake_nos=[intake.intake_no],
|
||||
)
|
||||
item = ensure_workflow_item_for_document(
|
||||
conversation_id=session.session_id,
|
||||
owner_user_id=int(user.id),
|
||||
document_id=int(document.id),
|
||||
run=run,
|
||||
)
|
||||
transition_item_status(
|
||||
item=item,
|
||||
lifecycle_status='extracting',
|
||||
actor_type='system',
|
||||
actor_id='test',
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
job = SimpleNamespace(status='queued', business_ref=run.run_no, id=1)
|
||||
updated = sync_workflow_items_after_extraction_job_recovery(run=run, job=job)
|
||||
db.session.commit()
|
||||
|
||||
# 关键断言:卡住的抽取态被回收为可重试 queued。
|
||||
assert updated == 1
|
||||
db.session.refresh(item)
|
||||
assert item.lifecycle_status == 'queued'
|
||||
|
||||
|
||||
def test_sync_workflow_items_after_extraction_recovery_to_failed(app):
|
||||
"""Job 回收为 failed 时,layout_parsing Item 进入 failed。"""
|
||||
with app.app_context():
|
||||
user, agent, session, intake, document = _seed_run_input(suffix='WFR-F')
|
||||
with patch(
|
||||
'app.services.shipping_notice.order_extraction_run_service.schedule_order_extraction_layouts',
|
||||
return_value=True,
|
||||
):
|
||||
run, _ = create_order_extraction_run(
|
||||
user=user,
|
||||
agent_id=agent.id,
|
||||
conversation_id=session.session_id,
|
||||
intake_nos=[intake.intake_no],
|
||||
)
|
||||
items = ensure_workflow_items_for_run(run, stage_when_ready='queued')
|
||||
assert items
|
||||
item = items[0]
|
||||
transition_item_status(
|
||||
item=item,
|
||||
lifecycle_status='layout_parsing',
|
||||
actor_type='system',
|
||||
actor_id='test',
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
job = SimpleNamespace(status='failed', business_ref=run.run_no, id=2)
|
||||
updated = sync_workflow_items_after_extraction_job_recovery(run=run, job=job)
|
||||
db.session.commit()
|
||||
|
||||
# 关键断言:终态失败回收把 Item 标 failed。
|
||||
assert updated == 1
|
||||
db.session.refresh(item)
|
||||
assert item.lifecycle_status == 'failed'
|
||||
Reference in new issue
Block a user