feat(v2): add safe runtime configuration
This commit is contained in:
@@ -53,6 +53,7 @@ V2 对应模块的当前落实与 T-304 目标如下:
|
||||
| 模块 | V2 目标位置 | 职责 | 不负责 |
|
||||
| --- | --- | --- | --- |
|
||||
| 回放解码器 | `v2/cmd/regression` | 用受控 FFmpeg 顺序读取 BGR 帧,供本机录像回归 | RTSP 重连、UI 绘制 |
|
||||
| 运行配置 | `v2/internal/config` | 校验公开 JSON、仅从环境变量解析 RTSP URL、生成非敏感配置版本 | 保存或显示 URL、账号、密码 |
|
||||
| ONNX Pose | `v2/internal/pose` | 114 letterbox、RGB/CHW、NMS、关键点及坐标还原 | 人员 ID、摔倒结论 |
|
||||
| 事件引擎 | `v2/internal/fall` | 复现 V1 的跟踪、证据、四态状态机和 `FallEvent` | 视频解码、声音、文件 |
|
||||
| Windows UI | `v2/internal/ui` | Walk 顶部“监控/设置”Tab、渲染最新帧和已计算状态 | 直接读 RTSP、执行 ONNX 或事件规则 |
|
||||
|
||||
@@ -42,6 +42,15 @@
|
||||
- 灵敏度参数(默认放宽,适配低位俯视):`require_rapid_drop`(默认 false,持续水平即可进入疑似,不再强制先检测到快速下移);`require_lower_body`(默认 false,质量门控只强制肩+髋,膝踝可缺);`horizontal_angle_threshold_degrees`(默认 45,躯干与水平夹角≤此值算水平)。放宽后由 `confirm_window_seconds` 作为主要防误报闸——弯腰、捡物不会持续水平到确认窗满。三者进入 `config_version`,可经设置调整并追溯。
|
||||
- 缺少环境变量、模型不存在或哈希不符时,应用显示配置错误,不启动监控。
|
||||
|
||||
### V2 Go 运行配置
|
||||
|
||||
`v2/config.example.json` 是 V2 的公开配置形状。它保留 V1 的来源、模型、事件和工件语义,但将 V2 交付依赖显式写入 `model.onnx`、`model.ort_dll` 和 `tools.ffmpeg`/`tools.ffprobe`:
|
||||
|
||||
- `source` 只接受 `id`、`rtsp_url_env`、`transport`、`timeout_seconds` 和 `low_latency`。任何 `url`、`rtsp_url`、`host`、`username` 或 `password` 字段都会被拒绝,即使它们为空;实际流地址只从指定环境变量进入进程内存。
|
||||
- `model.sha256` 必须是锁定 ONNX 的 64 位十六进制 SHA-256;`confidence_threshold` 是 Pose 框过滤阈值。配置相对路径相对于配置文件解析,但只在启动预检时要求实际文件存在。
|
||||
- `event` 字段与 V1 的默认事件语义相同。V2 使用 `source.id`、模型 SHA、模型置信度和这些事件字段生成 `cfg-<sha256>`;URL、工具路径和工件路径均不进入该版本值。
|
||||
- `artifacts.event_dir` 只保存本地 PNG/JSONL 事件证据。V2 发布脚本生成的 `runtime-manifest.json` 记录 ONNX Runtime、FFmpeg、FFprobe 和 ONNX 的来源文件哈希;示例 `runtime-manifest.example.json` 不是交付证据。
|
||||
|
||||
## 核心数据
|
||||
|
||||
```text
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
- Create: `v2/assets/runtime-manifest.example.json`
|
||||
- Modify: `docs/api.md`
|
||||
|
||||
- [ ] **Step 1: Write failing configuration tests**
|
||||
- [x] **Step 1: Write failing configuration tests**
|
||||
|
||||
```go
|
||||
func TestLoadResolvesOnlyNamedEnvironmentURL(t *testing.T) {
|
||||
@@ -56,12 +56,12 @@ func TestLoadRejectsEmbeddedRTSPURL(t *testing.T) {
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run the focused test and verify the missing package fails**
|
||||
- [x] **Step 2: Run the focused test and verify the missing package fails**
|
||||
|
||||
Run: `Set-Location v2; go test ./internal/config -run TestLoad -v`
|
||||
Expected: FAIL because `internal/config` does not exist.
|
||||
|
||||
- [ ] **Step 3: Implement the minimal public contract**
|
||||
- [x] **Step 3: Implement the minimal public contract**
|
||||
|
||||
```go
|
||||
type Config struct {
|
||||
@@ -79,12 +79,12 @@ func Load(path string) (Config, error) {
|
||||
|
||||
Validate all required files and 64-hex model hash before monitoring starts. Return generic path/configuration errors; do not include the resolved URL in errors. Document the V2 field meanings and unchanged `FallEvent` fields in `docs/api.md`.
|
||||
|
||||
- [ ] **Step 4: Re-run focused and package tests**
|
||||
- [x] **Step 4: Re-run focused and package tests**
|
||||
|
||||
Run: `Set-Location v2; go test ./internal/config -v`
|
||||
Expected: PASS, including missing environment, embedded URL, invalid hash and version-redaction cases.
|
||||
|
||||
- [ ] **Step 5: Commit the configuration slice**
|
||||
- [x] **Step 5: Commit the configuration slice**
|
||||
|
||||
```powershell
|
||||
git add v2/config.example.json v2/internal/config v2/assets/runtime-manifest.example.json docs/api.md
|
||||
|
||||
Reference in New Issue
Block a user