feat(v1): add secure configuration baseline

This commit is contained in:
ila
2026-07-21 09:45:59 +08:00
parent 7b05efe56c
commit 0b01e1bf24
13 changed files with 281 additions and 19 deletions
+2 -1
View File
@@ -42,7 +42,8 @@
| 基线检查 | `./init.ps1` |
| 旧代码编译检查 | `python -m compileall -q demo` |
| 旧 GUI 启动 | `Set-Location demo; python main.py` |
| V1 测试 | T-101 创建 `v1/requirements.txt` 和测试后写入真实 `pytest` 命令 |
| V1 依赖安装 | `python -m pip install -r v1/requirements.txt`(显式执行;`init.ps1` 不自动安装) |
| V1 单元测试 | `python -m pytest v1/tests -v` |
| V2 测试 | T-302 创建 Go 模块后使用 `go test ./...` |
## 演进决策
+1 -1
View File
@@ -14,7 +14,7 @@
| ID | 任务 | 依赖 | 验收要点 | 状态 |
| --- | --- | --- | --- | --- |
| T-101 | 创建 V1 包、依赖清单、示例配置和忽略规则 | T-000 | `v1/` 可导入;真实 RTSP 凭证被拒绝提交;`pytest` 能运行。 | DOING |
| T-101 | 创建 V1 包、依赖清单、示例配置和忽略规则 | T-000 | `v1/` 可导入;真实 RTSP 凭证被拒绝提交;`pytest` 能运行。 | DONE |
| T-102 | 实现可重连的视频源与录像回放适配器 | T-101 | 有效本地录像可按时间戳产帧;无效源进入连接错误状态且不崩溃。 | TODO |
| T-103 | 实现 Pose 适配器与模型来源校验 | T-102 | 输出 person box、17 点和置信度;错误模型或哈希不符时给出明确错误。 | TODO |
| T-104 | 实现人员跟踪与姿态质量门控 | T-103 | 连续人员维持 ID;低质量、缺失膝踝或空帧不会产生倒地候选。 | TODO |
+6 -6
View File
@@ -36,7 +36,7 @@
- Modify: `.gitignore`
- Modify: `init.ps1`, `docs/03-tech-stack.md`, `docs/current-state.md`
- [ ] **Step 1: Write the failing configuration test**
- [x] **Step 1: Write the failing configuration test**
```python
from v1.config import load_config
@@ -55,12 +55,12 @@ def test_load_config_resolves_rtsp_environment_variable(tmp_path, monkeypatch):
assert load_config(config_file).source_url == "rtsp://example"
```
- [ ] **Step 2: Run the test to verify it fails**
- [x] **Step 2: Run the test to verify it fails**
Run: `python -m pytest v1/tests/test_config.py -v`
Expected: FAIL because `v1.config` does not exist.
- [ ] **Step 3: Implement the smallest configuration interface**
- [x] **Step 3: Implement the smallest configuration interface**
```python
import json
@@ -114,12 +114,12 @@ def load_config(path: Path) -> AppConfig:
`config.local.json`, `artifacts/`, `testdata/private/`, `*.onnx` and camera credentials must be ignored; `config.example.json` contains only `rtsp_url_env`.
- [ ] **Step 4: Run baseline tests and update the standard command**
- [x] **Step 4: Run baseline tests and update the standard command**
Run: `python -m pytest v1/tests -v`
Expected: PASS. Update `init.ps1` so it installs `v1/requirements.txt` and runs this command.
Expected: PASS. Update `init.ps1` so it checks the required runtime imports and runs this command; keep `v1/requirements.txt` as an explicit installation command rather than mutating the environment during verification.
- [ ] **Step 5: Commit**
- [x] **Step 5: Commit**
```powershell
git add .gitignore init.ps1 v1 docs/03-tech-stack.md docs/current-state.md docs/06-tasks.md progress.md
+2 -2
View File
@@ -15,7 +15,7 @@
},
"model": {
"path": "models/best.pt",
"sha256": "填写受控模型哈希",
"sha256": "0000000000000000000000000000000000000000000000000000000000000000",
"confidence_threshold": 0.25
},
"event": {
@@ -32,7 +32,7 @@
```
- `rtsp_url_env` 必填;应用从同名环境变量读取真实 URL。
- 数值是待现场录像校准的默认值;每个值必须真正进入事件逻辑。
- 数值是待现场录像校准的默认值;每个值必须真正进入事件逻辑。示例中的全零 SHA-256 只占位配置形状,T-103 必须以受控模型的真实哈希替换并验证后才能启动推理。
- 缺少环境变量、模型不存在或哈希不符时,应用显示配置错误,不启动监控。
## 核心数据
+8 -8
View File
@@ -4,18 +4,18 @@
## 当前快照
- 日期:2026-07-20
- 阶段:V1 工程化起步;T-101 进行中。
- 日期:2026-07-21
- 阶段:V1 工程化起步;T-101 已验收,等待 T-102。
- 已验证环境:Windows PowerShell;Python 3.8.10;Ultralytics 8.3.205;PyQt5 可导入。
- 旧生产基线:`demo/main.py`、`demo/fall_detection_gui.py`、`demo/detect_fall.py`、`demo/best.pt`。
- V1 代码:`v1/` 目录存在但尚无实现。
- V1 代码:已建立 `v1/__init__.py`、`v1/config.py`、安全的 `config.example.json`、固定依赖清单和配置单元测试;视频源、Pose、跟踪、证据、状态机和 GUI 尚未实现。
- V2 代码:`v2/` 目录存在但尚无实现。
- 非代码设计工件:docs/ui/silver-pose-ui-ux-spec.md、docs/ui/2026-07-20-html-prototype-plan.md、docs/ui/silver-pose-v1-prototype.html 与 docs/ui/silver-pose-v2-prototype.html 已建立。v2 HTML 是符合正式浅色 Windows 规范的当前视觉参考:浅灰蓝底、白色卡片,红色只表示确认摔倒、其弹窗和事件证据;文件名中的 v2 只表示原型设计修订,不能理解为 Go V2 实现已开始。v1 HTML 保留为历史深色对照。两者均使用顶部双 Tab、设置草稿与状态交互,且画面、事件和时间都是模拟数据,不连接真实摄像头、模型或网络,也不改变 Phase 1 任务顺序。
- 测试:`python -m compileall -q demo` 已通过;T-101 开始前 `v1/tests` 尚不存在,因此 `python -m pytest v1/tests -v` 以目录未找到退出,这是待建立的初始测试基线。
- 测试:`python -m compileall -q demo` 已通过;`python -m pytest v1/tests -v` 当前有 2 个配置测试并已通过。`init.ps1` 会检查运行时依赖、编译旧基线并运行 V1 测试,但不会安装软件包。
- 模型:`demo/best.pt` 可加载为 YOLO Pose,类别 `person`,`kpt_shape=[17, 3]`;与 `D:\PythonP\fall_detection\best.pt` 哈希一致。
- 当前标准启动:`./init.ps1`。
- 当前标准验证:`python -m compileall -q demo`。
- 当前 blocker:V1 依赖清单、示例配置、回归录像及事件标签尚未创建;真实海康 RTSP 流尚未接入。
- 当前 blocker:回归录像及事件标签尚未创建;真实海康 RTSP 流尚未接入。
全局环境的 `pip check` 存在其他项目的包冲突,因此它不是 Silver Pose 的验收命令。`init.ps1` 只检查本项目实际导入的 OpenCV、NumPy、Ultralytics 与 PyQt5,并在命令非零退出时失败。
@@ -32,9 +32,9 @@
## 任务状态
- 已完成:T-000(Harness 文档与旧基线快照)。
- 正在进行:T-101(创建 V1 包、依赖清单、示例配置和忽略规则)。
- 下一个可领取:完成 T-101 后为 T-102。
- 已完成:T-000(Harness 文档与旧基线快照)、T-101(V1 安全配置基线)。
- 正在进行:无。
- 下一个可领取:T-102。
## 当前可运行内容