am-freescan/scripts/verify_scanner_history_readonly.py
lixiaolong 6f8a40644c feat(scanner): 完善补扫、执行监控及资源释放
完善扫描流式预览、成果归档与PLY/STL查看、补扫历史、执行步骤及日志展示,支持局域网访问和改名节点的原始组件识别。修复试运行终止后的占用释放及未采集时重复暂停SDK的问题,增加终止中交互与回归验证。

验证:后端1114项通过、18项既有跳过;前端109项通过,类型检查及构建通过;Python脚本54项通过;模拟扫描设备7组试运行/终止接口回归通过。
2026-10-26 11:04:07 +08:00

47 lines
2.9 KiB
Python

"""Audit existing execution history and result ownership without scanner control or business writes."""
import argparse
import json
from verify_cmvr_native import Client, require
def audit(client, task_id):
detail = client.request('GET', '/admin-api/lab/scan-task/get', query={'taskId': task_id})['data']
checked = []
for unit in detail['units']:
attempts = {str(row['id']): row for row in unit.get('attempts', [])}
if unit.get('currentExecutionId'):
require(str(unit['currentExecutionId']) in attempts, 'Current execution is missing from history')
owned = {}
for execution_id, attempt in attempts.items():
require(str(attempt['sampleUnitId']) == str(unit['id']), 'Execution belongs to another sample')
require(str(attempt['taskId']) == str(task_id), 'Execution belongs to another task')
if attempt.get('executionType') == 'SUPPLEMENT':
require(str(attempt.get('parentExecutionId')) in attempts, 'Supplement source is missing')
files = client.request('GET', '/admin-api/lab/execution/scanner-view/assets',
query={'executionId': execution_id})['data']
ids = [file['fileId'] for file in files]
require(len(ids) == len(set(ids)), 'Duplicate result IDs')
require(all('binding' not in file and 'sha256' not in file for file in files), 'Private metadata leaked')
owned[execution_id] = set(ids)
checked.append({'executionId': execution_id, 'executionNo': attempt['executionNo'],
'type': attempt.get('executionType'), 'status': attempt['status'],
'files': [{'fileId': f['fileId'], 'name': f['name'], 'bytes': f['bytes'],
'archived': f.get('archived', False)} for f in files]})
# A real file from another attempt must never be served under this execution ID.
for execution_id, ids in owned.items():
foreign = next((file for other, values in owned.items() if other != execution_id
for file in values if file not in ids), None)
if foreign:
result = client.request('GET', '/admin-api/lab/execution/scanner-view/asset/' + foreign,
query={'executionId': execution_id}, expected=None)
require(result.get('code') not in (0, 200), 'Another execution can read this result')
return {'taskId': str(task_id), 'taskNo': detail['task']['taskNo'], 'attempts': checked}
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--task-id', action='append', required=True)
args = parser.parse_args()
client = Client().login()
print(json.dumps({'passed': True, 'checks': [audit(client, task) for task in args.task_id]}, ensure_ascii=False))