fix(pybot×actpred): v3 审计 P1 修复 3 项——零依赖承诺 + ONNX 元数据/残差全链路

- robot.py numpy 恢复函数级 lazy import,纯 .mt 脚本执行不再需要 numpy(v3-P1-1)
- export_onnx 写入训练配置元数据;onnx_infer 自动识别 normalize_mode/predict_delta 并支持残差加回(v3-P1-2)
- pybot --loop 补 .onnx 后端分支,zscore 缺 action_stats.npy 时告警(P2-a 闭环)
- 回归测试:actpred TestOnnxMetadata +7、pybot 零依赖导入 +1(88/148 全绿)
- 附 v3 审计报告:13 项 v2 修复回归核对 + 7 项新发现(P0-2 遗留 + P2/P3 六项)
This commit is contained in:
qing committed 2026-08-14 22:13:06 +08:00
1 parent b73628b2e5
commit 35ee614ca9
8 files changed
+427 -14

No files matched your search

+31
View File
@@ -458,3 +458,34 @@ def test_loop_imu_multi_recorded(mock_i2c, tmp_path):
assert imus.shape == (3, 16)
assert np.allclose(imus[:, 0], 1.0) # sensor0 roll
assert np.allclose(imus[:, 9], 4.0) # sensor1 pitch
def test_robot_importable_without_numpy():
"""零依赖承诺(v3-P1-1):屏蔽 numpy 后 pybot.robot 仍可导入
纯 .mt 脚本执行路径不得要求 numpy——numpy 仅在 --record/--loop
函数内 lazy import。子进程隔离避免污染当前 pytest 会话。
"""
import os
import subprocess
import sys
child = (
"import sys, importlib.util\n"
"if importlib.util.find_spec('fcntl') is None:\n" # Windows 开发机
" from types import ModuleType\n"
" _m = ModuleType('fcntl'); _m.ioctl = lambda *a, **k: 0\n"
" sys.modules['fcntl'] = _m\n"
"import builtins\n"
"_real = builtins.__import__\n"
"def _fake(name, *a, **k):\n"
" if name == 'numpy' or name.startswith('numpy.'):\n"
" raise ImportError('numpy blocked by test')\n"
" return _real(name, *a, **k)\n"
"builtins.__import__ = _fake\n"
"import pybot.robot\n"
"print('ok')\n"
)
repo = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
r = subprocess.run([sys.executable, "-c", child],
capture_output=True, text=True, cwd=repo)
assert r.returncode == 0 and "ok" in r.stdout, r.stderr