fix: harden PCB and iCDB verification lifecycle for beta release

This commit is contained in:
阿白叔 committed 2026-10-26 15:32:01 +08:00
1 parent 11a2b2e46e
commit a11eb3c766
33 files changed
+1226 -267

No files matched your search

@@ -0,0 +1,38 @@
# 0.2.2 异常关闭补充验证
本轮没有修改生产代码,原 0.2.2 修复包仍适用。新增 10 项故障注入/进程测试,
与此前事故及扩展安全测试合跑,**47 项全部通过**。
命令:
```powershell
build\release-env\Scripts\python.exe -m pytest -q tests/test_abnormal_shutdown.py tests/test_incident_safety.py tests/test_extended_safety.py
```
## 覆盖情况
| 场景 | 结果与边界 |
| --- | --- |
| 正常关闭忙碌中的校验界面 | 现有 UI 行为为请求停止队列、等待当前项结束,不直接退出正在操作的进程。 |
| 强制结束监督程序 | 真实 Windows 无害进程试验:worker 退出码 75,已登记的保存助手退出,模拟原生数据库的进程仍存活。 |
| PCB 在 COM 就绪前退出 | 注入目标文档断开,worker 输出 FAIL、safe_to_continue=False,不启动保存。 |
| PCB/iCDB 在同步时断开 | 注入 COM/RPC 断开错误,worker 输出 FAIL、safe_to_continue=False,不启动保存。 |
| 保存助手异常退出 | 没有日志、只有 SAVE_START 或即使残留全部成功标记,只要退出码非零,均失败。 |
| 保存/关闭证据不完整 | 助手退出码为 0,但缺少 IS_SAVED 或 CLOSE_OK,仍然失败。 |
| worker 自身崩溃 | 无 outcome 文件或留下 PASS 文件但退出码非零,监督器仍判失败;不查询旧 READY 状态把失败变成成功。 |
| 进程或数据库地址残留 | 既有测试确认不报释放成功、不自动删地址文件、不强杀原生进程。 |
| 批次后续动作 | 既有测试确认 safe_to_continue=False 停止后续项;CLI/UI 保留恢复所需的临时网络映射。 |
真实进程试验使用独立的 Python 睡眠进程模拟监督程序、保存助手和原生数据库,
没有人为强杀真正处于写库中的 Mentor/iCDB。COM 断开和保存崩溃通过边界注入验证,
不能将它们说成已经实测过原生数据库崩溃后的完整性恢复。
## 不能保证的部分
工具退出保护旨在停止新的自动化操作并保留现场。已经发出的原生 COM 操作可能仍在进行,
本工具无法保证取消或回滚该操作。若 PCB/iCDB 本身被强杀、机器断电或磁盘写入失败,
数据库可能已经不一致,需要 Mentor 原生恢复或一致备份;程序不自动选择恢复版本或覆盖文件。
正常流程的本地真实验证另见
[本地验证与安全审查](2026-10-26-local-validation-and-audit.md):最终 EXE 校验成功,
Work/Cert 正常重新打开,最终无 PCB/iCDB 残留,原样本 20,994 个文件内容未变。
@@ -0,0 +1,72 @@
# 0.2.1 — PCB / iCDB emergency safety fix
Superseded by **0.2.2** after local Mentor testing found the already-verified
Forward Annotation defect. See [local validation and audit](2026-10-26-local-validation-and-audit.md).
Base: `11a2b2e` (`r4-stability-20260929`). This patch addresses confirmed unsafe
code paths. It does not establish the cause of a particular field incident and
does not repair an already damaged PCB/database.
## Changes
- Preserve `database/cdbsvr/sAddress.adr`. A TCP timeout is not evidence that its
owner is dead. Any existing advertisement (live, unreachable or invalid)
blocks automatic Verify until the native session is reviewed.
- Block a new Verify while any Expedition PCB session is already running,
before changing project configuration or attaching to shared COM objects.
- Do not auto-confirm design-lock overrides or choose a database restoration.
Record `DATABASE_RECOVERY_REQUIRED` without clicking the prompt.
- Release Python COM references before starting the save helper; release the
helper's document/integration references before `app.Quit`.
- Observe PCB/launcher/Library Manager exit. Neither a cleanup request nor
Save/Close markers alone count as process release. A surviving iCDB address
also prevents success.
- On timeout or failure, stop automation clients without killing the native
PCB/iCDB process tree. The Job Object no longer kills native descendants when
its handle closes. Library Manager shutdown requests no longer fall back to
force termination.
- Stop the batch on `safe_to_continue=False`, including unexpected exceptions.
Preserve available evidence backups on failure. Record retained processes,
the private desktop and project in `recovery-required.json`; the UI points
the operator to the recovery evidence.
## Operational consequences
The normal path still performs Project Integration and saves through Mentor.
It is **not** a read-only PCB check. The adapter can also align the CentralLibrary
entry in `PCB/pcb.prj`, preserving its original in the evidence directory.
A failure can deliberately leave a native session alive on the private desktop.
This avoids interrupting a database write; it is reported as a failure, never as
successful release. Review the recorded desktop/PIDs with the maintainer before
closing/recovering that session. Do not delete the address/lock files merely
because a connection probe timed out. The presence of an old address may require
manual Mentor recovery even when no local PCB process remains.
Existing partial backups exclude volatile database files and network runs may
skip them; they are **not** a complete database rollback. Before field testing,
use a consistent, isolated copy made after the original native session closes.
Opening a copied database can itself cause Mentor to report a moved/copied DB.
## Validation
The incident regression suite covers address preservation, ownership checks,
recovery prompts without clicks, COM reference lifetime, retained PCB/iCDB state,
supervisor rejection of false PASS, evidence retention and batch stopping.
A real Windows Job Object test uses harmless Python processes to check that
automation abort/handle closure does not terminate a native-like child.
Run `python -m pytest -q` and `python -m compileall -q src tests`. Packaging uses
`packaging/Build-CbbRefreshVerify.ps1`, including its frozen UI smoke check.
These checks do not validate recovery of the user's affected production PCB.
Validation completed on Windows 11 / Python 3.12.10:
- Full suite: **354 passed** (including 18 incident regression cases).
- Python compilation and Git whitespace checks passed.
- The 32-bit cscript host compiled a non-executing wrapper of the save helper
successfully; this checks syntax without connecting to Mentor.
- PyInstaller 6.22.3 build and frozen UI creation/clean-shutdown smoke passed.
Live Mentor verification and damaged-database recovery remain unvalidated.
The package has not been deployed to production or tested on Windows 10.
@@ -0,0 +1,82 @@
# 0.2.2 本地功能验证与安全审查
日期:2026-10-26。基线:`11a2b2e`,在 0.2.1 紧急补丁之上继续修复。
环境:Windows 11、Python 3.12.10、Mentor EE7.9.5EE。
## 真实试跑结果
使用仓库已有的历史成功样本 `IP101GR`,完整复制到
`diagnostics/local-verification-20261026/library`。原样本 20,994 个文件、
556,098,864 字节,验证前后 SHA-256 比对没有变化。所有写操作针对隔离副本。
| 检查 | 结果及证据 |
| --- | --- |
| 0.2.1 EXE 首次试跑 | **发现功能缺陷**:四项同步均为 2,`IsForwardAnnotationAllowed=False`,程序仍调用 ForwardAnnotate;Mentor 明确拒绝。保护机制停止批次、保留会话,没有误报 PASS。 |
| 首次失败后的关闭 | 精确核对隔离工程身份后,32 位助手正常 Close(False)/Quit;记录 `IsSaved=True`、`Close=True`。未强杀 PCB/iCDB。 |
| 修复后的源码试跑 | PASS、GREEN;`IsVerifiedReuseBlock` 返回 `READY/raw=1`;保存、关闭、进程退出均确认。 |
| 再次完整校验 | 第二次 PASS、GREEN;验证同一副本可重复校验。 |
| 最终 0.2.2 EXE 实测 | 打包后的 EXE 再次完成真实校验,退出码 0、PASS/GREEN;未遗留 PCB 进程。 |
| 正常打开 Work PCB | 不带 `-ReusableCircuit`,按普通 PCB 启动,COM 工程身份匹配,正常关闭,未发生数据库打不开错误。 |
| 正常打开 Cert PCB | 同上,Cert 工程身份匹配并正常关闭。 |
| 最终 EXE 校验后再打开 Work PCB | 再次普通打开、身份核对和正常关闭通过。 |
每次成功退出后检查没有残留的对应 PCB 进程,且工程的 `sAddress.adr`
已消失。新生成的 iCDB 日志记录 `Database closed` 和 `icdb.dat closed`。
保存日志仍有 Mentor 的子客户端自动解锁警告;随后数据库关闭、两份 PCB
重新打开均成功,未将这些警告视为已证实的数据库损坏。
原始证据在 `diagnostics/local-verification-20261026`:
`frozen-first-run`、`close-first-run.log`、`source-second-run`、
`source-third-run`、`normal-reopen-work`、`normal-reopen-cert`、
`frozen-final-run`、`normal-reopen-work-final`、`source-integrity.json`。
工程与原始现场文件不包含在发布 ZIP 中。
## 本轮修复
| 问题 | 修复 |
| --- | --- |
| 已验证、全同步的块被重复执行禁止的 Forward Annotation | 尊重原生 Allowed 标志;保留后续 Save/Close 和 READY 权威确认。需要同步却不允许执行时仍报错。 |
| `pcb.prj` 容错 UTF-8 解码可能替换 ANSI 字符 | 只替换目标字段的字节;严格处理 BOM/UTF-16,备份保持原字节。 |
| 写入异常可能截断 `pcb.prj` | 同卷暂存后原子替换;替换失败保持原文件。 |
| 目录 Junction 可绕过工程范围校验 | 校验真实解析路径;交给 Mentor 的路径仍保留原盘符表达。 |
| “成功文本”覆盖非零退出码 | Python 和旧 PowerShell 内容检查都要求退出码 0。 |
| 内容检查位于互斥锁之外 | 全流程持有串行互斥锁,包括内容检查及最终状态读取。 |
| 保留原生会话后仍可能卸载临时网络盘 | CLI 和 UI 在不安全结果/异常时保留本次映射,供恢复使用。 |
| 监督程序异常退出后自动化可能继续写入 | 子进程监视监督程序句柄;停止自动化及保存助手,保留原生数据库拥有者。用真实无害 Windows 进程测试此行为。 |
| 旧树状态读取路径强杀 Library Manager | 请求正常关闭并确认退出;未关闭则保留并报错。 |
| 动态 WMI 查询与相对系统命令查找 | 固定进程查询白名单;使用系统目录中的 taskkill.exe。移除未使用的自动丢弃文档处理器。 |
| 随包/构建依赖的已知漏洞 | Pillow 12.3.0 → 13.0.0;setuptools 84.0.0 → 84.1.0。只更新独立构建环境,不修改全局 Python。 |
## 自动化验证与扫描范围
- **373 项 pytest 通过**,包含初始事故和本轮扩展回归用例。
- 两组 PowerShell 测试通过。新增测试用无害的假 importer 验证“输出成功但退出码 7”必须失败,不打开 Mentor 数据。
- Python 编译检查通过。
- PyInstaller 构建、冻结版界面启动/关闭及真实校验均通过;检查 EXE
内部代码确认为 0.2.2,内部 Pillow 版本确认为 13.0.0,VBS 和规则文件
与已测试源码逐字节一致。
- Coverage:语句覆盖 72.19%,分支覆盖 62.69%,综合 70%。实际 Mentor
子进程试跑不计入此覆盖率;没有声称全部代码分支均被覆盖。
- Bandit 扫描整个 `src`:0 高、0 中、55 低。低等级提示分类:
8 个 subprocess 导入、12 个受控参数列表调用、25 个容错异常处理、
8 个诊断枚举跳过、2 个 Windows 打开日志目录操作。原始报告全部保留。
- 一处全接口端口检测明确标注 B104 排除:只尝试 bind 后立即关闭,
不调用 listen/accept,不提供网络服务。
- pip-audit 检查 18 个运行/构建依赖及其依赖:首次发现 38 条已知公告
(Pillow 37、setuptools 1),升级后复扫 **0 条已知漏洞**。
- 发布依赖清单:`packaging/requirements-build.txt`。扫描报告与覆盖率数据
在证据目录的 `bandit-final.json`、`dependency-audit-fixed.json`、`coverage.json`。
扫描覆盖本仓库 Python 运行代码、相关旧 PowerShell 入口和本次构建依赖;
没有对闭源 Mentor 二进制或整台 Windows 系统作“无漏洞”保证。
## 使用范围与未验证项
本轮真实样本为单个已经验证过的 IP101GR。非绿色状态推进、错误弹窗、
超时、取消、网络映射故障、并发和异常终止主要由隔离自动测试覆盖。
没有使用生产网络库、生产 DMS 凭据,也没有在 Windows 10 上运行。
本补丁防止不安全的继续操作;没有恢复用户原事故中受损的 PCB。
Verify 本身会通过 Mentor 更新工程数据,不能当作只读检查。
异常时可能保留私有桌面中的原生会话和临时盘符;查看恢复记录后进行
正常关闭或使用 Mentor 恢复流程,不应直接删锁或强杀数据库进程。
+41
View File
@@ -0,0 +1,41 @@
# CBB Verify v0.2.2-beta.1
**Beta 预发布,供隔离副本和小范围现场验收使用,尚未完成生产验收。**
本版本修复 PCB/iCDB 校验流程中的会话释放与失败收尾风险。运行逻辑与已完成
本地真实验证的 0.2.2 一致,发布版本标识为 `0.2.2b1`,Git 标签为
`v0.2.2-beta.1`。
## 主要修复
- 保存关闭前释放 COM 引用,确认 PCB 退出及数据库地址释放后才允许成功。
- 不自动移走 `sAddress.adr`、接管带锁设计或选择数据库恢复;异常时停止批次,
保留原生会话、证据及恢复所需的网络映射。
- 监督程序异常退出时停止自动化和保存助手,不连带强杀原生 PCB/iCDB。
- 已验证且全同步的 CBB 尊重 Mentor 的 Allowed 标志,避免重复执行被禁止的
Forward Annotation;仍要求 Save/Close 和权威 READY 确认。
- 保留 `pcb.prj` 原始编码和备份,以同卷原子替换防止截断;阻止目录链接越界。
- 全流程串行互斥;Python/PowerShell 内容检查不再让成功文本覆盖非零退出码。
- 更新 Pillow 至 13.0.0、构建 setuptools 至 84.1.0;18 个依赖复扫无已知漏洞。
## 已有验证
- Windows 11 / Mentor EE7.9.5EE,本地 IP101GR 隔离副本重复真实校验通过。
- Work/Cert PCB 普通重新打开及关闭通过;最终无 PCB/iCDB 残留。
- 原样本 20,994 个文件内容指纹保持不变。
- 发布前全量 Python 测试 **383 项通过**,两组 PowerShell 测试和编译检查通过。
测试期间出现 1 条 pywinauto 的 STA COM 模式提示,未导致失败。
冻结版 UI 检查及构建指纹记录在安装包的 `BUILD-MANIFEST.json` 中。
- 异常关闭专项覆盖 47 项相关测试,包括真实 Windows 无害进程的监督程序退出试验。
## 安装及验收边界
下载 ZIP 后完整解压,运行 `CbbRefreshVerify.exe`,保留 `_internal` 目录。
先在正常关闭后取得的一致、隔离工程副本上验收,不直接覆盖原事故数据。
现场仍需验证客户实际机器、生产网络库、DMS、多个未校验 CBB 的连续运行和
原事故样本;Windows 10 尚未验证。本补丁不代表受损 PCB 已恢复,也不能保证
PCB/iCDB 被强杀或机器断电后数据库自动修复。
详见 [本地验证与安全审查](2026-10-26-local-validation-and-audit.md) 和
[异常关闭补充验证](2026-10-26-abnormal-shutdown-validation.md)。