feat(rohs-check): 增强 RoHS 检核工具进度展示,新增判定统计与当前步骤信息
This commit is contained in:
1 parent
b82f31af8f
commit
ee39270069
9 files changed
+349
-11
No files matched your search
@@ -108,6 +108,105 @@ def test_rohs_service_normalizes_invalid_result():
|
||||
assert payload['workflow_run_id'] == 'wf-1'
|
||||
|
||||
|
||||
def test_rohs_loop_splits_processing_and_judgement_counts(app, monkeypatch):
|
||||
from app.services.schedule.srm_service import _run_check_job_loop
|
||||
|
||||
class _Agent:
|
||||
id = 1
|
||||
dify_api_key = 'secret'
|
||||
|
||||
def _evaluate(**kwargs):
|
||||
return {
|
||||
'dify_result': '人工判定',
|
||||
'dify_message': 'Dify执行失败:workflow timeout',
|
||||
'workflow_run_id': 'wf-failed',
|
||||
'error': 'workflow timeout',
|
||||
}
|
||||
|
||||
writebacks = []
|
||||
|
||||
monkeypatch.setattr('app.services.schedule.srm_service.RoHSCheckService.evaluate', _evaluate)
|
||||
with app.app_context():
|
||||
admin = _mk_admin()
|
||||
db.session.flush()
|
||||
task = _mk_check_task(admin.id)
|
||||
run = ScheduleRun(run_no='RUN-JUDGEMENT-SPLIT', schedule_task_id=task.id, status='running', trigger_type='manual')
|
||||
db.session.add(run)
|
||||
db.session.commit()
|
||||
run_id = run.id
|
||||
|
||||
total, success, failed, skipped, details, errors, step_logs = _run_check_job_loop(
|
||||
conn_str='',
|
||||
run_no='RUN-1',
|
||||
agent=_Agent(),
|
||||
user='tester',
|
||||
wait_seconds=5,
|
||||
run_id=run_id,
|
||||
fetch_fn=lambda _conn: [{'id': 'R1'}],
|
||||
build_record_fn=lambda _conn, item, row_id: ('record text', None),
|
||||
writeback_fn=lambda _conn, **kwargs: writebacks.append(kwargs),
|
||||
row_id_key='id',
|
||||
log_prefix='row',
|
||||
)
|
||||
db.session.refresh(run)
|
||||
judgement = (run.response_summary_json or {}).get('rohs_judgement') or {}
|
||||
|
||||
assert total == 1
|
||||
assert success == 1
|
||||
assert failed == 0
|
||||
assert skipped == 0
|
||||
assert writebacks
|
||||
assert details[0]['writeback_srm'] is True
|
||||
assert errors == []
|
||||
assert judgement['manual_count'] == 1
|
||||
assert judgement['dify_error_count'] == 1
|
||||
assert (run.response_summary_json or {}).get('current_step', {}).get('step') == 'completed'
|
||||
assert any(log['step'] == 'call_dify' and log['status'] == 'success' for log in step_logs)
|
||||
|
||||
|
||||
def test_srm_sql_operations_apply_configured_timeout(app, monkeypatch):
|
||||
from app.services.schedule import srm_service
|
||||
|
||||
observed = {'connect_timeout': None, 'cursor_timeout': None}
|
||||
|
||||
class _Cursor:
|
||||
description = [('id',)]
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name == 'timeout':
|
||||
observed['cursor_timeout'] = value
|
||||
object.__setattr__(self, name, value)
|
||||
|
||||
def execute(self, *_args):
|
||||
return None
|
||||
|
||||
def fetchall(self):
|
||||
return [(1,)]
|
||||
|
||||
class _Conn:
|
||||
def cursor(self):
|
||||
return _Cursor()
|
||||
|
||||
def commit(self):
|
||||
return None
|
||||
|
||||
def close(self):
|
||||
return None
|
||||
|
||||
class _Pyodbc:
|
||||
@staticmethod
|
||||
def connect(_conn_str, timeout):
|
||||
observed['connect_timeout'] = timeout
|
||||
return _Conn()
|
||||
|
||||
monkeypatch.setattr(srm_service, 'pyodbc', _Pyodbc)
|
||||
with app.app_context():
|
||||
app.config['SRM_SQLSERVER_TIMEOUT'] = 7
|
||||
srm_service._execute_writeback('conn', 'update table set col=?', ('x',))
|
||||
|
||||
assert observed == {'connect_timeout': 7, 'cursor_timeout': 7}
|
||||
|
||||
|
||||
def test_rohs_tool_requires_auth(app, client):
|
||||
with app.app_context():
|
||||
app.config['INTEGRATION_API_KEY'] = 'secret'
|
||||
@@ -274,6 +373,18 @@ def test_workspace_rohs_active_run_returns_progress(app, client):
|
||||
success_count=3,
|
||||
failed_count=1,
|
||||
skipped_count=1,
|
||||
response_summary_json={
|
||||
'current_step': {
|
||||
'step': 'writeback_srm',
|
||||
'label': '写回 SRM',
|
||||
'row_id': 'ROW-16',
|
||||
'started_at': '2026-06-11T10:00:00',
|
||||
'processed_count': 4,
|
||||
'success_count': 3,
|
||||
'failed_count': 1,
|
||||
'skipped_count': 0,
|
||||
},
|
||||
},
|
||||
)
|
||||
db.session.add(run)
|
||||
db.session.commit()
|
||||
@@ -285,6 +396,34 @@ def test_workspace_rohs_active_run_returns_progress(app, client):
|
||||
assert data['run']['run_no'] == 'RUN-ROHS-ACTIVE'
|
||||
assert data['run']['processed_count'] == 5
|
||||
assert data['run']['progress_percent'] == 50
|
||||
assert data['run']['current_step']['step'] == 'writeback_srm'
|
||||
assert data['run']['current_step']['row_id'] == 'ROW-16'
|
||||
|
||||
|
||||
def test_workspace_rohs_active_run_filters_by_conversation_id(app, client):
|
||||
with app.app_context():
|
||||
admin = _mk_admin()
|
||||
db.session.commit()
|
||||
task = _mk_check_task(admin.id)
|
||||
run = ScheduleRun(
|
||||
run_no='RUN-ROHS-ACTIVE-CONV',
|
||||
schedule_task_id=task.id,
|
||||
status='running',
|
||||
trigger_type='dify_chatflow',
|
||||
total_count=10,
|
||||
success_count=2,
|
||||
api_request_json={'conversation_id': 'conv-a'},
|
||||
)
|
||||
db.session.add(run)
|
||||
db.session.commit()
|
||||
|
||||
miss = client.get('/api/workspace/rohs-check/runs/active?conversation_id=conv-b', headers={'X-Username': 'admin'})
|
||||
assert miss.status_code == 200
|
||||
assert miss.get_json()['run'] is None
|
||||
|
||||
hit = client.get('/api/workspace/rohs-check/runs/active?conversation_id=conv-a', headers={'X-Username': 'admin'})
|
||||
assert hit.status_code == 200
|
||||
assert hit.get_json()['run']['run_no'] == 'RUN-ROHS-ACTIVE-CONV'
|
||||
|
||||
|
||||
def test_workspace_rohs_active_run_returns_null_when_idle(app, client):
|
||||
|
||||
Reference in new issue
Block a user