From ffe066cb1e4225732295d470e26fb78605fbc36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Tue, 29 Sep 2026 15:42:21 +0800 Subject: [PATCH] Initial import of DxDesigner part replacement tool (r21) --- .gitignore | 17 + docs/reviews/2026-09-06-code-review.md | 174 + docs/reviews/2026-09-06-controller-repros.py | 43 + docs/reviews/2026-09-06-native-repros.py | 114 + docs/reviews/2026-09-06-remediation.md | 49 + docs/reviews/2026-09-06-review-repros.py | 133 + docs/reviews/2026-09-06-ui-repros.py | 108 + docs/reviews/2026-09-06-ui-review.md | 120 + docs/reviews/2026-09-07-r11-gui-acceptance.md | 48 + .../2026-09-07-r12-multisheet-acceptance.md | 45 + ...26-09-07-r13-value-nc-delete-acceptance.md | 31 + ...6-09-07-r14-directory-switch-acceptance.md | 37 + .../2026-09-08-r15-long-run-acceptance.md | 81 + .../2026-09-08-r16-portable-performance.md | 51 + docs/reviews/2026-09-08-v1.0.0-release.md | 40 + ...ner-795-part-replacement-implementation.md | 1115 +++++ ...01-dxdesigner-795-refdes-implementation.md | 1128 +++++ ...cement-trial-task-center-implementation.md | 456 ++ .../plans/2026-09-06-value-options-layout.md | 11 + ...-dxdesigner-795-part-replacement-design.md | 525 ++ ...2026-09-01-dxdesigner-795-refdes-design.md | 306 ++ ...-parameter-presentation-transfer-design.md | 237 + ...rt-replacement-trial-task-center-design.md | 340 ++ .../dxdesigner-795-part-replacement-live.md | 254 + docs/user/automatic-designer-startup.md | 30 + docs/user/continuous-queue.md | 39 + docs/user/interrupted-recovery.md | 22 + docs/user/part-replacement.md | 169 + docs/user/permanent-task-deletion.md | 13 + docs/user/progress-timeout.md | 23 + docs/user/r5-execution-safety.md | 46 + docs/user/trial-task-center.md | 55 + docs/user/value-copy-and-layout.md | 31 + integration/dxdesigner795/BridgeCommon.vbs | 225 + integration/dxdesigner795/Install.ps1 | 183 + integration/dxdesigner795/MenuAdd.vbs | 22 + integration/dxdesigner795/MenuRuntime.vbs | 86 + .../dxdesigner795/PartReplaceBridge.vbs | 4402 +++++++++++++++++ .../dxdesigner795/PartReplaceMenuRuntime.vbs | 332 ++ .../dxdesigner795/PartReplaceProbe.vbs | 1161 +++++ .../dxdesigner795/PartReplacementContract.ps1 | 152 + integration/dxdesigner795/PathSafety.ps1 | 503 ++ .../dxdesigner795/QuickPartReplace.vbs | 2583 ++++++++++ .../dxdesigner795/Start-PartReplacement.ps1 | 460 ++ packaging/Build-DxPartReplace.ps1 | 134 + packaging/DxPartReplace.spec | 96 + pyproject.toml | 24 + src/dx_productivity.egg-info/PKG-INFO | 14 + src/dx_productivity.egg-info/SOURCES.txt | 45 + .../dependency_links.txt | 1 + src/dx_productivity.egg-info/entry_points.txt | 3 + src/dx_productivity.egg-info/requires.txt | 11 + src/dx_productivity.egg-info/top_level.txt | 1 + src/dx_productivity/__init__.py | 1 + src/dx_productivity/__main__.py | 6 + src/dx_productivity/part_replace/__init__.py | 22 + .../part_replace/certification.py | 343 ++ src/dx_productivity/part_replace/cli.py | 340 ++ .../part_replace/command_schema.py | 101 + .../part_replace/compatibility_profile.py | 1067 ++++ .../part_replace/controller.py | 2402 +++++++++ src/dx_productivity/part_replace/errors.py | 13 + src/dx_productivity/part_replace/inputs.py | 204 + src/dx_productivity/part_replace/mailbox.py | 221 + src/dx_productivity/part_replace/models.py | 156 + .../part_replace/operator_runtime.py | 446 ++ src/dx_productivity/part_replace/protocol.py | 405 ++ src/dx_productivity/part_replace/reports.py | 217 + src/dx_productivity/part_replace/run_store.py | 1235 +++++ .../part_replace/verification.py | 331 ++ .../trial_task_center/__init__.py | 15 + .../trial_task_center/application.py | 136 + .../trial_task_center/batch.py | 400 ++ .../trial_task_center/comparison.py | 365 ++ .../trial_task_center/errors.py | 29 + .../trial_task_center/evidence.py | 271 + .../trial_task_center/logging_setup.py | 257 + .../trial_task_center/models.py | 75 + .../trial_task_center/native_helper.py | 627 +++ .../trial_task_center/quick_run.py | 1918 +++++++ .../trial_task_center/recovery.py | 215 + .../trial_task_center/retention.py | 129 + .../trial_task_center/runner.py | 777 +++ .../trial_task_center/scanner.py | 125 + .../trial_task_center/sceneos_cli.py | 106 + .../trial_task_center/schematic_backup.py | 134 + .../trial_task_center/service.py | 746 +++ .../trial_task_center/store.py | 1226 +++++ .../trial_task_center/ui/__init__.py | 5 + .../trial_task_center/ui/main_window.py | 1734 +++++++ .../trial_task_center/ui/mapping_table.py | 62 + .../trial_task_center/ui/project_table.py | 122 + .../trial_task_center/ui/run_panel.py | 71 + .../trial_task_center/ui/styles.py | 38 + .../trial_task_center/ui/task_list.py | 48 + .../trial_task_center/ui/workers.py | 34 + .../trial_task_center/version.py | 1 + .../trial_task_center/worker_monitor.py | 229 + tests/conftest.py | 28 + .../compatibility-profile-v1.json | 206 + tests/fixtures/snapshot-after-compatible.json | 1 + tests/fixtures/snapshot-after-pin-change.json | 1 + tests/fixtures/snapshot-before.json | 1 + .../profile-after-invalid.json | 16 + .../profile-after-valid.json | 17 + .../trial_task_center/profile-before.json | 17 + tests/integration/mock_dxdesigner.py | 975 ++++ .../test_automatic_replacement_regression.py | 484 ++ tests/integration/test_part_replace_bridge.py | 2638 ++++++++++ .../test_part_replace_end_to_end.py | 1216 +++++ .../integration/test_part_replace_install.py | 2302 +++++++++ tests/integration/test_part_replace_probe.py | 1232 +++++ .../test_quick_part_replace_contract.py | 211 + .../integration/test_quick_session_startup.py | 517 ++ tests/integration/test_quick_value_modes.py | 687 +++ tests/packaging/test_dx_part_replace_build.py | 90 + tests/part_replace/test_certification.py | 637 +++ tests/part_replace/test_cli.py | 1254 +++++ tests/part_replace/test_command_schema.py | 69 + .../test_compatibility_profile.py | 1040 ++++ tests/part_replace/test_controller.py | 2134 ++++++++ tests/part_replace/test_inputs.py | 189 + tests/part_replace/test_models.py | 75 + tests/part_replace/test_protocol.py | 356 ++ tests/part_replace/test_reports.py | 191 + tests/part_replace/test_run_store.py | 972 ++++ tests/part_replace/test_verification.py | 382 ++ tests/trial_task_center/test_application.py | 183 + tests/trial_task_center/test_batch.py | 1069 ++++ tests/trial_task_center/test_comparison.py | 170 + tests/trial_task_center/test_evidence.py | 233 + .../test_execution_safety.py | 94 + tests/trial_task_center/test_logging_setup.py | 180 + .../test_permanent_delete.py | 108 + tests/trial_task_center/test_quick_run.py | 980 ++++ tests/trial_task_center/test_recovery.py | 288 ++ tests/trial_task_center/test_retention.py | 74 + tests/trial_task_center/test_runner.py | 682 +++ tests/trial_task_center/test_scanner.py | 210 + tests/trial_task_center/test_sceneos_cli.py | 81 + tests/trial_task_center/test_service.py | 251 + .../test_session_failure_messages.py | 20 + tests/trial_task_center/test_store.py | 512 ++ tests/trial_task_center/test_value_options.py | 213 + .../trial_task_center/test_worker_monitor.py | 193 + tests/ui/test_execution_feedback.py | 317 ++ tests/ui/test_permanent_delete_ui.py | 83 + tests/ui/test_trial_task_center_window.py | 112 + tests/ui/test_trial_task_center_workflow.py | 769 +++ tests/ui/test_value_options_layout.py | 115 + tests/vbs/test_bridge_common.vbs | 136 + 151 files changed, 58745 insertions(+) create mode 100644 .gitignore create mode 100644 docs/reviews/2026-09-06-code-review.md create mode 100644 docs/reviews/2026-09-06-controller-repros.py create mode 100644 docs/reviews/2026-09-06-native-repros.py create mode 100644 docs/reviews/2026-09-06-remediation.md create mode 100644 docs/reviews/2026-09-06-review-repros.py create mode 100644 docs/reviews/2026-09-06-ui-repros.py create mode 100644 docs/reviews/2026-09-06-ui-review.md create mode 100644 docs/reviews/2026-09-07-r11-gui-acceptance.md create mode 100644 docs/reviews/2026-09-07-r12-multisheet-acceptance.md create mode 100644 docs/reviews/2026-09-07-r13-value-nc-delete-acceptance.md create mode 100644 docs/reviews/2026-09-07-r14-directory-switch-acceptance.md create mode 100644 docs/reviews/2026-09-08-r15-long-run-acceptance.md create mode 100644 docs/reviews/2026-09-08-r16-portable-performance.md create mode 100644 docs/reviews/2026-09-08-v1.0.0-release.md create mode 100644 docs/superpowers/plans/2026-09-01-dxdesigner-795-part-replacement-implementation.md create mode 100644 docs/superpowers/plans/2026-09-01-dxdesigner-795-refdes-implementation.md create mode 100644 docs/superpowers/plans/2026-09-04-dxdesigner-part-replacement-trial-task-center-implementation.md create mode 100644 docs/superpowers/plans/2026-09-06-value-options-layout.md create mode 100644 docs/superpowers/specs/2026-09-01-dxdesigner-795-part-replacement-design.md create mode 100644 docs/superpowers/specs/2026-09-01-dxdesigner-795-refdes-design.md create mode 100644 docs/superpowers/specs/2026-09-04-dxdesigner-795-parameter-presentation-transfer-design.md create mode 100644 docs/superpowers/specs/2026-09-04-dxdesigner-part-replacement-trial-task-center-design.md create mode 100644 docs/testing/dxdesigner-795-part-replacement-live.md create mode 100644 docs/user/automatic-designer-startup.md create mode 100644 docs/user/continuous-queue.md create mode 100644 docs/user/interrupted-recovery.md create mode 100644 docs/user/part-replacement.md create mode 100644 docs/user/permanent-task-deletion.md create mode 100644 docs/user/progress-timeout.md create mode 100644 docs/user/r5-execution-safety.md create mode 100644 docs/user/trial-task-center.md create mode 100644 docs/user/value-copy-and-layout.md create mode 100644 integration/dxdesigner795/BridgeCommon.vbs create mode 100644 integration/dxdesigner795/Install.ps1 create mode 100644 integration/dxdesigner795/MenuAdd.vbs create mode 100644 integration/dxdesigner795/MenuRuntime.vbs create mode 100644 integration/dxdesigner795/PartReplaceBridge.vbs create mode 100644 integration/dxdesigner795/PartReplaceMenuRuntime.vbs create mode 100644 integration/dxdesigner795/PartReplaceProbe.vbs create mode 100644 integration/dxdesigner795/PartReplacementContract.ps1 create mode 100644 integration/dxdesigner795/PathSafety.ps1 create mode 100644 integration/dxdesigner795/QuickPartReplace.vbs create mode 100644 integration/dxdesigner795/Start-PartReplacement.ps1 create mode 100644 packaging/Build-DxPartReplace.ps1 create mode 100644 packaging/DxPartReplace.spec create mode 100644 pyproject.toml create mode 100644 src/dx_productivity.egg-info/PKG-INFO create mode 100644 src/dx_productivity.egg-info/SOURCES.txt create mode 100644 src/dx_productivity.egg-info/dependency_links.txt create mode 100644 src/dx_productivity.egg-info/entry_points.txt create mode 100644 src/dx_productivity.egg-info/requires.txt create mode 100644 src/dx_productivity.egg-info/top_level.txt create mode 100644 src/dx_productivity/__init__.py create mode 100644 src/dx_productivity/__main__.py create mode 100644 src/dx_productivity/part_replace/__init__.py create mode 100644 src/dx_productivity/part_replace/certification.py create mode 100644 src/dx_productivity/part_replace/cli.py create mode 100644 src/dx_productivity/part_replace/command_schema.py create mode 100644 src/dx_productivity/part_replace/compatibility_profile.py create mode 100644 src/dx_productivity/part_replace/controller.py create mode 100644 src/dx_productivity/part_replace/errors.py create mode 100644 src/dx_productivity/part_replace/inputs.py create mode 100644 src/dx_productivity/part_replace/mailbox.py create mode 100644 src/dx_productivity/part_replace/models.py create mode 100644 src/dx_productivity/part_replace/operator_runtime.py create mode 100644 src/dx_productivity/part_replace/protocol.py create mode 100644 src/dx_productivity/part_replace/reports.py create mode 100644 src/dx_productivity/part_replace/run_store.py create mode 100644 src/dx_productivity/part_replace/verification.py create mode 100644 src/dx_productivity/trial_task_center/__init__.py create mode 100644 src/dx_productivity/trial_task_center/application.py create mode 100644 src/dx_productivity/trial_task_center/batch.py create mode 100644 src/dx_productivity/trial_task_center/comparison.py create mode 100644 src/dx_productivity/trial_task_center/errors.py create mode 100644 src/dx_productivity/trial_task_center/evidence.py create mode 100644 src/dx_productivity/trial_task_center/logging_setup.py create mode 100644 src/dx_productivity/trial_task_center/models.py create mode 100644 src/dx_productivity/trial_task_center/native_helper.py create mode 100644 src/dx_productivity/trial_task_center/quick_run.py create mode 100644 src/dx_productivity/trial_task_center/recovery.py create mode 100644 src/dx_productivity/trial_task_center/retention.py create mode 100644 src/dx_productivity/trial_task_center/runner.py create mode 100644 src/dx_productivity/trial_task_center/scanner.py create mode 100644 src/dx_productivity/trial_task_center/sceneos_cli.py create mode 100644 src/dx_productivity/trial_task_center/schematic_backup.py create mode 100644 src/dx_productivity/trial_task_center/service.py create mode 100644 src/dx_productivity/trial_task_center/store.py create mode 100644 src/dx_productivity/trial_task_center/ui/__init__.py create mode 100644 src/dx_productivity/trial_task_center/ui/main_window.py create mode 100644 src/dx_productivity/trial_task_center/ui/mapping_table.py create mode 100644 src/dx_productivity/trial_task_center/ui/project_table.py create mode 100644 src/dx_productivity/trial_task_center/ui/run_panel.py create mode 100644 src/dx_productivity/trial_task_center/ui/styles.py create mode 100644 src/dx_productivity/trial_task_center/ui/task_list.py create mode 100644 src/dx_productivity/trial_task_center/ui/workers.py create mode 100644 src/dx_productivity/trial_task_center/version.py create mode 100644 src/dx_productivity/trial_task_center/worker_monitor.py create mode 100644 tests/conftest.py create mode 100644 tests/fixtures/part_replace/compatibility-profile-v1.json create mode 100644 tests/fixtures/snapshot-after-compatible.json create mode 100644 tests/fixtures/snapshot-after-pin-change.json create mode 100644 tests/fixtures/snapshot-before.json create mode 100644 tests/fixtures/trial_task_center/profile-after-invalid.json create mode 100644 tests/fixtures/trial_task_center/profile-after-valid.json create mode 100644 tests/fixtures/trial_task_center/profile-before.json create mode 100644 tests/integration/mock_dxdesigner.py create mode 100644 tests/integration/test_automatic_replacement_regression.py create mode 100644 tests/integration/test_part_replace_bridge.py create mode 100644 tests/integration/test_part_replace_end_to_end.py create mode 100644 tests/integration/test_part_replace_install.py create mode 100644 tests/integration/test_part_replace_probe.py create mode 100644 tests/integration/test_quick_part_replace_contract.py create mode 100644 tests/integration/test_quick_session_startup.py create mode 100644 tests/integration/test_quick_value_modes.py create mode 100644 tests/packaging/test_dx_part_replace_build.py create mode 100644 tests/part_replace/test_certification.py create mode 100644 tests/part_replace/test_cli.py create mode 100644 tests/part_replace/test_command_schema.py create mode 100644 tests/part_replace/test_compatibility_profile.py create mode 100644 tests/part_replace/test_controller.py create mode 100644 tests/part_replace/test_inputs.py create mode 100644 tests/part_replace/test_models.py create mode 100644 tests/part_replace/test_protocol.py create mode 100644 tests/part_replace/test_reports.py create mode 100644 tests/part_replace/test_run_store.py create mode 100644 tests/part_replace/test_verification.py create mode 100644 tests/trial_task_center/test_application.py create mode 100644 tests/trial_task_center/test_batch.py create mode 100644 tests/trial_task_center/test_comparison.py create mode 100644 tests/trial_task_center/test_evidence.py create mode 100644 tests/trial_task_center/test_execution_safety.py create mode 100644 tests/trial_task_center/test_logging_setup.py create mode 100644 tests/trial_task_center/test_permanent_delete.py create mode 100644 tests/trial_task_center/test_quick_run.py create mode 100644 tests/trial_task_center/test_recovery.py create mode 100644 tests/trial_task_center/test_retention.py create mode 100644 tests/trial_task_center/test_runner.py create mode 100644 tests/trial_task_center/test_scanner.py create mode 100644 tests/trial_task_center/test_sceneos_cli.py create mode 100644 tests/trial_task_center/test_service.py create mode 100644 tests/trial_task_center/test_session_failure_messages.py create mode 100644 tests/trial_task_center/test_store.py create mode 100644 tests/trial_task_center/test_value_options.py create mode 100644 tests/trial_task_center/test_worker_monitor.py create mode 100644 tests/ui/test_execution_feedback.py create mode 100644 tests/ui/test_permanent_delete_ui.py create mode 100644 tests/ui/test_trial_task_center_window.py create mode 100644 tests/ui/test_trial_task_center_workflow.py create mode 100644 tests/ui/test_value_options_layout.py create mode 100644 tests/vbs/test_bridge_common.vbs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95b2658 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +/.venv/ +/.pytest_cache/ +/build/ +/dist/ +/data/ +/runs/ +__pycache__/ +*.py[cod] +*.db +*.db-* +*.sqlite* +*.log +*.jsonl +*.zip +*.rar +.coverage +coverage.xml diff --git a/docs/reviews/2026-09-06-code-review.md b/docs/reviews/2026-09-06-code-review.md new file mode 100644 index 0000000..5aef1a2 --- /dev/null +++ b/docs/reviews/2026-09-06-code-review.md @@ -0,0 +1,174 @@ +# DxDesigner 元件替换项目代码审查 + +审查日期:2026-09-06。基线:当前磁盘源码;目录没有 Git 元数据,不能绑定提交或推断修改历史。 + +## 结论 + +**不建议把当前版本用于唯一工程副本或无人值守批量替换。** 确认 10 项问题:5 项 P1、5 项 P2。主要风险不是代码风格,而是错误成功判定、错误上下文撤销、恢复约束丢失和执行重入。 + +采用 Superpowers 的 systematic-debugging、requesting-code-review、verification-before-completion 工作流:先理解功能,再检查具体调用链,以隔离复现和持久事件验证结论。审查不等于修复;本次没有修改业务源码。 + +## 1. 功能与实际执行路径 + +### 当前桌面主路径 + +PySide6 窗口管理任务、扫描并选择 `.prj` 工程、维护旧料号到新料号的规则。主按钮“自动替换并校验”调用 `TaskCenterService.execute_quick_run()`,生成共享 `quick-run` 目录中的 TSV 命令、状态和快照,调用 VBS,再由 Python helper 连接 DxDesigner、执行原生替换及引脚编号提升,最后由 VBS 恢复实例参数并检查当前图页结果。 + +入口:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:595`。 + +这条路径以**当前图页**为实际工作范围;不应把按钮显示的“队列完成”等同于全工程所有图页都完成替换、保存或通过外部电气检查。 + +### 仍保留的另外两条路径 + +- 人工证据任务流程:`TrialRunner` 管理 Capture Before、人工替换、Capture After 和 SQLite 状态,使用 `compare_profiles()`。当前主窗口没有把这些人工操作按钮放入主操作布局,但服务、测试及相关代码仍保留。 +- 原批处理 CLI:`BatchController` 管理不可变输入、完整库存、认证、关闭/备份/重开、逐规则替换、保存、外部检查以及 Undo/恢复。其安全检查**不会自动覆盖桌面 quick-run 路径**。 + +对应入口:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\runner.py:193`;`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\part_replace\controller.py:1511`。 + +### 文档边界 + +用户指南仍主要描述人工替换、不写 Value/样式的旧流程,当前 EXE 已走自动替换和参数恢复。不能据此假定自动路径继承了旧 CLI 的备份、认证和全项目校验保障。建议分别声明三条路径的范围、保存责任及失败处理,而不是共用一个安全承诺。本项作为发布说明缺口,不计入下列 10 项缺陷。 + +## 2. 已确认发现 + +### F01 · P1 · 回滚前未核对项目/图页,可能撤销其他工程的编辑 + +- 路径:当前桌面自动替换;类别:工程数据安全。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\integration\dxdesigner795\QuickPartReplace.vbs:156`。 +- 触发:替换或恢复期间切换活动项目/图页。恢复阶段在第 371 行检测到上下文不符后抛错,外层第 94 行进入回滚,但回滚函数先对当前应用发送 `undo`,随后才检查恢复结果。 +- 复现:使用项目 A 的快照、活动项目 B 的假应用,真实回滚函数输出 `ACTIVE_PROJECT=C:\UnrelatedB\b.prj`、`WRONG_CONTEXT_COMMAND=undo`,之后才输出 `replacement component not found`。 +- 影响:对 A 的失败处理可能先撤销 B 的合法编辑,且不能恢复 A。事后报错不能抵消已经发出的错误命令。 +- 修复:任何 Undo 前核对项目、图页和本次事务归属;上下文变化时只阻断,不向当前未知撤销栈发送命令。不能仅增加 Undo 后的检查。 +- 证据边界:真实函数和假应用验证了命令顺序,没有在真实 DxDesigner 中制造工程损坏。 + +### F02 · P1 · 只改料号、保留旧符号,也能被当成原生替换成功 + +- 路径:当前桌面自动替换的续跑分支;类别:功能正确性、库身份完整性。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\native_helper.py:162`;同文件第 121 行。 +- 触发:已有快照,元件 Part Number 已变为目标值,但 UID、旧 Part Name、旧 Part Label 和引脚仍保留。`source_uids != wanted` 分支只检查目标料号以及非空库身份字段,直接跳过目标库查找和原生替换。 +- 复现:真实 helper 返回 `exit=0`、`ok=True`、`stage=native_replace_verified`、`already_replaced=True`,而 Part Name 仍为 `OLD_SYMBOL`、Part Label 仍为 `OLD_LABEL`。独立的 VBS 假对象复现也写出 `restored_ok`。 +- 影响:产生“新料号+旧库身份”的假成功,而不是用户要求的库元件替换。 +- 修复:续跑必须验证与当前作业绑定的原生替换记录、目标中央库身份和符号/接口指纹;不能以目标料号存在推断已完成替换。 +- 证据边界:helper 与 VBS 分别进行了隔离函数测试,不宣称完成了真实软件端到端复现。 + +### F03 · P1 · 恢复库存不一致后,再次 Continue 会丢失恢复约束 + +- 路径:原批处理 CLI;类别:恢复安全、错误成功判定。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\part_replace\controller.py:2237`。 +- 触发:失败替换经 Undo 后 reconcile,带有可信 `expected_snapshot_path`;第一次新库存不符合该快照,被 `recovery_snapshot_mismatch` 阻断。再次运行 operator step 时,按最新 reconcile 切分周期,旧的 mutation/recovery 证据不再进入判断,于是生成不带可信快照的 `read_only_retry`。 +- 复现:先提交缺失元件的库存,第一次正确 blocked;再 Continue 并提交同一库存,最终 `complete=True`、状态 `verified_saved`。主线程从临时目录重新构造全流程复核,安全断言失败。 +- 影响:恢复校验可以被正常续跑操作降级掉;异常空库存甚至会借零匹配的 `no_changes_required` 直接成为成功。 +- 修复:恢复义务必须跨库存重试持续存在,直到可信快照真正通过核验;不能用“本周期没有写事件”推断整个作业从未写入。 + +### F04 · P1 · 执行中刷新任务会重新启用替换按钮,允许重入 + +- 路径:当前桌面自动替换;类别:并发安全、鲁棒性。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:390`。 +- 触发:后台 worker 正在运行,用户切换任务或重新加载任务数据。`_run_async()` 暂时禁用按钮,但 `_update_gates()` 只检查选择与队列状态,没有检查仍在执行的 worker,重新启用按钮。 +- 复现:用 Event 阻塞 worker,确认按钮已禁用;调用真实 `open_task()` 后按钮立即恢复 enabled,worker 尚未结束。 +- 影响:用户能够再次发起执行。服务层没有对应的执行互斥,两个执行会共用 `quick-run/command.tsv`、状态、快照和活动 DxDesigner;事后关联状态失败并不能预防前面的并发操作。 +- 修复:执行中保持全局操作占用,服务层加原子互斥/租约;支持多实例时还需跨进程锁。按钮禁用和结果 generation 检查不能代替执行锁。 +- 证据边界:已复现 UI 重入条件;没有对真实 DxDesigner 执行并发写入。 + +### F05 · P1 · 保护证据缺失或库存声明矛盾时,比较器仍放行 + +- 路径:保留的人工证据任务流程,不是当前 quick-run helper;类别:校验完整性。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\comparison.py:152`;同文件第 179、225 行。 +- 触发:接口标志仍为 available,但匹配元件 `pins=[]`、`units=0` 或 `net_identity=None`。空列表、零单元和未知网络身份均通过当前 schema 检查;前后相等后不再产生错误。 +- 复现:以上三个输入均返回 `passed=True, issues=[]`。额外两个用例中,`enumeration.available=False` 或声明 200 个元件却只有 2 条记录,也返回通过,因为枚举声明没有参与比较。 +- 影响:无法证明引脚、单元或连接安全的证据被作为成功依据。枚举矛盾用例证明输入校验缺口,不代表现有 probe 必然会生成这种矛盾文件。 +- 修复:对匹配的真实器件要求正单元数、非空引脚及明确网络/未连接状态,检查全项目枚举能力与记录数一致性;缺证据与“无变化”必须分开处理。 + +### F06 · P2 · 已保存的 before 哈希没有在最终比较前复核 + +- 路径:保留的人工证据任务流程;类别:本地证据完整性。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\runner.py:273`。 +- 触发:Capture Before 后、Capture After 前,已保存的 before 文件被改写。数据库虽保存 SHA-256,但最终读取只调用 `_load_profile(context.before_path)`;`_require_attempt()` 只要求哈希字段存在。 +- 复现:原 before 的引脚 x 为 0;捕获后把存档 before 的 x 改为 999,再输入同样 x=999 的 after。流程将项目标为 `completed`,没有发现存档内容已偏离捕获时哈希。 +- 影响:损坏、误编辑或被替换的本地证据可成为新的可信基线。这是本地完整性问题,不是远程攻击或权限提升结论。 +- 修复:对最终实际读取的字节重新计算大小和 SHA-256,与持久化记录匹配后再解析;项目身份、schema、duplicate key 校验也应复用捕获入口。 + +### F07 · P2 · 写 API 已执行,错误报告却仍为 preflight,跳过恢复 + +- 路径:当前桌面自动替换的续跑分支;类别:异常处理、工程安全。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\native_helper.py:164`。 +- 触发:already-replaced 分支调用 `PromoteSymbolNumbers(1,1)` 后,引脚枚举失败或为空。该分支在调用成功返回以后才设置 stage;失败报告因此仍保留初始 `preflight`。 +- 复现:假 Block 记录了 `promotions=[(1,1)]`,随后真实 helper 返回 `exit=1, stage=preflight, Replacement produced no pins`。 +- 影响:VBS 只把 `native_replace_started` / `native_replace_verified` 当作可能写入,故此失败路径漏掉恢复处理;这不是误报成功,而是已发出写操作后丢失了写入阶段信息。 +- 修复:任何写 API 前持久化“可能已写入”阶段;明确原生替换、引脚提升、参数恢复各阶段及对应恢复责任。 + +### F08 · P2 · 最后一条规则验证后中断,作业无法正常续跑到保存 + +- 路径:原批处理 CLI;类别:崩溃恢复。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\part_replace\controller.py:1777`。 +- 触发:`rule_verified` 已落盘,但迁移至 `AWAITING_SAVE_CONFIRMATION` 前异常退出。重开后状态仍为 applying,同时既没有 pending command,也没有剩余规则。 +- 复现:故障注入产生的持久事件以 `rule_verified / target_state=applying` 结束;主线程重新打开并调用 operator step,返回 `rule_order: project has no remaining replacement rule to prepare`。 +- 影响:已经验证成功的替换不能通过正常 Continue 进入保存;重新 verify 和 prepare-save 也不符合各自状态条件,需要额外恢复操作。 +- 修复:最终 rule_verified 应原子驱动待保存状态,或启动重放时能幂等补全该迁移。 + +### F09 · P2 · mailbox 已移动但归档事件未提交,中断后先检查旧路径导致续跑失败 + +- 路径:原批处理 CLI;类别:文件/事件一致性、崩溃恢复。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\part_replace\controller.py:1009`。 +- 触发:归档把 snapshot 移入 history 后、追加 `mailbox_outputs_archived` 前中断。重新 prepare Apply 先调用当前快照校验,仍使用缺失的原 mailbox 路径,尚未到可补全归档的代码。 +- 复现:故障目录中 history 已有快照而归档事件缺失;重开后 `prepare_apply()` 返回 `stale_project: current snapshot is unavailable`。 +- 影响:证据存在却无法通过正常重试恢复,已实现的部分归档续做逻辑不可达。 +- 修复:使用持久化归档意图和可重放的文件发布步骤,在解析当前快照来源前先恢复未完成归档;不能随意忽略 stale_project。 + +### F10 · P2 · 合法 Library Wins 引脚名变化被误判成保护字段变化 + +- 路径:保留的人工证据任务流程;类别:功能兼容性、误报。 +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\comparison.py:277`。 +- 触发:目标库只改变引脚显示名称,号码、位置、网络及其他保护字段不变。比较器将整个 pins 字典列表作为硬保护字段直接比较。 +- 复现:仅把 pin name 改为 `LIBRARY-RENAMED-PIN`,得到 `passed=False, pins_changed`。原核心 verifier 则在同类条件下记录非阻断的 `library_pin_name_changed`,与用户指南对库控制字段的说明一致。 +- 影响:有效替换被标记 Failed,两个校验实现的允许变化集合不一致。 +- 修复:按 pin number 对齐后逐个校验坐标、网络等硬保护字段;库控制名称变化单独报告,不把合法变化当作连接变化。 + +## 3. 验证结果与可复现附件 + +### 现有定向测试:216 passed + +在项目目录中执行,均为实际完成并取得退出码 0 的测试,不包含被中止的运行: + +```powershell +$env:QT_QPA_PLATFORM='offscreen' +.\.venv\Scripts\python.exe -m pytest tests/trial_task_center tests/part_replace/test_verification.py tests/part_replace/test_inputs.py tests/part_replace/test_protocol.py tests/part_replace/test_models.py tests/part_replace/test_reports.py -q --tb=short +# 192 passed in 25.53s +.\.venv\Scripts\python.exe -m pytest tests/integration/test_automatic_replacement_regression.py tests/integration/test_quick_part_replace_contract.py -q --tb=short +# 24 passed in 1.08s +``` + +### 审查复现:12 个安全预期断言失败 + +这些文件故意断言“正确安全行为”,因此当前实现应显示失败;失败是缺陷证据,不是已修复或测试通过。三个附件最后合并运行结果为 `12 failed in 19.76s`,全部是预期行为断言失败,没有 fixture 初始化错误。附件放在 docs/reviews,而非默认 tests 收集目录,未改变正常测试发现配置。 + +- `F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\docs\reviews\2026-09-06-review-repros.py:1`:8 failed,覆盖 F04、F05、F06、F10。 +- `F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\docs\reviews\2026-09-06-native-repros.py:1`:3 failed,覆盖 F01、F02 的 helper 分支、F07;Win32/UI 均为桩,VBS 排除了自动连接应用的顶层启动代码。 +- `F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\docs\reviews\2026-09-06-controller-repros.py:1`:1 failed,用现有 fixture 在临时目录从头复现 F03。 + +```powershell +$env:QT_QPA_PLATFORM='offscreen' +.\.venv\Scripts\python.exe -m pytest docs/reviews/2026-09-06-review-repros.py docs/reviews/2026-09-06-native-repros.py docs/reviews/2026-09-06-controller-repros.py -q --tb=short +``` + +F08/F09 的故障注入持久证据位于以下临时目录;本次已重新打开验证相应错误。临时文件可能被系统清理,不能当作永久交付存储: + +- `C:\Users\ABS_Windows\AppData\Local\Temp\dx-controller-readonly-audit-fafuffpn\last-rule-transition\run\events.jsonl:1` +- `C:\Users\ABS_Windows\AppData\Local\Temp\dx-controller-readonly-audit-fafuffpn\archive-before-event\run\events.jsonl:1` + +### 全量测试不能宣称通过 + +初始收集范围有 587 项测试;完整运行没有完成。UI 的现有测试仍模拟旧的 `awaiting_native_replace` 两步协议,但当前 execute_step 要求 `restored_ok`。产生异常后,可见窗口的 `_show_error()` 进入 `QMessageBox.exec()`,无人点击使测试卡住。 + +单测定位:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\tests\ui\test_trial_task_center_workflow.py:113`。使用 `-o faulthandler_timeout=8` 得到主线程堆栈停在 `F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:792`。已停止本次卡住/过慢的测试进程,不把部分进度计为通过。应更新测试协议,并给错误对话框提供自动化处理机制。 + +## 4. 修复顺序与边界 + +1. 首先处理 F01/F02/F03:错误上下文 Undo、原生替换假成功和恢复约束降级。 +2. 给 quick-run 增加服务级互斥,先防止并发写入,再修复 F07 的写入阶段记录。 +3. 统一证据解析与校验策略,处理 F05/F06/F10,避免三条路径各自实现不同安全标准。 +4. 为 F08/F09 增加每个持久化边界的中断恢复测试,最后更新 UI 测试和用户指南。 + +已有正面基础包括规则链/环校验、核心完整快照比较、命令关联、部分原子发布和备份校验;216 项定向测试通过能证明这些被覆盖的场景可工作,不能抵消本报告的反例。 + +本次未连接或操作真实 DxDesigner,未修改设计、未安装组件、未修改用户环境变量、未重新打包 EXE;仅新增审查文档和隔离复现代码。真实多图页/多门器件传播、原生 Undo 栈粒度、中央库现场行为及打包产物与源码一致性仍需可丢弃副本上的专项验收。本报告不是对产品无其他漏洞的保证,也不声称发现远程代码执行或网络攻击入口。 diff --git a/docs/reviews/2026-09-06-controller-repros.py b/docs/reviews/2026-09-06-controller-repros.py new file mode 100644 index 0000000..822cd62 --- /dev/null +++ b/docs/reviews/2026-09-06-controller-repros.py @@ -0,0 +1,43 @@ +from __future__ import annotations + +from dataclasses import replace +from pathlib import Path +import runpy + +import pytest + + +ROOT = Path(__file__).resolve().parents[2] + + +def test_recovery_constraint_survives_failed_inventory_retry(tmp_path: Path) -> None: + helpers = runpy.run_path(str(ROOT / "tests" / "part_replace" / "test_controller.py")) + controller, markers, certification_path = helpers["_create_controller"](tmp_path) + project_id = controller.projects[0].project_id + inventory, _ = helpers["_ingest"](controller, tmp_path, project_id, markers[0]) + helpers["_certify"](certification_path, inventory) + helpers["_ready_for_apply"](controller, project_id, inventory) + command = controller.prepare_apply(project_id, 0) + helpers["_publish_bridge_snapshot"]( + controller, + command, + "applied", + helpers["_snapshot"](project_id, markers[0], "WRONG-1", "unsafe", symbol="LIB:NEW"), + ) + assert not controller.verify_apply(project_id, 0).passed + undo = controller.prepare_undo(project_id) + helpers["_publish_bridge_snapshot"]( + controller, undo, "undo_verified", inventory, status_command=command + ) + controller.confirm_undo(project_id) + controller.reconcile(project_id) + command = controller.prepare_inventory(project_id) + wrong_inventory = replace(inventory, components=()) + helpers["_publish_bridge_snapshot"](controller, command, "inventory_exported", wrong_inventory) + with pytest.raises(helpers["ControllerError"], match="recovery_snapshot_mismatch"): + controller.ingest_inventory(project_id) + controller = helpers["BatchController"].open(controller.root) + step = controller.operator_step() + helpers["_publish_bridge_snapshot"](controller, step.command, "inventory_exported", wrong_inventory) + step = controller.operator_step() + assert not step.complete, "previously rejected inventory became verified_saved after Continue" diff --git a/docs/reviews/2026-09-06-native-repros.py b/docs/reviews/2026-09-06-native-repros.py new file mode 100644 index 0000000..a76e131 --- /dev/null +++ b/docs/reviews/2026-09-06-native-repros.py @@ -0,0 +1,114 @@ +from __future__ import annotations + +import json +from pathlib import Path +import subprocess +import sys +from types import ModuleType, SimpleNamespace + +import pytest + +from dx_productivity.trial_task_center import native_helper + + +ROOT = Path(__file__).resolve().parents[2] + + +class OriginalComponent: + UID = "original-uid" + Refdes = "R1" + + def FindAttribute(self, name): + value = {"Part Number": "NEW", "Part Name": "OLD_SYMBOL", "Part Label": "OLD_LABEL"}[name] + return SimpleNamespace(InstanceValue=value, Value=value) + + +@pytest.mark.parametrize("has_pins", (True, False)) +def test_resume_does_not_infer_native_replacement_from_part_number(monkeypatch, tmp_path: Path, has_pins: bool) -> None: + modules = {name: ModuleType(name) for name in ("win32api", "win32con", "win32gui", "win32process", "pywinauto")} + modules["pywinauto"].Desktop = object + for name, module in modules.items(): + monkeypatch.setitem(sys.modules, name, module) + component = OriginalComponent() + promotions = [] + pin = SimpleNamespace(Component=component, Number="1") + pin._oleobj_ = pin + view = SimpleNamespace( + GetName=lambda flag: "A", + Block=SimpleNamespace(SheetNum=1, PromoteSymbolNumbers=lambda *args: promotions.append(args)), + Query=lambda *args: [pin] if has_pins else [], + ) + app = SimpleNamespace( + ActiveView=view, + GetProjectData=lambda: SimpleNamespace(GetProjectFilePath=lambda: r"C:\DisposableA\a.prj"), + ) + snapshot = tmp_path / "snapshot.tsv" + snapshot.write_text( + "M\tC:\\DisposableA\\a.prj\tOLD\tNEW\tA:1\n" + "C\toriginal-uid\tR1\t0\t0\t0\t1\tnet\n", + encoding="utf-8", + ) + monkeypatch.setattr(native_helper, "attach", lambda: (app, SimpleNamespace(IVdCmpPin=lambda value: value))) + monkeypatch.setattr(native_helper, "components_on_sheet", lambda *args: [component]) + monkeypatch.setattr(native_helper, "selection", lambda *args: None) + exit_code = native_helper.run(snapshot) + report = json.loads(Path(str(snapshot) + ".native.json").read_text(encoding="utf-8")) + if has_pins: + assert exit_code != 0, f"old library identity accepted: {report}" + else: + assert promotions == [(1, 1)] + assert exit_code != 0 + assert report["stage"] != "preflight", f"write API called but mutation state lost: {report}" + + +def test_native_rollback_rejects_wrong_project_before_undo(tmp_path: Path) -> None: + source = (ROOT / "integration" / "dxdesigner795" / "QuickPartReplace.vbs").read_text(encoding="ascii") + declarations = source[:source.index("Set QP_Fso =")] + routines = source[source.index("Sub QPMain()") :] + snapshot = tmp_path / "snapshot.tsv" + snapshot.write_text( + "M\tC:\\DisposableA\\a.prj\tOLD\tNEW\tA:1\n" + "C\told-uid\tR1\t0\t0\t0\t1\tnet\n" + "A\told-uid\tPart Number\tOLD\t\t0\t0\t0\t0\t10\t0\t1\n", + encoding="utf-8", + ) + body = r''' +Set QP_Fso = CreateObject("Scripting.FileSystemObject") +Set QP_App = New WrongProjectApp +WScript.Echo "ACTIVE_PROJECT=" & QPProjectPath() +On Error Resume Next +QPRollbackNativeReplacement "SNAPSHOT" +WScript.Echo "ERROR_AFTER_UNDO=" & Err.Description +Err.Clear +On Error GoTo 0 +WScript.Quit 0 +Class WrongProjectApp + Public Function ExecuteCommand(ByVal Command) + WScript.Echo "WRONG_CONTEXT_COMMAND=" & Command + ExecuteCommand = True + End Function + Public Function GetProjectData() + Set GetProjectData = Me + End Function + Public Function GetProjectFilePath() + GetProjectFilePath = "C:\UnrelatedB\b.prj" + End Function + Public Property Get ActiveView + Set ActiveView = Me + End Property + Public Function Query(ByVal Flags, ByVal Selected) + Set Query = CreateObject("Scripting.Dictionary") + End Function +End Class +'''.replace("SNAPSHOT", str(snapshot)) + wrapper = tmp_path / "isolated-rollback.vbs" + wrapper.write_text(declarations + body + routines, encoding="ascii") + completed = subprocess.run( + ["cscript.exe", "//nologo", str(wrapper)], + capture_output=True, + text=True, + timeout=15, + creationflags=subprocess.CREATE_NO_WINDOW, + ) + assert completed.returncode == 0, completed.stderr + assert "WRONG_CONTEXT_COMMAND=undo" not in completed.stdout, completed.stdout diff --git a/docs/reviews/2026-09-06-remediation.md b/docs/reviews/2026-09-06-remediation.md new file mode 100644 index 0000000..cd2d266 --- /dev/null +++ b/docs/reviews/2026-09-06-remediation.md @@ -0,0 +1,49 @@ +# 2026-09-06 审查整改记录 + +整改范围:`2026-09-06-code-review.md` 的 F01-F10,以及 `2026-09-06-ui-review.md` 的 U01-U05、V01-V04。整改采用 Superpowers 的 receiving-code-review、systematic-debugging、test-driven-development 和 verification-before-completion 流程。 + +## 代码审查项 + +- F01:所有 Undo 前核对作业、工程、图页和事务归属;上下文变化时阻断,不向未知撤销栈发送命令。 +- F02/F07:原生替换与目标库行、符号、快照哈希和作业绑定;任何写 API 前持久化 mutation stage,失败后不丢失恢复责任。 +- F03:恢复快照义务跨重试保留,直到可信库存真正匹配。 +- F04:GUI worker generation、进程内锁和跨进程文件锁共同阻止重复 quick-run;执行期间删除及输入修改也由服务层阻断。 +- F05/F10:完整项目枚举、单元、引脚和网络证据成为硬门禁;Library Wins 引脚名称变化单独作为非阻断警告。 +- F06:最终比较前重新读取 before 原始字节并复核大小、SHA-256、JSON/schema 和项目身份。 +- F08:最后规则验证与待保存状态原子提交,并兼容修复旧日志中断状态。 +- F09:mailbox 部分归档可重放,同时保留旧工程 stale 检查顺序。 + +## UI 审查项 + +- U01:quick-run 执行期间禁用删除、扫描、工程选择和规则修改;服务层锁可阻止直接调用及其他进程实例绕过 UI。 +- U02:从关联的 command/status 文件重建并持久化队列进度;项目和任务最终进入 Completed。界面明确该状态只代表所选工程的当前图页规则队列,不代表全工程、保存或外部检查完成。 +- U03:证据按钮指向任务绑定的真实 `quick-run` 输出;后续队列归档后仍可从 `quick-run-history` 定位旧任务证据。 +- U04:规则表“启用”列改为可操作复选框,编辑对话框也可启用或停用规则;执行中统一锁定。 +- U05:错误提示保留具体底层原因、当前工程/规则、写入不确定性和稳定错误编号;`quick_run_complete` 使用普通完成提示,不再显示失败弹窗。 +- V01-V03:自动替换按钮成为主操作,删除操作使用危险语义;增加真实队列计数、当前项、忙碌指示和运行时长,左侧操作改为紧凑两列布局。 +- V04:窗口最小尺寸由 1100x700 调整为 900x600;工程、规则和执行区域继续使用可拖动 QSplitter,表格列保持 Interactive,并用滚动处理小窗口内容。 + +## 验证结果 + +```text +原代码审查复现 + 新 UI 审查复现 + 任务中心/UI 定向回归:154 passed +最终完整 pytest:937 passed in 1889.45s +打包专项测试:7 passed +PyInstaller:构建成功,Python 3.12.13 +源码与打包 QuickPartReplace.vbs:SHA-256 一致 +dist EXE 冒烟:通过 +部署目录 EXE 冒烟:ExitCode=0,application_start/clean_shutdown 均存在 +900x600 离屏渲染:无控件重叠,分隔区和表格滚动正常 +``` + +部署位置:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-Test`。 + +部署 EXE SHA-256:`1F682EB83E2F5DD723CD36361F7F552129BF15D98949F40311FD8D37CCEAC38D`。 + +部署 VBS SHA-256:`B7A3FE65D275462F8CB2F0E68447797F6959F2174D8723A6792FBDCE0B82BD04`。 + +旧部署备份:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-Test.backup-20260906-130722`。 + +## 现场验证边界 + +本机没有目标中央库,因此本次没有宣称真实库元件替换或现场端到端验收完成。当前结果证明代码复现、自动化回归、构建、部署和应用启动链路通过;真实 DxDesigner 联调仍需在连接正确中央库的可丢弃完整工程副本上执行,并由操作员审阅后决定是否保存。 diff --git a/docs/reviews/2026-09-06-review-repros.py b/docs/reviews/2026-09-06-review-repros.py new file mode 100644 index 0000000..660f2a7 --- /dev/null +++ b/docs/reviews/2026-09-06-review-repros.py @@ -0,0 +1,133 @@ +from __future__ import annotations + +import json +from pathlib import Path +import runpy +from threading import Event + +import pytest + +from dx_productivity.part_replace.models import MappingRule +from dx_productivity.trial_task_center.comparison import compare_profiles + + +ROOT = Path(__file__).resolve().parents[2] +FIXTURES = ROOT / "tests" / "fixtures" / "trial_task_center" + + +def profile(name: str) -> dict: + return json.loads((FIXTURES / name).read_text(encoding="utf-8")) + + +@pytest.mark.parametrize("missing", ("pins", "units", "net_identity")) +def test_comparison_requires_observed_connectivity(missing: str) -> None: + before = profile("profile-before.json") + after = profile("profile-after-valid.json") + for snapshot in (before, after): + component = snapshot["components"][0] + if missing == "pins": + component["pins"] = [] + component["nets"] = [] + elif missing == "units": + component["units"] = 0 + else: + component["pins"][0]["net_identity"] = None + component["nets"] = [] + result = compare_profiles(before, after, (MappingRule("OLD-1", "NEW-1"),)) + assert not result.passed, f"missing {missing} unexpectedly passed: {result.to_json()}" + + +def test_library_wins_pin_name_change_is_not_connectivity_change() -> None: + before = profile("profile-before.json") + after = profile("profile-after-valid.json") + after["components"][0]["pins"][0]["name"] = "LIBRARY-RENAMED-PIN" + result = compare_profiles(before, after, (MappingRule("OLD-1", "NEW-1"),)) + assert result.passed, result.to_json() + + +def test_incomplete_enumeration_cannot_pass() -> None: + before = profile("profile-before.json") + after = profile("profile-after-valid.json") + for snapshot in (before, after): + snapshot["enumeration"] = { + "available": False, + "component_count": 200, + "route": "Application.DesignComponents", + } + result = compare_profiles(before, after, (MappingRule("OLD-1", "NEW-1"),)) + assert not result.passed, result.to_json() + + +def test_component_count_mismatch_cannot_pass() -> None: + before = profile("profile-before.json") + after = profile("profile-after-valid.json") + for snapshot in (before, after): + snapshot["enumeration"] = { + "available": True, + "component_count": 200, + "route": "Application.DesignComponents", + } + result = compare_profiles(before, after, (MappingRule("OLD-1", "NEW-1"),)) + assert not result.passed, result.to_json() + + +def test_saved_before_hash_is_rechecked_before_completion(tmp_path: Path) -> None: + helpers = runpy.run_path(str(ROOT / "tests" / "trial_task_center" / "test_runner.py")) + runner, store, task_id, project_ids, probe = helpers["_runner_with_probe_source"](tmp_path) + project_id = project_ids[0] + project_path = store.list_projects(task_id)[0].path + try: + runner.start_task(task_id, disposable_copy_confirmed=True) + helpers["_write_profile"]("profile-before.json", probe, project_path) + runner.capture_before(task_id, project_id, probe) + context = store.current_attempt(project_id) + altered = json.loads(context.before_path.read_text(encoding="utf-8")) + altered["components"][0]["pins"][0]["x"] = 999 + context.before_path.write_text(json.dumps(altered), encoding="utf-8") + helpers["_write_profile"]("profile-after-valid.json", probe, project_path) + after = json.loads(probe.read_text(encoding="utf-8")) + after["components"][0]["pins"][0]["x"] = 999 + probe.write_text(json.dumps(after), encoding="utf-8") + with pytest.raises(Exception, match="evidence_integrity"): + runner.capture_after(task_id, project_id, probe) + assert store.list_projects(task_id)[0].status.value == "failed" + finally: + store.close() + + +def test_busy_quick_run_stays_disabled_when_task_is_reopened(qtbot, tmp_path: Path) -> None: + from dx_productivity.trial_task_center.logging_setup import configure_logging + from dx_productivity.trial_task_center.service import TaskCenterService + from dx_productivity.trial_task_center.store import TaskStore + from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow + + store = TaskStore(tmp_path / "task-center.db") + service = TaskCenterService(store, configure_logging(tmp_path / "storage")) + task = service.create_task("Audit fixture") + project_root = tmp_path / "projects" + project_root.mkdir() + (project_root / "test.prj").touch() + project = service.scan_projects(task.task_id, project_root)[0] + service.set_project_selected(project.project_id, True) + service.add_rule(task.task_id, "OLD-1", "NEW-1") + window = TrialTaskCenterWindow(service) + qtbot.addWidget(window) + window.open_task(task.task_id) + started = Event() + release = Event() + + def blocked_worker() -> None: + started.set() + release.wait(5) + + try: + window._run_async(blocked_worker, lambda _result: None, window.run_panel.quick_run_button) + qtbot.waitUntil(started.is_set, timeout=2000) + assert not window.run_panel.quick_run_button.isEnabled() + window.open_task(task.task_id) + assert not window.run_panel.quick_run_button.isEnabled(), "task refresh reenabled an executing mutation" + finally: + release.set() + qtbot.waitUntil(lambda: not window._workers, timeout=3000) + window.close() + store.close() diff --git a/docs/reviews/2026-09-06-ui-repros.py b/docs/reviews/2026-09-06-ui-repros.py new file mode 100644 index 0000000..a7a53dc --- /dev/null +++ b/docs/reviews/2026-09-06-ui-repros.py @@ -0,0 +1,108 @@ +from __future__ import annotations + +from pathlib import Path +import subprocess +from threading import Event + +from dx_productivity.trial_task_center.logging_setup import configure_logging +from dx_productivity.trial_task_center.models import ProjectStatus, TaskStatus +from dx_productivity.trial_task_center.quick_run import QuickRunPreparer +from dx_productivity.trial_task_center.service import TaskCenterService +from dx_productivity.trial_task_center.store import TaskStore +from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow + + +def setup_window(qtbot, root: Path, started: Event | None = None, release: Event | None = None): + storage = root / "storage" + projects = root / "projects" + projects.mkdir() + (projects / "board.prj").touch() + + def fake_worker(command, timeout): + if started is not None: + started.set() + if release is not None: + assert release.wait(5) + handoff = storage / "quick-run" + job_id = (handoff / "command.tsv").read_text(encoding="utf-8").splitlines()[1].split("\t")[1] + with (handoff / "status.tsv").open("a", encoding="utf-8") as status: + status.write(f"{job_id}\tawaiting_native_replace\t\tFixture selection\n") + status.write(f"{job_id}\trestored_ok\t\tFixture completion\n") + return subprocess.CompletedProcess(command, 0, "", "") + + store = TaskStore(storage / "task-center.db") + service = TaskCenterService( + store, + configure_logging(storage), + path_opener=lambda path: None, + quick_run_preparer=QuickRunPreparer( + storage, + process_runner=fake_worker, + cscript_resolver=lambda: Path("unused-cscript.exe"), + ), + ) + task = service.create_task("UI fixture") + project = service.scan_projects(task.task_id, projects)[0] + service.set_project_selected(project.project_id, True) + service.add_rule(task.task_id, "OLD", "NEW") + window = TrialTaskCenterWindow(service, quick_run_confirmer=lambda *args: True) + qtbot.addWidget(window) + window.open_task(task.task_id) + return window, service, store, task, project + + +def finish_fixture(window, service, task): + result = service.execute_quick_run(task.task_id) + assert result.state == "restored_ok" and result.next_project_path is None + window._show_quick_run_result(result) + window._update_gates() + return result + + +def test_success_updates_project_and_task_state(qtbot, tmp_path: Path) -> None: + window, service, store, task, project = setup_window(qtbot, tmp_path) + try: + finish_fixture(window, service, task) + assert service.projects(task.task_id)[0].status is ProjectStatus.COMPLETED + assert service.get_task(task.task_id).status is TaskStatus.COMPLETED + finally: + window.close() + store.close() + + +def test_success_enables_evidence_button(qtbot, tmp_path: Path) -> None: + window, service, store, task, project = setup_window(qtbot, tmp_path) + try: + finish_fixture(window, service, task) + assert window.run_panel.open_evidence_button.isEnabled() + finally: + window.close() + store.close() + + +def test_evidence_action_opens_current_execution_outputs(qtbot, tmp_path: Path) -> None: + window, service, store, task, project = setup_window(qtbot, tmp_path) + try: + result = finish_fixture(window, service, task) + opened = service.open_evidence(task.task_id, project.project_id) + assert opened.resolve() == result.status_path.parent.resolve() + finally: + window.close() + store.close() + + +def test_deletion_is_blocked_while_quick_run_executes(qtbot, tmp_path: Path) -> None: + started = Event() + release = Event() + window, service, store, task, project = setup_window(qtbot, tmp_path, started, release) + try: + window._prepare_quick_run() + qtbot.waitUntil(started.is_set, timeout=2000) + assert window._workers + window._delete_task() + assert service.get_task(task.task_id).status is not TaskStatus.DELETED + finally: + release.set() + qtbot.waitUntil(lambda: not window._workers, timeout=3000) + window.close() + store.close() diff --git a/docs/reviews/2026-09-06-ui-review.md b/docs/reviews/2026-09-06-ui-review.md new file mode 100644 index 0000000..ab55e99 --- /dev/null +++ b/docs/reviews/2026-09-06-ui-review.md @@ -0,0 +1,120 @@ +# UI 专项审查:DxDesigner 器件批量替换任务中心 + +日期:2026-09-06。审查当前源码中的实际 PySide6 窗口,而非仅评价样式表。用临时工程、SQLite 数据库和模拟成功的 worker 渲染界面;没有连接 DxDesigner。 + +## 结论 + +UI 最大的问题是**自动执行流程与旧任务中心的状态、权限、证据入口没有统一**,并非单纯“不够美观”。确认 5 类功能/交互问题,其中执行重入是上一份报告已记录的问题;另有 4 类视觉与可用性改进点。以下不把外观偏好等同于代码漏洞。 + +## 一、功能与交互缺陷 + +### U01 · P1 · 执行期间的操作保护不完整 + +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:390`。 +- 原已复现:后台 worker 未结束时重新打开任务,替换按钮被 `_update_gates()` 重新启用,允许重复发起执行。 +- 新增复现:后台 worker 被 Event 阻塞时,调用界面的删除操作,任务从 draft 变为 deleted,而 worker 仍继续执行。位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:457`。 +- 原因:quick-run 没有将任务置为运行中,数据库的“禁止删除运行中任务”规则没有生效;按钮状态也没有统一绑定真实执行占用。删除不会取消 worker,切换任务后其结果还可能因上下文检查而不再呈现在当前界面。 +- 建议:执行生命周期由服务层统一管理;执行中锁住重复启动、删除及会改变执行输入的操作。切换查看别的任务可以允许,但必须始终保留当前活动作业的状态入口。安全取消需要有明确恢复语义,不能简单杀进程。 + +### U02 · P2 · 成功提示与工程、任务状态相互矛盾 + +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:610`;`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\service.py:228`。 +- 复现:让真实 execute_quick_run 消费模拟的有效 `awaiting_native_replace → restored_ok` 状态,所有规则均完成。实际输出:`result=restored_ok`、`next=None`,但 `task=draft`、`project=pending`。 +- 窗口底部写“当前队列已完成”,工程表仍写“待处理”,左侧仍在“进行中”;重新加载也不能凭空补上未持久化的完成状态。“已完成”筛选因此无法展示这些自动完成的任务/工程。 +- 建议:统一队列、工程和任务的状态来源,并且区分“当前图页校验完成”“整个工程完成”“保存完成”;不能只把按钮改成完成文案。 + +### U03 · P2 · 证据按钮不可用,诊断入口还会打开旧流程的空目录 + +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:400`;`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\service.py:290`。 +- 复现一:成功完成快速替换后,“打开证据目录”按钮仍为 disabled。它依赖人工 TrialRunner 的 active_project,而 quick-run 不产生该记录。 +- 复现二:直接调用与诊断按钮相同的 open_evidence 服务,打开的是 `tasks//evidence//attempt-1`,当前执行的 TSV、快照和 native 报告却在 `quick-run`。服务还会创建那个旧流程目录,让用户看到一个存在但没有当前证据的文件夹。 +- 建议:证据入口绑定具体 execution/run ID 及真实输出路径;成功、失败、状态不确定三种结果都应能打开对应证据,而不是依赖“当前活动项目”。 + +### U04 · P2 · “启用”列只有展示,没有启用/禁用规则的操作入口 + +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\mapping_table.py:30`;`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:552`。 +- 静态确认:表格设为 NoEditTriggers,“启用”列只是“是/否”文本。编辑对话框只有旧料号、新料号,提交时继续传入原来的 `enabled=rule.enabled`。 +- 影响:用户无法临时停用某条规则,只能删除或在界面外修改数据;已有 disabled 规则也不能从界面重新启用。 +- 建议:启用列提供复选框或在编辑对话框提供开关,调用已有 service.update_rule;执行中统一锁定。 + +### U05 · P2 · 错误反馈丢失具体原因,把不同故障统一描述为连接问题 + +- 位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:778`。 +- 静态确认:界面仅按 error.code 显示 ERROR_TEXT 和错误编号,不显示 stable_error.message。不同 quick_run_execution 原因会被统一引导为“确认已打开正确工程和图页”;quick_run_uncertain 还固定描述为“执行超时”,但该错误也可来自状态无法关联或状态文件损坏。 +- 影响:用户看不到目标库不匹配、校验失败等具体原因,容易按错误方向重复操作;与 U03 的证据入口问题叠加后,诊断链路更差。 +- 建议:保留简短中文结论,另提供可展开的具体原因、当前工程/规则、是否已写入和下一步;显示经过适当处理的错误细节,不把所有错误文本原样塞进主提示条。 + +## 二、视觉与可用性问题 + +### V01 · 主操作缺少视觉层级 + +`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\styles.py:10` 把蓝色主按钮样式绑定给旧的 startTaskButton,当前真正显示的 quickRunButton 没有对应样式,因此与“添加、编辑、删除”等普通按钮同级。 + +建议:将“自动替换并校验”设为明确主操作;把危险的删除操作和辅助操作区分开。不能仅靠颜色表达是否可执行,还要有状态文案。 + +### V02 · 缺少执行进度及运行中反馈 + +当前快跑操作在后台执行,但窗口没有对应的阶段显示、运行时长或队列进度;主要即时变化是按钮被禁用。成功、普通指导和错误也共用黄色提示带,缺少明确的语义区分。 + +建议:显示“工程 1/3、规则 2/5、当前阶段、耗时”,执行期间提供忙碌标识;结果摘要分别显示完成、失败、待人工确认。阶段进度需要真实事件支持,不应伪造百分比。 + +### V03 · 信息布局偏重空表格,缺少工程任务摘要 + +1280×800 的隔离渲染中,左侧任务列占据较大宽度且底部横排四个按钮;右侧两个表格保留大量空白,却没有清楚的“已选工程数、启用规则数、当前执行对象、上次执行结果”汇总。成功信息在提示条与日志区域重复,工程状态却没有同步。 + +建议:压缩左侧工具栏,把操作摘要放到执行区附近;明确“配置输入 → 执行确认 → 结果检查”的阅读顺序。日志作为可展开诊断区域,不承担唯一的结果展示职责。 + +### V04 · 小可用桌面和高缩放场景存在适配风险 + +位置:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:156`,窗口硬性最小尺寸为 1100×700。可用逻辑桌面低于该尺寸时,窗口无法缩小适配;例如某些低分辨率叠加系统缩放的环境。 + +这是根据固定最小尺寸推导的兼容性风险,本次没有改变用户显示缩放进行现场验证。建议做紧凑布局、可折叠导航和滚动兜底,并分别测试常用可用逻辑分辨率;不要只降低字体来强行塞入。 + +## 三、验证记录 + +新增附件:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\docs\reviews\2026-09-06-ui-repros.py:1`。 + +```powershell +$env:QT_QPA_PLATFORM='offscreen' +.\.venv\Scripts\python.exe -m pytest docs/reviews/2026-09-06-ui-repros.py -q --tb=short +``` + +实际结果:`4 failed in 0.96s`。分别在“成功后应更新状态”“证据按钮应可用”“证据入口应打开当前输出”“执行中应阻止删除”四个业务断言处失败;没有连接真实 DxDesigner,未修改业务代码。U01 的按钮重入复现沿用上一份审查附件;U04/U05 为完整 UI 调用路径的静态确认。 + +模拟成功后的界面截图: + +![隔离数据模拟成功后的实际PySide6窗口,底部完成提示与上方待处理状态矛盾](C:/Users/ABS_Windows/.codex/visualizations/2026/09/06/01a07479-a905-7cd3-bb57-5f99b03d06fb/ui-review-completed.png) + +截图使用临时演示数据和模拟 worker,不是实际工程替换完成的证明。建议先修复 U01–U03 的流程与状态,再补齐 U04/U05,最后进行视觉优化。 + +## 四、补充复核:功能完整性、美观度与错误警告 + +本节重新读取了当前源码。main_window.py 和 service.py 已出现新增的 busy gate / quick-run lease 实现,因此前文 U01 的执行重入结论属于此前审查基线,不能不经复测直接认定最新源码仍未修复。本轮不改动这些新实现,仅核对当前提示逻辑。 + +### 实际验证的六种提示偏差 + +使用隔离 service 产生真实重复规则、规则链和任务重名错误;另外向真实隐藏窗口注入三类 TaskCenterError,以验证错误呈现函数。窗口未显示,未进入模态事件循环,也没有连接 DxDesigner。验证命令正常退出。 + +| 实际错误/状态 | 当前 UI 文案 | 更准确的处理 | +| --- | --- | --- | +| 重复旧料号 | 操作失败:操作未完成,请查看日志了解详细原因。 | 在规则输入处指出具体旧料号已经存在,保留输入便于修改 | +| A→B、B→C 的规则链 | 同上 | 说明目标料号同时被用作其他规则的来源,指出冲突规则 | +| 任务重名 | 同上 | 在任务名称输入框旁提示名称已存在 | +| quick_run_uncertain:状态无法关联,而非超时 | 操作失败:替换执行超时,工程状态不确定。请人工核对后再继续。 | 表达“无法确认本次结果”,明确可能已修改,不伪称超时 | +| quick_run_execution:底层报告具体目标库错误 | 统一提示确认正确工程和图页 | 展示具体错误类别及详情,不误导用户反复打开工程 | +| quick_run_complete:全部规则已完成 | 操作失败:当前任务中的替换规则已经全部完成。 | 用普通完成/无须重复执行提示,而不是失败弹窗 | + +原因位于 `F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\src\dx_productivity\trial_task_center\ui\main_window.py:785`:所有 TaskCenterError 共用失败前缀和 Critical 弹窗,只按 code 查固定文案,且丢弃具体 message。quick_run_uncertain 本身包含多种根因,不宜统一翻译为超时。 + +### 还需要修正的安全提示 + +- “请人工核对后再继续”没有对应的验证恢复流程。uncertain.flag 存在时后台仍会拒绝执行;用户仅核对界面并不能解除状态。应提供带证据和状态核验的恢复步骤,不能通过直接删除 flag 或普通“继续”绕过保护。 +- 当前自动替换确认框只显示已选工程数、规则数和“打开正确工程/图页”,没有展示这次即将执行的准确工程、图页、旧料号→新料号和命中数量,也未明确要求使用可恢复副本。 +- 最终“连接校验均已完成”没有解释当前图页的范围,也没有区分当前图页、全工程、保存和外部检查。应只声明实际执行并验证的范围,避免把局部成功理解为整项目验收完成。 + +### 产品完整性与视觉建议 + +- 执行前提供只读匹配预览;执行中提供真实阶段、队列进度和当前对象;结束后提供成功/失败/未匹配的结构化结果及证据入口。 +- 批量规则维护可以增加导入、导出、搜索和筛选;这些是新增产品能力建议,并非已承诺但失效的代码功能。 +- 视觉层级采用“当前任务摘要 → 工程与规则配置 → 执行及结果”,主操作显著,日志折叠;成功、警告、失败、状态不确定使用不同语义及文字,不只更换颜色。 +- 表单输入错误优先内联;普通完成状态不弹失败框;只有涉及可能写入、恢复或数据损失的情况才使用阻断性警告。 diff --git a/docs/reviews/2026-09-07-r11-gui-acceptance.md b/docs/reviews/2026-09-07-r11-gui-acceptance.md new file mode 100644 index 0000000..fdba8df --- /dev/null +++ b/docs/reviews/2026-09-07-r11-gui-acceptance.md @@ -0,0 +1,48 @@ +# R11 实际 EXE 验收及功能修复 + +## 验收边界 + +通过 Explorer 实际双击候选 EXE 快捷方式,使用独立数据目录和可丢弃工程副本完成界面操作。没有使用服务层调用替代任务创建、规则编辑、执行确认、暂停恢复或错误对话框操作。SQLite 仅作只读断言;保存后的 CAD 读回用于独立验证,不替代实际 EXE 执行。 + +## 实际验证 + +| 场景 | 结果 | +| --- | --- | +| 任务增删改、重名/空名校验、软删除、恢复、永久删除及取消 | 通过实际 GUI 验证 | +| 工程扫描、重扫保留选择、全选/清空、待处理/已完成过滤 | 通过 | +| 规则新增、编辑、删除、启停、排序、重复/链式/自映射校验 | 通过 | +| 内部分隔条、日志开关、布局重置及重启保留、只读滚动和列宽调整 | 通过 | +| 两工程三规则混合队列 | 6/6:4 项未命中、2 项已保存替换 | +| 20 工程全部未命中 | 自动连续完成 20/20,无逐项确认或不确定保护 | +| 勾选 Part Number 写入 Value | 40 个器件保存后读回符合要求 | +| 未勾选 Value | 20 个器件保留目标库值 10n,不额外改写为 Part Number | +| 显示样式、位置方向、实例字段、引脚/连接 | 保存后读回核验通过 | +| 暂停、删除、恢复后续跑 | 从 2/6 继续,不重做已完成项 | +| 原生替换期间移动鼠标、拖动窗口/分隔条 | 队列继续且没有不确定状态 | +| 旧料号未命中后目标库料号不存在 | 未命中跳过;缺失目标在原生替换前停止,后续规则不执行;20 个源器件保持不变 | +| 明确确认后重试替换前失败 | 不重做前面未命中项;不误报已改图 | +| 正在查看另一任务时后台队列结束/失败 | 错误可见、按钮解锁、任务列表更新,旧任务进度不被覆盖 | +| 实际中断属性恢复阶段 | 检出旧版遗留非终态;GUI 核验磁盘中已有效保存的结果,不重复原生替换,完成 1/1 | +| 已打开工程的所有权保护 | 拒绝接管,未执行替换 | +| 两图页工程保护 | 捕获/替换前拒绝,显示单图页限制和停止状态 | + +## 根因修复 + +- 自动队列持久化暂停状态,人工流程与自动执行共用互斥保护。 +- 修改性控件及时禁用,表格保留只读查看和调整能力。 +- 完整旧队列先归档再校验新任务 Value 策略;历史进度绑定对应任务证据。 +- 列表刷新不触发瞬时旧选择回调;后台完成始终刷新当前界面的按钮状态,错误绑定发起任务。 +- 区分启动/工程检查失败、原生替换前校验失败以及结果不确定,停止后不继续显示“正在执行”。 +- 非终态退出或可能改图后失败建立保护;没有保护标志的旧版遗留任务也能显示核验入口。解除保护仍要求快照、规则、Value 策略和原生事务绑定核验。 +- 只读恢复确认磁盘仍是源器件时,先关闭恢复过程打开的只读工程再给出重试;关闭失败或文档所有权变化不解锁重试。 +- 标题和日志共用 R11 版本常量。 + +## 自动化回归与限制 + +317 项回归通过,包含执行队列、任务状态互斥、Qt 界面、Windows VBS、恢复、Value 策略和打包检查。冻结包中 30 个代码对象、VBS 和独立启动检查通过。 + +真实中断验收得到的是“磁盘结果已有效保存”的分支;“磁盘仍是旧器件”的重试准备及只读关闭保护有 Python/VBS 回归覆盖,不冒充已完成该分支的真实 CAD 验收。 + +连续模式目前仅支持单图页工程,不遍历多图页。未命中是正常跳过结果;缺失目标、真实异常和结果不确定仍必须停止。317 项测试和上述真实样本不能证明不存在其他缺陷。 + +原生产任务和原工程没有用于本次执行验收。发布需保留旧版、备份原生产数据、校验合并源文件与发布包,并对正式路径下的 EXE 再做独立数据目录的实际点击验收。 diff --git a/docs/reviews/2026-09-07-r12-multisheet-acceptance.md b/docs/reviews/2026-09-07-r12-multisheet-acceptance.md new file mode 100644 index 0000000..37bc70b --- /dev/null +++ b/docs/reviews/2026-09-07-r12-multisheet-acceptance.md @@ -0,0 +1,45 @@ +# R12 多图页实际 EXE 验收 + +## 验收边界 + +通过桌面快捷方式实际双击候选 EXE,使用全新隔离数据目录和可丢弃的双图页工程副本完成任务创建、工程扫描、规则添加、Value 策略勾选、确认和自动执行。正式发布后又从正式路径实际双击一次,确认复制后的冻结包可独立启动并干净退出。 + +## 实际结果 + +| 场景 | 结果 | +| --- | --- | +| 双图页枚举 | 识别 `Schematic1:1` 和 `Schematic1:2`,生成两条明确绑定图页的队列项 | +| 第 1 页替换 | `C0603-100U-J -> C0603-10N-J`,20 个器件替换、保存、重新打开回读通过 | +| 第 2 页未命中 | 记录 `no_match/batch_closed` 并自动继续,队列未停止 | +| 队列结果 | 全工程图页队列 `2/2`,替换校验 1 项,未命中跳过 1 项 | +| Value 策略 | 20 个目标器件的有效 Value 均为 `C0603-10N-J` | +| Value 显示样式 | 20 个器件的位置、颜色、字体、字号、方向和可见性均与替换前快照一致 | +| 执行中拖动 | 执行期间将内部工程/规则分隔条拖动 55 像素,后台任务继续并正常完成 | +| CAD 所有权 | 验收前无 DxDesigner;由程序启动的实例只处理验收副本,工程关闭后用于只读回读并正常退出 | +| UI 完成提示 | 黄色区域表示“已完成但存在未命中”,不作为错误,也不阻断后续图页 | + +执行证据位于: + +`C:\Users\ABS_Windows\.codex\visualizations\2026\09\06\01a07479-a905-7cd3-bb57-5f99b03d06fb\round13-multisheet-r12-20260907` + +其中 `gui-data-r12\quick-run\sheets.tsv`、`command.tsv` 和 `status.tsv` 分别记录固定图页清单、逐页命令和终态。完成界面截图为 `r12-multisheet-complete.png`。 + +## 自动化回归 + +- 旧替换模块:454 项通过。 +- 旧 VBS/批处理集成组:342 项通过。 +- 多图页、任务中心、UI、Value、会话和打包核心组:323 项通过。 +- 构建前应用与打包检查:7 项通过。 +- 冻结包中的 `QuickPartReplace.vbs` 与源码 SHA256 一致,构建前后 7 个关键源码文件哈希未变化。 + +## 发布记录 + +- 正式路径:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-Test\DxPartReplace.exe` +- 版本:`2026.09.07-R12` +- EXE SHA256:`E16344DCED13B25C6122A6377D6A1AD560B40387142CD2C5EACAC40D18DA1AD7` +- 冻结包:3699 个文件,669687137 字节;正式路径逐文件长度和 SHA256 与候选包一致。 +- R11 整包和原任务数据备份:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-Backups\release-20260907-112502` + +## 剩余边界 + +真实 CAD 验收覆盖了一个两图页工程,其中一页实际命中、一页未命中。多工程、多规则、暂停续跑、图页清单变化保护和恢复绑定已由自动化测试覆盖,但本轮没有用大量真实多图页工程做压力测试。多工程仍严格串行,避免同时启动多个 CAD 工程造成资源竞争;真实批量性能需要按实际工程规模继续观察。 diff --git a/docs/reviews/2026-09-07-r13-value-nc-delete-acceptance.md b/docs/reviews/2026-09-07-r13-value-nc-delete-acceptance.md new file mode 100644 index 0000000..a2b2462 --- /dev/null +++ b/docs/reviews/2026-09-07-r13-value-nc-delete-acceptance.md @@ -0,0 +1,31 @@ +# R13 Value、NC 与永久删除验收 + +## 功能边界 + +- 未勾选“替换后将 Part Label 写入 Value”时,不读取或要求目标 Part Label,保留替换后目标器件的原生 Value。 +- 勾选后,将目标器件的有效 Part Label 写入 Value,并进行最终回读校验。 +- 旧 Value 含以 `/` 分隔的独立 `NC` 段时,两种 Value 模式都将 `/NC` 同步到替换后的 Value。 +- `NC`、`NCM` 和 `NC_OPTION` 等相似文本不视为 `/NC` 标记;目标值已有 `/NC` 时不重复追加。 +- 已删除任务可直接永久删除,不受自动队列锁限制;工程文件和诊断证据仍保留。 + +## 自动化结果 + +| 场景 | 结果 | +| --- | --- | +| Value、NC、批量与 UI 专项 | 94 项通过 | +| Bridge 重解析路径复现 | 同步盘临时目录被安全检查拒绝;改用非重解析临时目录后通过 | +| 完整测试套件 | 1135 项直接通过;唯一过期的 R12 窗口标题断言更新为 R13 后通过,合计 1136 项通过 | +| NC 日志 | 输出 `位号 R1 R0603/NC -> R0805/NC,识别到 NC,已同步` | + +## 发布记录 + +- 正式路径:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-Test\DxPartReplace.exe` +- 版本:`2026.09.07-R13` +- EXE SHA256:`95A88D4DD216761671A68687F7FE1F126886AF1AB1D7F2C271C9F167FC1D92A0` +- 冻结包:3660 个文件,667523788 字节;正式目录逐文件长度和 SHA256 与候选包一致。 +- R12 整包备份:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-Backups\release-20260907-145943-R12-before-R13` +- 正式路径隔离冒烟:`application_start version=2026.09.07-R13`,`application_clean_shutdown exit_code=0`。 + +## 剩余验证 + +自动化已覆盖缺失 Value、缺失或空白 Part Label、已有 `/NC`、相似文本误识别边界和批量日志聚合。发布前仍应使用可丢弃的真实 DxDesigner 工程分别验收勾选与未勾选模式,并核对保存后的工程文件。 diff --git a/docs/reviews/2026-09-07-r14-directory-switch-acceptance.md b/docs/reviews/2026-09-07-r14-directory-switch-acceptance.md new file mode 100644 index 0000000..8f55ede --- /dev/null +++ b/docs/reviews/2026-09-07-r14-directory-switch-acceptance.md @@ -0,0 +1,37 @@ +# R14 工程目录切换验收 + +## 问题与修复 + +- 原实现切换扫描目录后只把旧工程标记为不可用,仍将它们返回给界面,因此新旧目录工程会同时显示。 +- 目录文本变化后,界面立即清空工程表,显示“目录已更改,等待重新扫描”,并在完成新扫描前禁用执行入口。 +- 尚未执行的任务切换目录时,持久层删除旧目录工程清单,再写入新目录扫描结果;新目录项目默认不勾选。 +- 同一目录重扫继续保留选择状态,并将本次缺失的工程标记为不可用。 +- 已有项目执行状态、attempt、恢复记录或自动队列证据时拒绝切换目录,保留旧清单并提示新建任务,避免丢失或混合审计证据。 + +## 验证结果 + +| 场景 | 结果 | +| --- | --- | +| 新目录替换未执行旧清单 | 通过 | +| 已有执行记录时拒绝切换并保留原数据 | 通过 | +| UI 修改目录后立即隐藏旧项目 | 通过 | +| 当前源码专项重跑 | 9 项通过 | +| 存储、服务、队列、恢复、批量及 UI 回归 | 172 项通过 | +| 构建前检查 | 7 项通过 | +| 正式路径隔离冒烟 | `application_start version=2026.09.07-R14`;`application_clean_shutdown exit_code=0` | + +## 发布记录 + +- 版本:`2026.09.07-R14` +- 正式程序:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-Test\DxPartReplace.exe` +- 最新归档:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-R14-20260907.zip` +- 归档大小:249279473 字节;3928 个 ZIP 条目;未压缩文件合计 667525074 字节。 +- ZIP SHA256:`B87878C775BB7A975E6531815343EC27398EF5998CB348E4F167C41124E6ABEC` +- ZIP 内 EXE SHA256:`C8F37D4C55E974BEBD94F79972DDE0C1641972555AE8316DFF6230F8C04555B8` +- ZIP 内 `QuickPartReplace.vbs` SHA256:`53EF207FFA2E5D97857EC9C069E2F58CC0F4FCFF2392F31EF13F6359D56BA107` + +## 清理记录 + +- 已删除 R13 ZIP、R13 部署回滚候选、本轮 `build`、`dist` 和 R14 测试临时目录。 +- 保留源码目录、正式 R14 目录和唯一 R14 ZIP。 +- 更早的历史回滚备份与验收证据没有在本轮永久删除,避免在未单独确认保留策略时误删不可重建证据。 diff --git a/docs/reviews/2026-09-08-r15-long-run-acceptance.md b/docs/reviews/2026-09-08-r15-long-run-acceptance.md new file mode 100644 index 0000000..1aa9aac --- /dev/null +++ b/docs/reviews/2026-09-08-r15-long-run-acceptance.md @@ -0,0 +1,81 @@ +# R15 批量、恢复与长期运行验收 + +## 验收范围 + +本轮验证 `2026.09.08-R15` 的真实多图页执行、20 工程串行批量、未命中继续、故障恢复与暂停续跑、长期日志和历史留存、自动化回归、冻结包构建及独立冒烟。按用户要求,第 5 项干净电脑外发验收未执行。 + +所有真实 CAD 写入均使用可丢弃工程副本。测试期间只清理本轮明确启动的 DxDesigner 进程,没有结束并发测试或其他未知进程。 + +## 真实 DxDesigner 7.9.5 + +| 场景 | 结果 | +| --- | --- | +| 双图页、两条规则 | 4 个队列项全部结束:1 个 `saved_ok`,3 个 `no_match`;未命中没有中断队列 | +| 实际命中 | `C0603-10N-J -> C0603-100U-J`,20 个器件替换、保存、重新打开回读并关闭 | +| Value 策略 | 勾选 Part Label 写入 Value;日志确认 `value_mode=part_label`,20 个器件回读通过 | +| 图页范围 | 发现 `Schematic1:1`、`Schematic1:2`,命令逐页绑定,没有只处理当前页 | +| 实际失败 | `C0603 -> C0805` 的连接校验失败后自动回滚并停止,未把失败当成未命中继续 | +| 20 工程未命中批量 | 20/20 项均为 `no_match/batch_closed`,队列完成,无 `uncertain.flag`,无残留 `current-state.tsv` | +| 备份顺序 | 20 个工程均在图页枚举前完成独立备份;全部备份和枚举完成后才进入替换队列 | +| 性能 | 20 工程总耗时 653.431 秒;DxDesigner 单实例复用,观测工作集约 198.4 MiB 至峰值 249.3 MiB | + +双图页证据: + +`C:\Users\ABS_Windows\.codex\visualizations\2026\09\06\01a07479-a905-7cd3-bb57-5f99b03d06fb\r15-long-run-acceptance-20260907\multisheet-hit\data` + +20 工程证据: + +`C:\Users\ABS_Windows\.codex\visualizations\2026\09\06\01a07479-a905-7cd3-bb57-5f99b03d06fb\r15-long-run-acceptance-20260907\lb-003934` + +回滚失败证据: + +`C:\Users\ABS_Windows\.codex\visualizations\2026\09\06\01a07479-a905-7cd3-bb57-5f99b03d06fb\r15-long-run-acceptance-20260907\hit-miss-5\data` + +## 故障与恢复 + +- 超时先请求安全停止,继续无响应才终止受控 worker;worker 及其允许的子进程不会残留。 +- 暂停后从下一条未完成命令继续,已完成命令不重复执行。 +- 命令、状态、快照或恢复绑定损坏时保持保护锁,不把不确定结果标成成功。 +- 初始备份失败使用 `quick_run_backup`,不会误显示成“中断恢复失败”。 +- Python 3.11 实机测试发现 `Path.is_junction()` 兼容崩溃后,备份哈希改为基于 `lstat` 和 Windows reparse 属性;3.11 探针及 3.12 回归均通过。 +- 故障、恢复、执行安全和批量专项共 82 项通过。 + +## 长期留存 + +- `quick-part-replace.log`:单段上限 5 MiB,保留 3 个轮转备份。 +- 单任务 `events.jsonl`:单段上限 5 MiB,保留 5 个轮转备份,事件序号跨段连续。 +- `quick-run-history`:默认 30 天、100 份或 5 GiB 任一边界触发清理,同时至少保留最新 10 份。 +- 清理仅识别 `batch-*`、`recovery-*`、`sheet-discovery-*` 和 `obsolete-*`;未知人工目录、链接和重定向目录不删除。 +- 250 份合成历史经默认参数收敛为最新 100 份(`batch-150` 至 `batch-249`);人工目录保留,5 轮 6 MiB 日志最终仅保留 3 个备份。 +- 留存与日志专项 10 项通过。 + +## 自动化回归 + +由于单个超长 pytest 会话在分组边界被外部执行器终止,最终按文件和目录拆分运行全部收集项;各组均独立返回退出码 0: + +| 分组 | 结果 | +| --- | --- | +| Integration | 424 passed | +| Part replacement core | 454 passed | +| Trial task center | 254 passed | +| UI(Qt offscreen) | 40 passed | +| Packaging | 2 passed | +| 合计 | 1174 passed | + +`pip check` 返回 `No broken requirements found`,`compileall -q src` 通过。 + +## 构建结果 + +- 构建前应用与打包检查:8 项通过。 +- 候选程序:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\dist\DxPartReplace\DxPartReplace.exe` +- EXE SHA256:`C560BA6A65A37CC29F2F2D80FFD9283E3871E601376FFEC000E75A35570E2DCF` +- 冻结目录:218 个文件,105.54 MiB。 +- 源码及包内 `QuickPartReplace.vbs` SHA256:`B4FDD1C47B379D5E1541423DF8FF2CB29815B534D9E0998BB2DB0D3305FA11BA`。 +- 独立冒烟:退出码 0;日志包含 `application_start version=2026.09.08-R15` 和 `application_clean_shutdown exit_code=0`。 + +## 已知边界 + +- 未执行用户排除的干净电脑安装、杀毒软件、不同权限账户和缺少开发环境时的外发验收。 +- 20 工程实机压力场景验证的是大批量未命中继续;批量连续多次真实写入仍只由自动化测试和单工程实机命中覆盖。 +- 32 位 WSH/ADODB 对超长控制文件路径仍有传统限制:273 字符的人工验收数据根无法读取监督授权文件,247 字符路径可正常运行。正式应用默认 `%LOCALAPPDATA%` 数据根不触发该问题;自定义超长 `--data-root` 不在支持范围内。 +- 本轮只生成仓库 `dist` 候选包,没有覆盖工作区外的 `DxPartReplace-Test` 正式目录,也没有创建新的外发 ZIP。 diff --git a/docs/reviews/2026-09-08-r16-portable-performance.md b/docs/reviews/2026-09-08-r16-portable-performance.md new file mode 100644 index 0000000..21d3965 --- /dev/null +++ b/docs/reviews/2026-09-08-r16-portable-performance.md @@ -0,0 +1,51 @@ +# R16 便携数据与批量性能验收 + +## 本轮结果 + +- 发布版默认数据根改为 `DxPartReplace.exe` 同目录的 `data`;数据库、日志、任务证据和工程备份均位于该目录下。源码开发运行仍使用 `%LOCALAPPDATA%`,命令行和环境变量覆盖保持不变。 +- 构建脚本重建 `dist` 前会暂存并恢复已有 `data`,避免更新程序时删除本机备份。正式安装目录的镜像更新同样排除 `data`。 +- 扫描工程时排除当前数据根,选择安装目录或其上级目录时不会把 `data\quick-run-history\batch-*\project-*` 中的备份重新识别成待处理工程。 +- 图页枚举同时建立规则旧料号命中索引。已确认未命中的队列项直接记录为 `no_match/batch_closed`,不再为同一结论第二次打开工程。 +- 真实命中完成后清理 `current-state.tsv`;未命中项不执行无意义的删除系统调用,1000 项合成队列性能门槛重新通过。 +- 替换日志优先使用替换前快照中的位号;原工程未标注位号时使用 `UID=...`,不输出无法追踪的空白条目。 + +## 实测性能 + +| 场景 | 总耗时 | 每工程 | 真实结果 | +| --- | ---: | ---: | --- | +| R15,20 工程未命中 | 653.431 秒 | 32.672 秒 | 20/20 `no_match`,仍启动 20 次替换 worker | +| R16,20 工程未命中 | 218.472 秒 | 10.924 秒 | 20/20 `no_match`,替换 worker 为 0 | +| R16,最初标作命中的 3 工程 | 33.424 秒 | 11.141 秒 | 实际 3/3 未命中,不能作为命中性能数据 | +| R16,3 个双图页真实命中工程 | 595.727 秒 | 198.576 秒 | 3 个 `saved_ok`、3 个第二页预筛 `no_match`;每工程替换 20 个器件 | +| R16,单工程状态清理回归 | 193.098 秒 | 193.098 秒 | 1 个 `saved_ok`、1 个预筛 `no_match`;无 `current-state.tsv`、无 `uncertain.flag` | +| R16,单工程日志诊断回归 | 219.090 秒 | 219.090 秒 | 1 个 `saved_ok`、1 个预筛 `no_match`;样本本身未标注位号 | + +因此不能把当前性能概括为“平均一个工程 1 分钟”。未命中工程约 11 秒;包含 20 个真实器件替换、保存、关闭和重新打开回读的工程约 3.2 至 3.7 分钟。若批次约四分之一工程真实命中,混合平均值才可能接近 1 分钟;实际耗时还取决于图页数、规则数、命中器件数、中央库和 DxDesigner 数据库响应。 + +R16 的未命中路径比 R15 快约 66.6%。真实命中日志显示主要耗时位于 DxDesigner 原生替换、数据库处理和保存后回读,而不是 Python 队列遍历。保存后回读是确认落盘的安全门禁,不能直接删除。 + +## 测试覆盖边界 + +- 本轮前的完整自动化回归为 `1182 passed`。最终便携目录、状态清理、监控、扫描、VBS 契约和构建相关回归为 `112 passed`;最终两个性能与状态清理专项为 `3 passed`。 +- 20 工程实机压力测试确实全部未命中;最初选取的 3 工程“命中样本”也实际未命中。之后已改用替换前备份,完成 3 工程连续真实写入和两次单工程真实写入。 +- 当前仍缺少 10 至 20 个工程连续真实命中的长时间压力测试,以及不同工程规模、不同命中数量的分层样本。现有结果能证明逻辑和未命中批量性能,不能证明所有真实生产批次都按同一平均耗时运行。 +- 32 位 WSH/ADODB 对超长控制文件路径存在传统限制。人工测试的长数据根出现授权文件不可见,短路径立即通过。正式安装目录应避免过深;后续应增加启动前路径长度诊断,而不是等待 20 秒后显示握手失败。 + +## 后续优化优先级 + +1. 同一工程同一图页有多条命中规则时,将多条规则合并为一次受控打开、替换、保存和回读。这是最大潜在收益,但需要重做事务边界、逐规则状态和恢复协议,必须先用可丢弃工程专项验证。 +2. 增加备份、枚举、原生替换、恢复、保存和回读的分阶段耗时事件,UI 按命中与未命中历史分别估算剩余时间,避免使用失真的单一平均值。 +3. 将工程备份的三次完整哈希遍历改成受控复制时同步计算摘要,并保留源目录前后变化检查,降低大工程在替换前的磁盘扫描成本。 +4. 对发布目录和控制文件做 32 位 WSH 路径长度预检,必要时提示移动到更短安装目录;不能通过静默改回 AppData 绕开用户指定的数据位置。 + +## 发布结果 + +- 候选目录:`F:\Sync Tool Skyworth\Work Maps\dxdesigner-part-replacement\dist\DxPartReplace` +- 实际测试安装目录:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-Test` +- 版本:`2026.09.08-R16` +- 文件数:218 +- 体积:105.55 MiB +- EXE SHA256:`5062DE8580DBA0A244C5ABA21FFC260E292863C64F089645C3C8E9EAD14EF93E` +- 源码与包内 `QuickPartReplace.vbs` SHA256:`B5A31D1ACED6BEFAFCEE351F9A794A4F3D0B18C66E9DD68F59E8C2383D892C04` +- 候选包和实际安装目录冒烟均退出码 0;实际安装目录已生成并保留 EXE 旁的 `data\task-center.db` 与 `data\logs\application.log`。 +- PyInstaller 缺失模块告警均来自非 Windows 平台分支、可选 Pillow/Numpy/Xlib、兼容层内部类型或测试模块;当前包内功能与独立冒烟未发现缺失运行依赖。 diff --git a/docs/reviews/2026-09-08-v1.0.0-release.md b/docs/reviews/2026-09-08-v1.0.0-release.md new file mode 100644 index 0000000..3475e4c --- /dev/null +++ b/docs/reviews/2026-09-08-v1.0.0-release.md @@ -0,0 +1,40 @@ +# DxPartReplace 1.0.0 正式发布记录 + +发布日期:2026-09-08 + +## 发布范围 + +- 桌面版版本号固定为 `1.0.0`。 +- 多个已选工程按“工程 -> 图页 -> 规则”严格串行执行,不并发打开或同时修改多个工程。 +- 正式桌面界面和当前用户指南已移除试用阶段的工程副本文案。 +- 正式包包含 `DxPartReplace 1.0.0 使用说明.docx`,提供逐步截图、点击位置标注和常见报错处理。 +- 工程扫描只接收带有 DxDesigner 原理图数据库标记的 `.prj`;纯 PCB 工程及其他软件的同后缀文件不进入任务列表。 +- 项目表超过可视区域后,勾选或取消勾选会保持当前垂直和水平滚动位置及当前行。 +- 修复后台 worker 完成时窗口已销毁仍访问按钮的 Qt 生命周期竞态。 +- 数据、日志和工程备份继续写入程序目录旁的 `data`;正式包不携带本机数据。 + +## 验证结果 + +- Scanner、Service、Batch 和 UI 直接回归:`80 passed`。 +- 其余扫描调用链回归:`93 passed`。 +- 最终界面一致性回归:`13 passed`。 +- 构建前置测试:`10 passed`。 +- `compileall`:通过。 +- `pip check`:`No broken requirements found.` +- PyInstaller 构建:通过。 +- 独立 EXE 冒烟:记录 `application_start version=1.0.0` 和 `application_clean_shutdown exit_code=0`。 +- 打包后的 `QuickPartReplace.vbs` 与源码 SHA-256 一致。 + +## 正式产物 + +- 便携目录:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace` +- 文件数:219 +- 未压缩体积:106.27 MiB +- EXE SHA-256:`85885602EDB103530C6BD5A8784E440CDB2DCC285A8919BE31377F7889090223` +- 使用说明 SHA-256:`0CB91973EF88F091EE65DE1A9897A1C265BC4C57952B43F44B3C895C98964BE7` +- ZIP:`F:\Sync Tool Skyworth\Work Maps\DxPartReplace-1.0.0.zip` +- ZIP 体积:43.14 MiB +- ZIP SHA-256:`B92023CA88B9B7BD8FE0ADB751F872781500AFF92E6C023CB32149CCE743079A` +- VBS SHA-256:`B5A31D1ACED6BEFAFCEE351F9A794A4F3D0B18C66E9DD68F59E8C2383D892C04` + +ZIP 包含一个顶层 `DxPartReplace` 目录、一个 EXE、使用说明和完整运行依赖;不包含 `data`、旧测试目录、阶段构建目录或历史发布副本。 diff --git a/docs/superpowers/plans/2026-09-01-dxdesigner-795-part-replacement-implementation.md b/docs/superpowers/plans/2026-09-01-dxdesigner-795-part-replacement-implementation.md new file mode 100644 index 0000000..c3a67a4 --- /dev/null +++ b/docs/superpowers/plans/2026-09-01-dxdesigner-795-part-replacement-implementation.md @@ -0,0 +1,1115 @@ +# DxDesigner 7.9.5 Multi-Project Part Replacement Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Deliver a resumable semi-automatic script that applies one old-Part-Number to new-Part-Number mapping set across multiple DxDesigner 7.9.5 projects through native Replace Part, with inventory, certification, backup, verification, and reports. + +**Architecture:** A pure Python 3.12 package owns immutable job inputs, snapshots, compatibility rules, the project state machine, backups, orchestration, and reports. ASCII-only VBScript runs inside DxDesigner 7.9.5 to enumerate and select live objects, invoke only probe-verified application routes, and exchange versioned UTF-8 files with Python; native Replace Part with Library Wins remains the production write path and has an explicit operator-menu fallback. + +**Tech Stack:** Python 3.12 standard library, pytest 8.x, coverage 7.x, VBScript/cscript, Windows PowerShell 5.1 or PowerShell 7, UTF-8 JSON/TSV, static HTML, Git. + +**Spec:** `docs/superpowers/specs/2026-09-01-dxdesigner-795-part-replacement-design.md` + +## Global Constraints + +- DxDesigner/Expedition Enterprise 7.9.5 is the only supported schematic integration baseline. +- All DxDesigner API access stays in the internal VBScript host; Python must not instantiate or attach to `ViewDraw.Application`. +- Native Replace Part with Library Wins is the only version-1 production replacement path. +- `ChangeComponentPreserveRefdes` and direct exported-design edits are prohibited production paths. +- `ccomp` may be probed but must not be enabled for production Apply in version 1. +- No UI-coordinate automation, `SendKeys`, blind timing delays, or automatic schematic rewiring. +- Every `.vbs` source file is ASCII-only; localized messages use `ChrW` or are rendered by Python. +- Python source runs on Python `>=3.12,<3.13` with no runtime package dependency. +- Multi-project jobs use full-project scope; current-sheet and selected-component scopes are single-project only. +- Mapping identity is case-insensitive after trimming, while reports preserve original spelling. +- Duplicate, equal, chained, and cyclic mappings are rejected before inventory. +- An uncertified old/new pair cannot enter production Apply and has no override. +- Every project must be saved and closed before its complete project-tree backup. +- Apply is blocked by stale state, ambiguous component identity, unverifiable protected state, or missing pin/network data. +- Save is blocked until target, count, protected placement, pin geometry, connectivity, and unrelated-object invariants pass. +- AI output is advisory only and cannot change verification or save state. +- Compatibility is not claimed until the live 7.9.5 probe and acceptance checklist pass. + +--- + +## Planned File Structure + +```text +pyproject.toml +src/dx_productivity/ + __init__.py + __main__.py + part_replace/ + __init__.py + models.py Immutable mappings, projects, snapshots, issues, states + inputs.py Mapping/project parsing and candidate discovery + protocol.py Versioned JSON/TSV and atomic file exchange + verification.py Impact matrix and before/after invariant checks + certification.py Trial certification fingerprints and invalidation + run_store.py Durable event log, state projection, tree hashes, backups + reports.py CSV, JSON, and static HTML report generation + controller.py Inventory/apply/save/resume use-case orchestration + cli.py Reproducible command-line interface +integration/dxdesigner795/ + BridgeCommon.vbs ASCII-only UTF-8, escaping, path, mailbox helpers + PartReplaceProbe.vbs Read-mostly 7.9.5 capability and route probe + PartReplaceBridge.vbs Inventory, selection, result export, undo/save adapter + MenuAdd.vbs Idempotent startup-imported suite menu + Start-PartReplacement.ps1 CLI launcher and optional standard path pickers + Install.ps1 User-level DXTOOLS_HOME and settings installation +tests/ + conftest.py + fixtures/ + snapshot-before.json + snapshot-after-compatible.json + snapshot-after-pin-change.json + part_replace/ + test_models.py + test_inputs.py + test_protocol.py + test_verification.py + test_certification.py + test_run_store.py + test_reports.py + test_controller.py + test_cli.py + integration/ + mock_dxdesigner.py + test_part_replace_end_to_end.py + test_part_replace_probe.py + test_part_replace_bridge.py + test_part_replace_install.py + vbs/ + test_bridge_common.vbs +docs/user/part-replacement.md +docs/testing/dxdesigner-795-part-replacement-live.md +``` + +## Spec Coverage + +| Spec sections | Implementation tasks | +| --- | --- | +| Purpose, compatibility, evidence, scope | Tasks 1, 8, 10, 11, 12 | +| Mapping and project identity | Task 2 | +| Architecture and file protocol | Tasks 3, 5, 7, 8, 10, 11 | +| Inventory and impact matrix | Tasks 4, 8, 9, 11 | +| Compatibility certification | Tasks 4, 6, 9, 13 | +| Apply workflow and protected verification | Tasks 4, 5, 8, 9, 11 | +| Failure handling, restore, and resume | Tasks 5, 8, 9, 11 | +| Operator and AI-review boundaries | Tasks 3, 7, 8, 12, 13 | +| Compatibility probe | Task 10 | +| Automated/live testing and release criteria | Tasks 9, 10, 11, 12, 13, 14 | + +### Task 1: Python Package and Immutable Domain Model + +**Files:** +- Create: `pyproject.toml` +- Create: `src/dx_productivity/__init__.py` +- Create: `src/dx_productivity/part_replace/__init__.py` +- Create: `src/dx_productivity/part_replace/models.py` +- Create: `tests/conftest.py` +- Create: `tests/part_replace/test_models.py` + +**Interfaces:** +- Consumes: no earlier task. +- Produces: `Scope`, `ProjectState`, `MappingRule`, `ProjectRef`, `PinSnapshot`, `UnitSnapshot`, `ComponentSnapshot`, `DesignSnapshot`, `Issue`, `VerificationResult`, `ImpactCell`, and `ExternalChecks` immutable dataclasses. + +- [ ] **Step 1: Write failing immutable-model tests** + +```python +from dataclasses import FrozenInstanceError +from decimal import Decimal + +import pytest + +from dx_productivity.part_replace.models import ( + ComponentSnapshot, + DesignSnapshot, + MappingRule, + PinSnapshot, + ProjectState, + Scope, + UnitSnapshot, +) + + +def test_snapshot_model_is_immutable_and_decimal_exact() -> None: + pin = PinSnapshot(number="1", name="A", x=Decimal("10.25"), y=Decimal("20"), net="N$1") + unit = UnitSnapshot(unit_id="u1", sheet="/MAIN", symbol="res.1", x=Decimal("0"), + y=Decimal("0"), rotation=0, mirrored=False, pins=(pin,)) + component = ComponentSnapshot(logical_key="/MAIN|R1", refdes="R1", + part_number="OLD-1", units=(unit,), attributes=()) + snapshot = DesignSnapshot(format_version=1, project_id="p1", project_path="C:/P/a.prj", + fingerprint="abc", components=(component,)) + with pytest.raises(FrozenInstanceError): + snapshot.project_id = "p2" # type: ignore[misc] + assert snapshot.components[0].units[0].pins[0].x == Decimal("10.25") + + +def test_state_and_scope_values_are_protocol_stable() -> None: + assert Scope.FULL_PROJECT.value == "full_project" + assert ProjectState.AWAITING_SAVE_CONFIRMATION.value == "awaiting_save_confirmation" + assert MappingRule("OLD", "NEW").old_part_number == "OLD" +``` + +- [ ] **Step 2: Run the test and confirm the missing-package failure** + +Run: `py -3.12 -m pytest tests/part_replace/test_models.py -v` + +Expected: collection fails with `ModuleNotFoundError: No module named 'dx_productivity'`. + +- [ ] **Step 3: Add package metadata and the focused model types** + +```toml +[build-system] +requires = ["setuptools>=75"] +build-backend = "setuptools.build_meta" + +[project] +name = "dx-productivity" +version = "0.1.0" +requires-python = ">=3.12,<3.13" +dependencies = [] + +[project.optional-dependencies] +dev = ["pytest>=8,<9", "pytest-cov>=5,<7", "coverage>=7,<8", "build>=1.2,<2"] + +[tool.setuptools.packages.find] +where = ["src"] + +[tool.pytest.ini_options] +testpaths = ["tests"] +addopts = "-ra" +``` + +Implement every record with `@dataclass(frozen=True, slots=True)`. Store attributes as sorted `tuple[tuple[str, str], ...]`, pins and units as tuples, coordinates as `Decimal`, rotation as integer degrees, and issue details as immutable tuples. `ExternalChecks` has `packager`, `erc`, and `netlist` fields of type `bool | None`. Define the exact state values from Section 11.1 of the spec. Put shared immutable snapshot factories in `tests/conftest.py`; they must return new values per test and must not read or write the live filesystem outside `tmp_path`. + +- [ ] **Step 4: Install editable development dependencies and run the focused test** + +Run: `py -3.12 -m pip install -e ".[dev]"` + +Run: `py -3.12 -m pytest tests/part_replace/test_models.py -v` + +Expected: all model tests pass. + +- [ ] **Step 5: Commit the package foundation** + +```powershell +git add pyproject.toml src/dx_productivity tests/part_replace/test_models.py +git commit -m "feat: add part replacement domain model" +``` + +### Task 2: Strict Mapping and Project Inputs + +**Files:** +- Create: `src/dx_productivity/part_replace/inputs.py` +- Create: `tests/part_replace/test_inputs.py` + +**Interfaces:** +- Consumes: `MappingRule`, `ProjectRef`, and `Scope` from `models.py`. +- Produces: `InputError(code: str, message: str)`, `load_mapping(path: Path) -> tuple[MappingRule, ...]`, `load_projects(path: Path, allowed_suffixes: tuple[str, ...]) -> tuple[ProjectRef, ...]`, and `discover_projects(root: Path, allowed_suffixes: tuple[str, ...]) -> tuple[Path, ...]`. + +- [ ] **Step 1: Write failing mapping validation tests** + +```python +def test_load_mapping_rejects_case_duplicate_chain_and_cycle(tmp_path: Path) -> None: + duplicate = write(tmp_path / "duplicate.csv", + "old_part_number,new_part_number\nA,B\na,C\n") + with pytest.raises(InputError, match="duplicate_source"): + load_mapping(duplicate) + + chain = write(tmp_path / "chain.csv", + "old_part_number,new_part_number\nA,B\nB,C\n") + with pytest.raises(InputError, match="mapping_chain"): + load_mapping(chain) + + cycle = write(tmp_path / "cycle.csv", + "old_part_number,new_part_number\nA,B\nB,A\n") + with pytest.raises(InputError, match="mapping_cycle"): + load_mapping(cycle) + + +def test_load_mapping_accepts_utf8_bom_and_preserves_spelling(tmp_path: Path) -> None: + path = tmp_path / "替换.csv" + path.write_text("old_part_number,new_part_number\n old-01 , New-01 \n", + encoding="utf-8-sig") + assert load_mapping(path) == (MappingRule("old-01", "New-01"),) +``` + +- [ ] **Step 2: Run the focused test and confirm the missing-module failure** + +Run: `py -3.12 -m pytest tests/part_replace/test_inputs.py -v` + +Expected: collection fails because `inputs.py` does not exist. + +- [ ] **Step 3: Implement strict CSV and project-list parsing** + +Use `csv.DictReader`, require the header set to equal +`{"old_part_number", "new_part_number"}`, normalize identity with +`value.strip().casefold()`, reject equal rules before graph checks, detect +chains when any normalized target is also a normalized source, and report a +cycle-specific code when the directed graph closes. Preserve input order. + +For projects, ignore blank lines and `#` comments, require absolute existing +files with an allowlisted case-insensitive suffix, resolve each path, reject +duplicates case-insensitively on Windows, and derive `project_id` as the first +16 hex characters of SHA-256 over the normalized canonical path. + +Discovery recursively finds only allowlisted project-definition files, sorts by +casefolded canonical path, and returns candidates without writing or accepting +them. + +- [ ] **Step 4: Run all input tests** + +Run: `py -3.12 -m pytest tests/part_replace/test_inputs.py -v` + +Expected: tests pass for invalid graphs, exact headers, Unicode paths, duplicate +projects, missing projects, deterministic discovery, and explicit review output. + +- [ ] **Step 5: Commit input validation** + +```powershell +git add src/dx_productivity/part_replace/inputs.py tests/part_replace/test_inputs.py +git commit -m "feat: validate replacement job inputs" +``` + +### Task 3: Versioned Snapshot and Mailbox Protocol + +**Files:** +- Create: `src/dx_productivity/part_replace/protocol.py` +- Create: `tests/part_replace/test_protocol.py` +- Create: `tests/fixtures/snapshot-before.json` +- Create: `tests/fixtures/snapshot-after-compatible.json` +- Create: `tests/fixtures/snapshot-after-pin-change.json` + +**Interfaces:** +- Consumes: snapshot and mapping models. +- Produces: immutable `BridgeCommand` and `BridgeStatus` records; `load_snapshot(path: Path) -> DesignSnapshot`, `write_snapshot(path: Path, snapshot: DesignSnapshot) -> None`, `write_command(path: Path, command: BridgeCommand) -> None`, `load_status(path: Path) -> BridgeStatus`, `atomic_write_text(path: Path, text: str) -> None`, and `snapshot_fingerprint(snapshot: DesignSnapshot) -> str`. + +- [ ] **Step 1: Write failing round-trip, schema, Decimal, and atomicity tests** + +```python +def test_snapshot_round_trip_is_canonical(tmp_path: Path, before_snapshot: DesignSnapshot) -> None: + output = tmp_path / "snapshot.json" + write_snapshot(output, before_snapshot) + loaded = load_snapshot(output) + assert loaded == before_snapshot + assert json.loads(output.read_text(encoding="utf-8"))["format_version"] == 1 + assert snapshot_fingerprint(loaded) == snapshot_fingerprint(before_snapshot) + assert not list(tmp_path.glob("*.tmp")) + + +def test_unknown_schema_is_rejected(tmp_path: Path) -> None: + path = tmp_path / "future.json" + path.write_text('{"format_version":2}', encoding="utf-8") + with pytest.raises(ProtocolError, match="unsupported_format_version"): + load_snapshot(path) +``` + +- [ ] **Step 2: Run the protocol tests and verify missing symbols** + +Run: `py -3.12 -m pytest tests/part_replace/test_protocol.py -v` + +Expected: collection fails because `protocol.py` is missing. + +- [ ] **Step 3: Implement canonical protocol conversion** + +Serialize Decimal values as strings, booleans as JSON booleans, tuples as JSON +arrays, attributes as sorted `{"name": ..., "value": ...}` objects, and object +keys in deterministic order. Reject unknown format versions, missing required +fields, duplicate logical keys, duplicate unit IDs within a component, and +duplicate pin numbers within a unit. + +`BridgeCommand` has exact fields `format_version`, `command_id`, `action`, +`job_id`, `project_id`, `scope`, `old_part_number`, `new_part_number`, +`expected_logical_keys`, `expected_count`, and `expected_fingerprint`. + +Atomic publication writes UTF-8 with `\n` newlines to a same-directory unique +temporary file, flushes and `os.fsync()`s it, then calls `os.replace()`. + +- [ ] **Step 4: Run the protocol and fixture tests** + +Run: `py -3.12 -m pytest tests/part_replace/test_protocol.py -v` + +Expected: all canonicalization, validation, and atomicity tests pass. + +- [ ] **Step 5: Commit the protocol** + +```powershell +git add src/dx_productivity/part_replace/protocol.py tests/part_replace/test_protocol.py tests/fixtures +git commit -m "feat: add versioned part replacement protocol" +``` + +### Task 4: Impact Matrix and Hard Verification Engine + +**Files:** +- Create: `src/dx_productivity/part_replace/verification.py` +- Create: `tests/part_replace/test_verification.py` + +**Interfaces:** +- Consumes: `DesignSnapshot`, `MappingRule`, `ImpactCell`, and `VerificationResult`. +- Produces: `build_impact_matrix(snapshots: Iterable[DesignSnapshot], rules: Sequence[MappingRule]) -> tuple[ImpactCell, ...]`, `eligible_logical_keys(snapshot: DesignSnapshot, rule: MappingRule) -> tuple[str, ...]`, and `verify_replacement(before: DesignSnapshot, after: DesignSnapshot, rule: MappingRule, expected_logical_keys: Sequence[str], coordinate_tolerance: Decimal = Decimal("0.000001")) -> VerificationResult`. + +- [ ] **Step 1: Write failing compatible and blocking-difference tests** + +```python +def test_compatible_replacement_preserves_every_hard_invariant(fixtures) -> None: + result = verify_replacement(fixtures.before, fixtures.compatible, + MappingRule("OLD-1", "NEW-1"), ("/MAIN|R1",)) + assert result.passed + assert result.issues == () + + +@pytest.mark.parametrize("mutator,code", [ + (change_refdes, "refdes_changed"), + (move_origin, "placement_changed"), + (remove_pin, "pin_set_changed"), + (move_pin, "pin_position_changed"), + (change_net, "connectivity_changed"), + (change_unrelated_part, "unrelated_component_changed"), + (select_wrong_target, "wrong_target_part_number"), +]) +def test_verification_blocks_unsafe_change(fixtures, mutator, code) -> None: + result = verify_replacement(fixtures.before, mutator(fixtures.compatible), + MappingRule("OLD-1", "NEW-1"), ("/MAIN|R1",)) + assert not result.passed + assert code in {issue.code for issue in result.issues} +``` + +- [ ] **Step 2: Run the focused tests and confirm failure** + +Run: `py -3.12 -m pytest tests/part_replace/test_verification.py -v` + +Expected: collection fails because `verification.py` does not exist. + +- [ ] **Step 3: Implement deterministic matching and comparisons** + +Index components by `logical_key`. Compare the complete before/after component +key set, then treat expected keys and unrelated keys separately. For expected +keys require exact target Part Number after trim/casefold, exact RefDes, +hierarchy, unit set, symbol placement, integer rotation, mirror state, gate/slot, +pin-number set, and net identity. Compare coordinates with absolute Decimal +difference no larger than the supplied serialization tolerance. + +Library-controlled symbol and non-protected attribute changes are returned as +nonblocking differences. Any expected object missing, extra object added, +duplicate identity, count mismatch, protected-field change, pin change, network +change, or unrelated component change is blocking. + +- [ ] **Step 4: Run verification tests including multi-unit fixtures** + +Run: `py -3.12 -m pytest tests/part_replace/test_verification.py -v` + +Expected: all hard-invariant and impact-matrix tests pass. + +- [ ] **Step 5: Commit verification logic** + +```powershell +git add src/dx_productivity/part_replace/verification.py tests/part_replace/test_verification.py +git commit -m "feat: verify part replacements without rewiring" +``` + +### Task 5: Durable Run Store, Project States, and Full Backup + +**Files:** +- Create: `src/dx_productivity/part_replace/run_store.py` +- Create: `tests/part_replace/test_run_store.py` + +**Interfaces:** +- Consumes: protocol atomic writes, `ProjectRef`, `ProjectState`, and snapshot fingerprints. +- Produces: immutable `TreeManifest`; `RunStore.create(root: Path, rules: Sequence[MappingRule], projects: Sequence[ProjectRef]) -> RunStore`, `RunStore.append_event(project_id: str, event: str, payload: Mapping[str, object]) -> None`, `RunStore.transition(project_id: str, target: ProjectState) -> None`, `RunStore.project_state(project_id: str) -> ProjectState`, `fingerprint_tree(root: Path) -> TreeManifest`, `backup_project(project_root: Path, backup_root: Path) -> TreeManifest`, `verify_tree(root: Path, manifest: TreeManifest) -> bool`, and `restore_project(project_root: Path, backup_root: Path, recovery_root: Path, manifest: TreeManifest, closed_confirmed: bool) -> TreeManifest`. + +- [ ] **Step 1: Write failing transition and backup tests** + +```python +def test_invalid_state_transition_is_rejected(run_store: RunStore) -> None: + with pytest.raises(StateError, match="invalid_transition"): + run_store.transition("p1", ProjectState.VERIFIED_SAVED) + + +def test_backup_is_complete_and_manifest_detects_change(tmp_path: Path) -> None: + project = tmp_path / "工程" + (project / "design").mkdir(parents=True) + (project / "design" / "main.sch").write_bytes(b"schematic") + backup = tmp_path / "backup" + manifest = backup_project(project, backup) + assert verify_tree(backup, manifest) + (backup / "design" / "main.sch").write_bytes(b"changed") + assert not verify_tree(backup, manifest) + + +def test_restore_requires_closed_project_and_preserves_failed_tree(tmp_path: Path) -> None: + project, backup, manifest = make_changed_project_and_backup(tmp_path) + with pytest.raises(BackupError, match="project_must_be_closed"): + restore_project(project, backup, tmp_path / "recovery", manifest, + closed_confirmed=False) + failed_manifest = restore_project(project, backup, tmp_path / "recovery", manifest, + closed_confirmed=True) + assert verify_tree(project, manifest) + assert verify_tree(tmp_path / "recovery", failed_manifest) +``` + +- [ ] **Step 2: Run focused tests and verify failure** + +Run: `py -3.12 -m pytest tests/part_replace/test_run_store.py -v` + +Expected: collection fails because `run_store.py` is missing. + +- [ ] **Step 3: Implement append-only state and safe tree copying** + +Allow only the transitions defined by the spec, plus `blocked` from every +non-final state and re-entry from `blocked` to `inventory_pending` after an +explicit reconcile event. Write each event as one canonical JSON line containing +monotonic sequence, UTC timestamp, project ID, prior state, target state, event, +and payload. Rebuild state from the log on open and reject a malformed or +noncontiguous sequence. + +Tree manifests contain normalized relative paths, byte sizes, and SHA-256 hashes +for every regular file. Reject symlinks/reparse points and any relative path that +escapes the project root. Require the backup destination not to exist and not to +be inside the source tree. Copy to a sibling staging directory, verify it, then +rename it to the final backup path. + +Restore requires `closed_confirmed=True`, a canonical target equal to the job +record, and a verified backup. Copy the current failed tree into a new recovery +directory and verify that manifest before replacing project contents from the +backup. Verify the restored tree before reporting success; retain both backup +and recovery trees. + +- [ ] **Step 4: Run state, corruption, path-safety, and backup tests** + +Run: `py -3.12 -m pytest tests/part_replace/test_run_store.py -v` + +Expected: all tests pass, including interruption replay and Unicode paths. + +- [ ] **Step 5: Commit durable run storage** + +```powershell +git add src/dx_productivity/part_replace/run_store.py tests/part_replace/test_run_store.py +git commit -m "feat: persist replacement jobs and verified backups" +``` + +### Task 6: Trial Compatibility Certification + +**Files:** +- Create: `src/dx_productivity/part_replace/certification.py` +- Create: `tests/part_replace/test_certification.py` + +**Interfaces:** +- Consumes: before/after snapshots, `MappingRule`, `VerificationResult`, external-check results, and atomic JSON writes. +- Produces: `interface_fingerprint(snapshot: DesignSnapshot, logical_keys: Sequence[str]) -> str`, `CertificationStore.record(rule: MappingRule, target_fingerprint: str, library_identity: str | None, checks: ExternalChecks) -> Certification`, and `CertificationStore.require(rule: MappingRule, target_fingerprint: str, library_identity: str | None) -> Certification`. + +- [ ] **Step 1: Write failing certification and invalidation tests** + +```python +def test_certification_requires_hard_checks_and_external_checks(store, fixtures) -> None: + with pytest.raises(CertificationError, match="external_checks_incomplete"): + store.record(MappingRule("OLD-1", "NEW-1"), fixtures.target_fingerprint, + "lib-r42", ExternalChecks(packager=True, erc=None, netlist=True)) + + +def test_changed_library_or_target_fingerprint_invalidates(store, certification) -> None: + with pytest.raises(CertificationError, match="certification_mismatch"): + store.require(certification.rule, "different-fingerprint", "lib-r42") + with pytest.raises(CertificationError, match="certification_mismatch"): + store.require(certification.rule, certification.target_fingerprint, "lib-r43") +``` + +- [ ] **Step 2: Run tests and confirm the missing-module failure** + +Run: `py -3.12 -m pytest tests/part_replace/test_certification.py -v` + +Expected: collection fails because `certification.py` does not exist. + +- [ ] **Step 3: Implement immutable certification records** + +Fingerprint only the observed interface: normalized unit/gate identities, +symbol origin, pin number/name/coordinate tuples, and logical unit count. Require +successful hard verification and explicit `True` for Packager, ERC, and netlist. +Store created UTC time, 7.9.5 build, old/new values, target fingerprint, optional +library identity, representative project fingerprint, and evidence paths. + +When library identity is absent, exact target fingerprint is mandatory on every +production Apply. Never expose a force or ignore flag. + +- [ ] **Step 4: Run certification tests** + +Run: `py -3.12 -m pytest tests/part_replace/test_certification.py -v` + +Expected: valid records round-trip and all mismatches fail closed. + +- [ ] **Step 5: Commit certification support** + +```powershell +git add src/dx_productivity/part_replace/certification.py tests/part_replace/test_certification.py +git commit -m "feat: certify safe part replacement pairs" +``` + +### Task 7: Reports and Operator-Facing Difference Output + +**Files:** +- Create: `src/dx_productivity/part_replace/reports.py` +- Create: `tests/part_replace/test_reports.py` + +**Interfaces:** +- Consumes: run-store events, impact cells, verification results, certifications, and project states. +- Produces: immutable `BatchReport`; `write_impact_csv(path: Path, cells: Sequence[ImpactCell]) -> None`, `write_differences_json(path: Path, results: Sequence[VerificationResult]) -> None`, and `write_summary_html(path: Path, report: BatchReport) -> None`. + +- [ ] **Step 1: Write failing escaping and partial-batch tests** + +```python +def test_html_report_escapes_part_numbers_and_has_no_remote_content(tmp_path: Path) -> None: + output = tmp_path / "report.html" + write_summary_html(output, report_with_part_number('