feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -11,6 +11,7 @@ from __future__ import annotations
|
||||
from app import db
|
||||
from app.core.auth.jwt import issue_local_access_token
|
||||
from app.models import ShippingOrderCandidate, ShippingOrderProcessingRun
|
||||
from sqlalchemy import event
|
||||
from app.services.shipping_notice.order_extraction_run_service import create_order_extraction_run
|
||||
from app.services.shipping_notice.order_task_service import (
|
||||
allocate_user_task_no_for_run,
|
||||
@@ -99,6 +100,10 @@ def test_workspace_shipping_processing_and_focus_viewed_api(app, client):
|
||||
)
|
||||
assert focus.status_code == 200, focus.get_json()
|
||||
assert focus.get_json()['data']['focused_task_no'] == user_task_no
|
||||
assert 'work_items' not in focus.get_json()['data']
|
||||
assert set(focus.get_json()['data']['processing']['status_groups']) == {
|
||||
'failed', 'waiting_human', 'processing', 'completed', 'cancelled', 'archived',
|
||||
}
|
||||
|
||||
viewed = client.post(
|
||||
f'/api/workspace/shipping-notice/conversation-tasks/{user_task_no}/viewed',
|
||||
@@ -106,3 +111,122 @@ def test_workspace_shipping_processing_and_focus_viewed_api(app, client):
|
||||
headers=headers,
|
||||
)
|
||||
assert viewed.status_code == 200, viewed.get_json()
|
||||
assert 'work_items' not in viewed.get_json()['data']
|
||||
|
||||
|
||||
def test_workspace_shipping_processing_summary_omits_detail_and_legacy_mirrors(app, client):
|
||||
"""首屏会话摘要只返回状态→EML→PDF权威分组,详情必须按需读取。"""
|
||||
with app.app_context():
|
||||
user, agent, session, intake, _document = _seed_run_input(suffix='API-SUMMARY')
|
||||
run, _ = create_order_extraction_run(
|
||||
user=user,
|
||||
agent_id=agent.id,
|
||||
conversation_id=session.session_id,
|
||||
intake_nos=[intake.intake_no],
|
||||
keep_input_open=True,
|
||||
)
|
||||
db.session.commit()
|
||||
token = issue_local_access_token(user)
|
||||
session_id = session.session_id
|
||||
assert run.id is not None
|
||||
|
||||
response = client.get(
|
||||
f'/api/workspace/shipping-processing/conversations/{session_id}?view=summary',
|
||||
headers={'Authorization': f'Bearer {token}'},
|
||||
)
|
||||
|
||||
assert response.status_code == 200, response.get_json()
|
||||
data = response.get_json()['data']
|
||||
assert data['conversation_id'] == session_id
|
||||
assert data['projection_mode'] == 'summary'
|
||||
assert 'work_items' not in data
|
||||
projection = data['conversation_processing']
|
||||
assert set(projection['status_groups']) == {
|
||||
'failed', 'waiting_human', 'processing', 'completed', 'cancelled', 'archived',
|
||||
}
|
||||
assert 'needs_action' not in projection
|
||||
assert 'history' not in projection
|
||||
for tasks in projection['status_groups'].values():
|
||||
for task in tasks:
|
||||
assert 'process_gate' not in task
|
||||
assert 'objects' not in task
|
||||
# PDF 叶子是首屏“状态→EML→PDF”树的一部分;但叶子同样不携带详情 Gate。
|
||||
for child in task.get('aggregate_children') or []:
|
||||
assert 'process_gate' not in child
|
||||
|
||||
|
||||
def test_workspace_shipping_processing_summary_does_not_read_run_snapshots(app, client):
|
||||
"""首屏摘要不得查询 processing run,避免 JSON 快照解码重新进入轮询路径。"""
|
||||
with app.app_context():
|
||||
user, _agent, session, _intake, _document = _seed_run_input(suffix='API-SUMMARY-FAST')
|
||||
token = issue_local_access_token(user)
|
||||
session_id = session.session_id
|
||||
run_selects: list[str] = []
|
||||
|
||||
def capture_run_selects(_conn, _cursor, statement, _parameters, _context, _executemany):
|
||||
if 'shipping_order_processing_runs' in statement.lower():
|
||||
run_selects.append(statement)
|
||||
|
||||
event.listen(db.engine, 'before_cursor_execute', capture_run_selects)
|
||||
try:
|
||||
response = client.get(
|
||||
f'/api/workspace/shipping-processing/conversations/{session_id}?view=summary',
|
||||
headers={'Authorization': f'Bearer {token}'},
|
||||
)
|
||||
finally:
|
||||
event.remove(db.engine, 'before_cursor_execute', capture_run_selects)
|
||||
|
||||
assert response.status_code == 200, response.get_json()
|
||||
assert run_selects == []
|
||||
|
||||
|
||||
def test_workspace_shipping_processing_summary_keeps_lightweight_action_entries(app, client):
|
||||
"""摘要不加载重型详情,但必须保留后端裁决的最小操作入口。"""
|
||||
with app.app_context():
|
||||
user, agent, session, intake, document = _seed_run_input(suffix='API-SUMMARY-ACTIONS')
|
||||
run, _ = create_order_extraction_run(
|
||||
user=user,
|
||||
agent_id=agent.id,
|
||||
conversation_id=session.session_id,
|
||||
intake_nos=[intake.intake_no],
|
||||
keep_input_open=True,
|
||||
)
|
||||
run_no = run.run_no
|
||||
db.session.commit()
|
||||
token = issue_local_access_token(user)
|
||||
session_id = session.session_id
|
||||
document.parse_status = 'parsed'
|
||||
document.order_extraction_status = 'review_required'
|
||||
candidate = ShippingOrderCandidate(
|
||||
candidate_no=f'SNC-API-SUMMARY-ACTIONS-{run.id}',
|
||||
intake_id=intake.id,
|
||||
primary_document_id=document.id,
|
||||
candidate_key=f'key-api-summary-actions-{run.id}',
|
||||
order_extraction_run_id=run.id,
|
||||
is_current_version=True,
|
||||
candidate_status='provisional',
|
||||
structured_result_json={},
|
||||
)
|
||||
db.session.add(candidate)
|
||||
db.session.flush()
|
||||
db.session.commit()
|
||||
|
||||
response = client.get(
|
||||
f'/api/workspace/shipping-processing/conversations/{session_id}?view=summary',
|
||||
headers={'Authorization': f'Bearer {token}'},
|
||||
)
|
||||
|
||||
assert response.status_code == 200, response.get_json()
|
||||
projection = response.get_json()['data']['conversation_processing']
|
||||
assert [node['code'] for node in projection['lifecycle_nodes']] == [
|
||||
'intake_parse', 'order_review', 'fulfillment_prep', 'freight_upload', 'upload_complete',
|
||||
]
|
||||
tasks = projection['status_groups']['waiting_human']
|
||||
assert len(tasks) == 1
|
||||
leaf = tasks[0]['aggregate_children'][0]
|
||||
assert leaf['run_no'] == run_no
|
||||
assert leaf['source_summary']['po_number'] is None
|
||||
assert leaf['ui_state']['lifecycle_stage'] == 'intake_parse'
|
||||
assert leaf['ui_state']['primary_action']['code'] == 'open_order_review'
|
||||
assert leaf['ui_state']['primary_action']['target_surface'] == 'order_lifecycle_workbench'
|
||||
assert leaf['ui_state']['primary_action']['target_lifecycle_stage'] == 'intake_parse'
|
||||
Reference in new issue
Block a user