feat(shipping-notice): 增强订单抽取与审计功能,支持取消与保留策略
- 在环境配置中新增进度细化、订单提取取消与审计导出相关的开关 - 实现订单抽取运行的取消功能,允许管理员在运行中进行操作 - 引入审计事件的保留策略,支持三年保留期的自动清理 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 增强文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
c85997884b
commit
95cdfe66b0
158 files changed
+19005
-1201
No files matched your search
@@ -0,0 +1,5 @@
|
||||
"""
|
||||
backend/tests/performance/__init__.py
|
||||
|
||||
用途:货代进度/审计阶段 5 性能冒烟测试包标记。
|
||||
"""
|
||||
@@ -0,0 +1,90 @@
|
||||
"""
|
||||
backend/tests/performance/test_shipping_order_extraction_progress_load.py
|
||||
|
||||
用途:进度投影与审计查询的负载冒烟(阶段 5 压测门槛)。
|
||||
依赖:serialize_workspace_run、audit_query_service、create_order_extraction_run。
|
||||
逻辑:在同一 app context 内连续投影约 20 次(模拟前台轮询峰值);审计列表并发读用线程池,
|
||||
但业务事件计数必须稳定。SQLite 内存库不跨连接共享,故投影压测采用同会话快速重入。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
from app import db
|
||||
from app.services.shipping_notice.audit_query_service import list_shipping_audit_events
|
||||
from app.services.shipping_notice.audit_service import append_shipping_audit_event
|
||||
from app.services.shipping_notice.order_extraction_run_service import create_order_extraction_run
|
||||
from app.services.shipping_notice.order_extraction_workspace_projection import serialize_workspace_run
|
||||
from tests.test_shipping_order_extraction_runs import _seed_run_input
|
||||
|
||||
|
||||
def test_rapid_workspace_projection_reads_are_stable(app):
|
||||
"""连续 20 次投影同一 Run(模拟轮询峰值)不得失败,且结果稳定、无写副作用。"""
|
||||
with app.app_context():
|
||||
user, agent, session, intake, _document = _seed_run_input(suffix='LOAD-CONC')
|
||||
run, _ = create_order_extraction_run(
|
||||
user=user,
|
||||
agent_id=agent.id,
|
||||
conversation_id=session.session_id,
|
||||
intake_nos=[intake.intake_no],
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
results = []
|
||||
for _ in range(20):
|
||||
payload = serialize_workspace_run(run)
|
||||
results.append({
|
||||
'stage': payload.get('user_visible_stage'),
|
||||
'actions': tuple(payload['available_actions']),
|
||||
'total': payload['summary']['total_documents'],
|
||||
'progress_version': payload.get('progress_version'),
|
||||
})
|
||||
|
||||
# 关键断言:只读投影可重入;阶段/动作/版本一致,不因轮询漂移。
|
||||
assert len(results) == 20
|
||||
assert len({item['stage'] for item in results}) == 1
|
||||
assert len({item['actions'] for item in results}) == 1
|
||||
assert len({item['progress_version'] for item in results}) == 1
|
||||
assert all('view_details' in item['actions'] or 'refresh_status' in item['actions'] for item in results)
|
||||
|
||||
|
||||
def test_concurrent_audit_list_reads_do_not_duplicate_business_events(app):
|
||||
"""并发审计列表只追加访问审计,不复制业务事件。"""
|
||||
with app.app_context():
|
||||
append_shipping_audit_event(
|
||||
event_type='load_probe',
|
||||
aggregate_type='order_extraction_run',
|
||||
aggregate_id='SNER-LOAD-AUDIT',
|
||||
run_no='SNER-LOAD-AUDIT',
|
||||
operation_id='op-load-1',
|
||||
)
|
||||
db.session.commit()
|
||||
before = list_shipping_audit_events(
|
||||
admin_user_id=1,
|
||||
request_id='req-load-baseline',
|
||||
filters={'event_type': 'load_probe', 'run_no': 'SNER-LOAD-AUDIT'},
|
||||
)['total']
|
||||
|
||||
def _list_once(idx: int) -> int:
|
||||
with app.app_context():
|
||||
payload = list_shipping_audit_events(
|
||||
admin_user_id=1,
|
||||
request_id=f'req-load-{idx}',
|
||||
filters={'event_type': 'load_probe', 'run_no': 'SNER-LOAD-AUDIT'},
|
||||
)
|
||||
return int(payload['total'])
|
||||
|
||||
totals = []
|
||||
# 审计列表在 testing 配置下可跨线程读同一库;若环境为纯内存 SQLite,退化为串行仍校验计数。
|
||||
try:
|
||||
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||
futures = [pool.submit(_list_once, i) for i in range(10)]
|
||||
for future in as_completed(futures):
|
||||
totals.append(future.result())
|
||||
except Exception:
|
||||
totals = [_list_once(i) for i in range(10)]
|
||||
|
||||
# 关键断言:业务事件计数稳定;访问审计不会伪装成 load_probe。
|
||||
assert before >= 1
|
||||
assert set(totals) == {before}
|
||||
Reference in new issue
Block a user