diff --git a/docs/releases/2026-11-12-native-acceptance-validation.json b/docs/releases/2026-11-12-native-acceptance-validation.json new file mode 100644 index 0000000..cb4af05 --- /dev/null +++ b/docs/releases/2026-11-12-native-acceptance-validation.json @@ -0,0 +1,337 @@ +{ + "schema_version": 1, + "created": "2026-11-12T11:32:48", + "overall_acceptance": "NOT_PASSED", + "automatic_icdb_repair": false, + "merged": false, + "issue_closed": false, + "environment": { + "windows": [ + "11", + "10.0.26200", + "SP0", + "Multiprocessor Free" + ], + "python": "3.12.10", + "mentor": "EE7.9.5" + }, + "baseline_commit": "b86e4e315a2ac7d8a3d05587389d0237b6576881", + "candidate": { + "executable": "F:\\CbbAccept-20261112\\candidate-release4\\dist\\CbbRefreshVerify-Background\\CbbRefreshVerify.exe", + "module_count": 62, + "source_and_frozen_code_equal": true, + "source_sha256_checked": true, + "packaged_assets_equal": true, + "exe_icon_images_equal": true, + "executable_sha256": "2ad132e434a8e1de0b61f271aa87215749b0f3174ea0682eb578bc31271e8a4d" + }, + "tests": { + "name": "pytest", + "errors": "0", + "failures": "0", + "skipped": "0", + "tests": "1851", + "time": "382.059", + "timestamp": "2026-11-12T11:20:58.800467+08:00", + "hostname": "Abs" + }, + "compileall_passed": true, + "git_diff_check_passed": true, + "original_integrity": { + "time": "2026-11-12T11:29:23", + "results": [ + { + "scope": "A", + "source": "F:\\Sync Tool Skyworth\\Work Maps\\Skyworth_CBB_Lib\\CBB\\1GPHY_RTL8211F", + "checked": 187, + "changes": [] + }, + { + "scope": "B", + "source": "F:\\Sync Tool Skyworth\\Work Maps\\Skyworth_CBB_Lib\\CBB\\1GPHY_RTL8211F_A", + "checked": 185, + "changes": [] + }, + { + "scope": "field-library-originals", + "source": "F:\\Sync Tool Skyworth\\Work Maps\\Skyworth_CBB_Lib\\Mentor_lib_EE7.9", + "checked": 26887, + "changes": [] + } + ], + "originals_unchanged": true + }, + "native_crud": { + "same_name_update": { + "operation": "update", + "name": "1GPHY_8212", + "stage": "complete", + "status": "UPLOADED", + "safe_to_continue": true, + "detail": "上传已确认;本批次未启用自动校验。" + }, + "remove": { + "operation": "remove", + "name": "1GPHY_8212", + "stage": "complete", + "status": "REMOVED", + "safe_to_continue": true, + "detail": "已由原生操作移除,重新读取目录确认不存在;应用未创建备份。" + }, + "batch_first_safe_failure": { + "operation": "add", + "name": "1GPHY_RTL8211F", + "stage": "complete", + "status": "UPLOAD_FAILED", + "safe_to_continue": true, + "detail": "Native identity exporter failed or reported an error." + }, + "batch_next_added": { + "operation": "add", + "name": "1GPHY_8212", + "stage": "complete", + "status": "UPLOADED", + "safe_to_continue": true, + "detail": "上传已确认;本批次未启用自动校验。" + } + }, + "final_ui_observations": [ + { + "time": "2026-11-12T11:26:17", + "event": "legacy-backup-recovery-result", + "bundle_sha256": "2ad132e434a8e1de0b61f271aa87215749b0f3174ea0682eb578bc31271e8a4d", + "text": [ + "目标 CBB", + "备份工程", + "恢复未通过:备份校验未通过,目标未更改。\nDATABASE_RECOVERY_REQUIRED: 是(&Y) | 否(&N) | If an XDS or ExpeditionPCB is running on this design, it's likely that\nyour file system and/or network system was too slow to determine\nwhich product the design is open in within the 15 second timeout\nperiod.\n\nOtherwise, the design may not have been closed properly due to\nthe XDS or ExpeditionPCB crashing in the last session.\n\nBefore continuing, please confirm that no other users have the\ndesign open.\n\nContinue to open the design with read/write access permission?\n记录:F:\\CbbAccept-20261112\\final-data\\evidence\\backup-restore-90b843115d07\\recovery-result.json" + ], + "target_primary_unchanged": true + }, + { + "time": "2026-11-12T11:27:59", + "event": "final-backup-queue-cancelled", + "bundle_sha256": "2ad132e434a8e1de0b61f271aa87215749b0f3174ea0682eb578bc31271e8a4d", + "text": [ + "目标 CBB", + "备份工程", + "恢复未通过:已取消排队,未启动原生操作。" + ] + }, + { + "time": "2026-11-12T11:28:27", + "event": "summary-release-initial-state", + "bundle_sha256": "2ad132e434a8e1de0b61f271aa87215749b0f3174ea0682eb578bc31271e8a4d", + "enabled": false, + "text": [ + "ICDB 检查结束:未发现异常 0,发现问题 0,占用 0,无法确认 0,取消 1,未执行 0", + "中心库", + "可见 1 / 1 · READY 0 · 异常/待确认 1", + "ICDB 检查结束:未发现异常 0,发现问题 0,占用 0,无法确认 0,取消 1,未执行 0", + "正在执行当前任务…" + ] + }, + { + "time": "2026-11-12T11:28:28", + "event": "summary-release-opened", + "bundle_sha256": "2ad132e434a8e1de0b61f271aa87215749b0f3174ea0682eb578bc31271e8a4d", + "text": [ + "正在检查当前库关联的会话…", + "" + ] + }, + { + "time": "2026-11-12T11:28:34", + "event": "force-warning-cancel", + "bundle_sha256": "2ad132e434a8e1de0b61f271aa87215749b0f3174ea0682eb578bc31271e8a4d", + "text": [ + "仅强制结束以下客户端。客户端中其他已打开工程也会退出;未保存的更改会丢失,正在写入的工程可能需要恢复。\n数据库服务器和归属未知的进程不会被强制结束。\n\n1GPHY_8212 — ExpeditionPCB.exe (PID 21856)\n1GPHY_8212 — ExpeditionPCB.exe (PID 21248)\n\n仍要结束这些进程吗?" + ] + }, + { + "time": "2026-11-12T11:28:59", + "event": "r7-normal-exit", + "bundle_sha256": "2ad132e434a8e1de0b61f271aa87215749b0f3174ea0682eb578bc31271e8a4d", + "exit_code": 0 + } + ], + "backup_recovery": { + "installed": false, + "status": "FAIL", + "detail": "备份校验未通过,目标未更改。\nDATABASE_RECOVERY_REQUIRED: 是(&Y) | 否(&N) | If an XDS or ExpeditionPCB is running on this design, it's likely that\nyour file system and/or network system was too slow to determine\nwhich product the design is open in within the 15 second timeout\nperiod.\n\nOtherwise, the design may not have been closed properly due to\nthe XDS or ExpeditionPCB crashing in the last session.\n\nBefore continuing, please confirm that no other users have the\ndesign open.\n\nContinue to open the design with read/write access permission?", + "target_primary_unchanged": true + }, + "residual": { + "library": "F:\\CbbAccept-20261112\\library\\native-add\\fixture\\mentor_lib.lmc", + "status": "PARTIAL", + "confirmed_scope": [ + { + "name": "ExpeditionPCB.exe", + "pid": 21856, + "release_status": "RELEASED", + "consent_allowed": true + }, + { + "name": "ExpeditionPCB.exe", + "pid": 21248, + "release_status": "RELEASED", + "consent_allowed": true + } + ], + "final_target_clients": 0, + "observed_unconfirmed": [ + { + "name": "viewdraw.exe", + "pid": 29832, + "scope_confirmed": false + }, + { + "name": "cscript.exe", + "pid": 8652, + "scope_confirmed": false + } + ], + "foreign_task_processes_terminated": false, + "lock_or_address_files_deleted": false + }, + "remaining": [ + { + "priority": "P1", + "problem": "Unconfirmed processes from another task still prevent whole-library release proof" + }, + { + "priority": "P2", + "problem": "Release count includes unconsented observation rows that exited independently" + }, + { + "problem": "Native PCB read/write permission prompt prevents successful verify/READY and backup installation" + }, + { + "problem": "Native EDIF exporter crashes for isolated A/B inputs, exit 0xC0000005" + }, + { + "problem": "Some conditional native buttons, field lost-session recovery, Windows 10 remain unaccepted" + } + ], + "evidence": [ + { + "path": "F:\\CbbAccept-20261112\\candidate-release4\\bundle-verification.json", + "bytes": 261, + "sha256": "8dbefef3d8cbd65f3531a1919b11a8bea1b494f01fe63a65ac277e05b572b7de" + }, + { + "path": "F:\\CbbAccept-20261112\\candidate-release4\\source-sha256.json", + "bytes": 8168, + "sha256": "35d9904b515297ab033e3290ae69785fa827e7f3440d1a670e665016c18b28f8" + }, + { + "path": "F:\\CbbAccept-20261112\\full-suite-delivery.xml", + "bytes": 265893, + "sha256": "cb3298e2aa72c5f4899e1b4dc21c88b35b58af6343de5f3d148e6a5acfcba7de" + }, + { + "path": "F:\\CbbAccept-20261112\\desktop-map-red.xml", + "bytes": 11144, + "sha256": "e209aa9aadefec21013ffaa1364c42cf210b3bfb738fb7cc817bd9f39f1aaa5f" + }, + { + "path": "F:\\CbbAccept-20261112\\desktop-map-green.xml", + "bytes": 4929, + "sha256": "1a5b5814bc21d3f739573700f4c93da3b241161124f80ed44d2ee0bcf5f01c39" + }, + { + "path": "F:\\CbbAccept-20261112\\legacy-backup-red.xml", + "bytes": 7828, + "sha256": "6c05be80efcd1430de99a905b9a32aaa29079aedb7cef606a673896bebf200dc" + }, + { + "path": "F:\\CbbAccept-20261112\\legacy-backup-green.xml", + "bytes": 13877, + "sha256": "2a0fc3ddb5b743f2cb2db00a81dc1bc025f76a75a5c6099f667e3461a555d49b" + }, + { + "path": "F:\\CbbAccept-20261112\\summary-release-red.xml", + "bytes": 3116, + "sha256": "3dcec893e4d3dca47d8d48bd8e83752f8a3860da09195c40429d1841bf6b9a6b" + }, + { + "path": "F:\\CbbAccept-20261112\\summary-release-green.xml", + "bytes": 10321, + "sha256": "f8beefdea1b616d6459f4e12becdbdac633b4650f487332627d5e54c85518ce6" + }, + { + "path": "F:\\CbbAccept-20261112\\originals-rechecked.json", + "bytes": 632, + "sha256": "693155ed50d18af7d9ae1bda41a696d25687b486541fc0e9df9956e7dbfe7653" + }, + { + "path": "F:\\CbbAccept-20261112\\final-native-inspection.json", + "bytes": 22288, + "sha256": "038a635a8bd3e5d5de5eb4ad73125b12bbd1416d53a8f27ebe014e2a6bb84536" + }, + { + "path": "F:\\CbbAccept-20261112\\r7-accept.log", + "bytes": 25203, + "sha256": "ceca1412c2df483f4290e7131c587af5de16d30874f23a588f53d32db432f9e7" + }, + { + "path": "F:\\CbbAccept-20261112\\final-data\\management\\management-741e463dc75d4f35acd992ad42200fbf\\checkpoint.json", + "bytes": 3547, + "sha256": "7fe68525e01d8e35bacb2bc84cdc4fa1469bb599f40bd6a77dcad7a6725bce24" + }, + { + "path": "F:\\CbbAccept-20261112\\final-data\\management\\management-d83e404f22864885ab57943783897ebe\\checkpoint.json", + "bytes": 11411, + "sha256": "6928ef7a8d9664da7ee209afeb280c61fd081f5d207ef8686ebf09ad57d8140a" + }, + { + "path": "F:\\CbbAccept-20261112\\final-data\\management\\management-a900d2b62a544623b499ce55d099dfd2\\checkpoint.json", + "bytes": 1140, + "sha256": "dc0725ff0db339f81be5af021925396cba50f303cfea5c0aa2370a8deff18486" + }, + { + "path": "F:\\CbbAccept-20261112\\final-data\\management\\management-c8a18e3bb8bc4aa19f7dbc982b3602d2\\checkpoint.json", + "bytes": 11652, + "sha256": "d09ad8d7b88e7ba607ddb34cac523ef8074f5d3f43fe2f033c35125629bc251c" + }, + { + "path": "F:\\CbbAccept-20261112\\final-data\\evidence\\backup-restore-90b843115d07\\recovery-result.json", + "bytes": 3901, + "sha256": "df44ea3f2d01ace1189c2c5f93af8c67abc6c196cf2ba8e99318d222a582c58a" + }, + { + "path": "F:\\CbbAccept-20261112\\final-data\\release-checks\\sessions-346da47efa8d\\result.json", + "bytes": 8947, + "sha256": "743fc764021ac8fc22d6f799f4f9663d704d0fd6c41aafd14409666e85747900" + }, + { + "path": "F:\\CbbAccept-20261112\\step-restore_execute.py.log", + "bytes": 4134, + "sha256": "a6da200bd6a3895d60ae85eac419b440696a5b9b5503856990782ed04f1f9795" + }, + { + "path": "F:\\CbbAccept-20261112\\r5-batch-add-result.png", + "bytes": 75306, + "sha256": "a812edf98f2a96ce4c1f5cd218c9ec0b045e94538af11dbd65c35db799e03e2d" + }, + { + "path": "F:\\CbbAccept-20261112\\r5-release-result-1.png", + "bytes": 44151, + "sha256": "a916a2080504201902c5d873fc3d7913e47804b7c5e1aa410a8ef8f778e759b5" + }, + { + "path": "F:\\CbbAccept-20261112\\r7-summary-release-initial-state.png", + "bytes": 11891, + "sha256": "d13236159a38adf8030d84a66f59db4269cba471f305e835918cf1e4f86b7397" + }, + { + "path": "F:\\CbbAccept-20261112\\r7-summary-release-opened.png", + "bytes": 87863, + "sha256": "a77e0169e7dce2f25f5f3343afa73af75418837987bb7561c24dca18485e3627" + }, + { + "path": "F:\\CbbAccept-20261112\\r7-final-release-result.png", + "bytes": 88350, + "sha256": "1b504c4b0c42c18cdbc73bc58b5aa716cde43cb0330106b07fc7cb5e40c7a514" + } + ] +} diff --git a/docs/releases/2026-11-12-native-acceptance.md b/docs/releases/2026-11-12-native-acceptance.md new file mode 100644 index 0000000..14c3dcf --- /dev/null +++ b/docs/releases/2026-11-12-native-acceptance.md @@ -0,0 +1,72 @@ +# 2026-11-12 冻结程序与 Mentor 原生验收 + +**结论:未通过整体验收,不合并发布、不关闭工单。** + +本轮实际运行冻结 EXE、Mentor EE7.9.5、原生 COM/命令和私有桌面窗口;点击使用真实 UIA/Win32 控件,没有替换业务服务、伪造原生结果或抢占前台鼠标。此前 48 按钮 Qt 模拟结果不计为本次原生验收。 + +最终候选包:`F:\CbbAccept-20261112\candidate-release4\dist\CbbRefreshVerify-Background\CbbRefreshVerify.exe`。 +SHA-256:`2ad132e434a8e1de0b61f271aa87215749b0f3174ea0682eb578bc31271e8a4d`。 +冻结档案中的 62 个模块逐一与源代码编译结果相符;打包资产及 EXE 图标与当前源图标相符。 +原始记录、截图、失败尝试和各轮候选包保存在 `F:\CbbAccept-20261112`,便于核对本报告中的具体测试轮次。 + +## 隔离范围与原件核对 + +- 原生创建独立空库 `library\native-add\fixture\mentor_lib.lmc`,随后实际新增、更新和移除测试 CBB。 +- 另复制现场库的共享依赖及四个工程到 `field-lib`:26,887 个文件,815,607,385 字节。该库实际读取到四个 READY 项。 +- 独立来源 A/B 的库引用原指向不可用的 S 盘,仅对隔离副本改为测试库;原工程未改。 +- 验收结束重新核对原件:A 的 187 个主要文件、B 的 185 个主要文件、复制现场库所对应的 26,887 个原文件,大小及 SHA-256 均未改变。见 `originals-rechecked.json`。 +- 完整旧 Work 已人工保留到 `manual-old-work`;应用管理操作继续采用手动备份提示,没有新增自动整库备份。 +- 原生进程只使用正常关闭/取消。强制结束的确认窗口实际打开后选择了取消;没有强制结束其他工具的进程,也没有删除地址或锁文件。 + +## 实际发现并修改的六处问题 + +| 问题 | 修改 | 实际复测及边界 | +| --- | --- | --- | +| 导出器退出期间 OpenProcess 返回 5,立即被当成释放失败 | 5/87 均继续观测;只有新快照无目标、已取得句柄退出且数据库探测通过才放行 | R3 同名更新、R5 新增及同批失败续跑;真实活动进程和数据库占用仍拒绝放行 | +| 另一个工程无 PRJ 参数的 viewdraw 阻止备份入口 | 备份空闲检查结合目标路径、地址及实际独占读探测,不再单凭未知命令阻止 | R7 中其他 DxDesigner 仍运行,备份进入隔离库及原生校验;这不等于下面的整库释放问题已解决 | +| 原生导入不保留历史 `sAddress_.adr`,被误报内容不一致 | 将其与 `sAddress.adr` 一起排除在主要内容哈希之外,规则版本升为 2,完整复制仍保留 | R3 更新 `UPLOADED`,原理图 ASCII/CSV/EDIF、布局与注册内容一致;R5 再新增成功 | +| 外部私有桌面的 GetThreadDesktop 返回拒绝访问,重新 OpenDesktop 后 HWND 还不可读 | 对失败 PID 枚举当前窗口站的桌面;打开桌面后先枚举窗口,再核对 PID 并发送关闭/取消 | R5 原先残留的 PCB 启动器/客户端两个真实进程正常退出,获得 RELEASE_CONFIRMED;R6/R7 同类客户端也退出 | +| 恢复入口强制要求旧格式工程没有的辅助 `PCB/pcb.prj` | 复用既有工程身份检查;PCB 必须唯一关联所选主 PRJ,数据库与布局仍必需 | R5 原包拒绝;R7 新包进入隔离复制和真实 PCB 校验。原生读写确认仍导致校验失败,目标主要文件未改,未安装备份 | +| ICDB 结果窗口在前台任务忙时仍允许点击释放,处理函数却直接返回 | 结果按钮跟随执行状态;目标库因保留会话而排队时使用排队释放入口 | R6 实际点击无窗口;R7 同样操作时按钮先禁用,随后恢复,点击成功打开释放窗口。排队入口另有回归覆盖 | + +## 实际按钮与流程结果 + +| 入口/动作 | 观察结果 | 验收判断 | +| --- | --- | --- | +| 选择库、读取、三个菜单、搜索/筛选、选择可见项/清空选择 | 空库、一个 PENDING、四个 READY 的真实数据可读取和操作;READY 不进入维护入口 | 已覆盖这些真实数据场景;381/3,000 项响应测试仍仅是此前模拟 | +| 高级设置及原生 Verify 开关 | 展开、收起、切换和还原成功 | 仅验证控件;Win10 原生 Verify 运行未验收 | +| 查看运行日志、打开日志目录 | 实际点击可用 | 已覆盖 | +| 已选校验、可见非 READY 校验 | 前者实际运行;后者确认后取消,没有执行写入 | 已选校验未通过,不能报告 READY | +| 检查中提交普通校验 | UI 可用、确认成功、显示排队;检查结束后实际启动普通 PCB 校验 | 排队行为通过;校验本身失败 | +| ICDB 批量检查(取消确认/完整执行/停止/再次使用) | 完整检查约 38 秒;读写确认不含 ICDB 错误,归类为无法确认;停止后可重新使用,可能留下客户端供确认释放 | 未执行自动 Repair;不能视为现场修复通过 | +| 版本历史与备份 | 从应用打开真实原生窗口,读取五个备份;创建 User 备份,再从原生 Restore 对话框恢复所选备份 | 原生输出 `Backup restored successfully.`;关闭后 CLOSED、safe=true,应用按钮恢复。证据为 R3 原生工具操作 | +| 从备份恢复(无效来源、取消确认、重复点击) | 无效输入拒绝;取消不启动;执行后按钮禁用,重复点击未重复启动 | 已覆盖 | +| 恢复排队、取消排队 | R6/R7 在检查期间提交,显示排队;取消后明确未启动原生操作 | 已覆盖 | +| 旧格式备份完整恢复 | R7 通过格式/复制检查,在隔离库打开 PCB 时被读写确认拦下 | **未完成恢复**;installed=false、目标主要文件不变,保留证据 | +| 用工程替换已选 CBB | R3 实际 Remove → 原生缺项复读 → Add → 内容比对 → 目录复读 | UPLOADED、safe=true;关闭自动校验,不等于 READY | +| 移除 | R5 原生 CleanWGLib 返回成功;独立目录读取为空,应用读取 0 项 | REMOVED、safe=true | +| 多来源新增 | 同批 A 的 EDIF 导出失败、safe=true;随后 C 实际新增成功;独立复读只有 C | 未因首项安全失败而停止整批 | +| 重复名称新增 | 实际拒绝;独立复读的条目、工程身份不变 | 已覆盖 | +| 管理执行确认取消、再次确认、连续点击执行 | 取消后可重新确认;运行时禁用执行,重复点击不创建第二项 | 新增、更新、移除均有真实操作记录 | +| 查看原生提示、重新检查、确认释放、关闭 | 窗口和提示可读;本工具两个 PCB 进程正常退出 | R5 完整释放通过;R6/R7 仍被下面的跨任务观察项阻止整库确认 | +| 强制结束客户端 | 确认名单只列两个本库 PCB,点击取消后继续正常释放 | 仅确认/取消路径通过,实际强制终止未执行 | +| 主程序退出 | R3/R4/R5/R6/R7 正常退出,末次退出码 0 | 不将退出应用造成的内存释放算作整库释放功能通过 | + +**仍未实际触发的条件按钮**:处理 PCB 未保存更改的保存/放弃选择、活动原生备份的“请求原生取消”、管理批次“当前项结束后停止”、实际强制终止、ICDB 特征错误后的工程副本重导入、成功安装备份后的再次打开并 READY。它们的 Qt/回归测试不能替代原生验收;不宣称每一个按钮的所有原生分支都已通过。 + +## 未解决的验收卡点 + +1. **P1:未确认归属的其他任务仍能阻止整库释放。** R7 `sessions-346da47efa8d/result.json` 中,确认允许的 PCB PID 21856/21248 均 RELEASED,但另一个私有桌面上的 viewdraw PID 29832 为 scope_confirmed=false、consent_allowed=false、WAITING,整体仍 PARTIAL。末次检查还观察到其他工具的 cscript;没有本库确认所属的客户端残留。原因在于 `residual_sessions._release_residual_sessions` 要求全部观察项 RELEASED,随后 `library_lock._prove_library_released` 也把无法确定路径的进程当成候选占用。不能要求关闭其他任务来通过本库验收。后续需要将观察项与可操作目标分开,并用本库数据库/地址/独占句柄及在途调用证明决定能否继续;同时覆盖真实持有本库数据库时仍必须拒绝的场景。本轮未修改此判定。 +2. **P2:释放数量混入自然退出的观察项。** R7 显示“已释放 4 个会话,确认允许 2 项”;另两个未允许项在操作期间自行退出,不能让用户误以为工具主动关闭了四项。 +3. **原生 PCB 读写确认尚未走通。** `DATABASE_RECOVERY_REQUIRED` / `DATABASE_SAFETY_STOP` 的正文要求确认没有其他用户后以读写权限继续,未直接提供 ICDB 损坏证据。检查、普通校验和备份副本校验均未获得 READY;不能自动同意写入后宣称通过。 +4. **输入兼容性:A/B 的原生 EDIF 导出崩溃。** 退出码 3221225477(0xC0000005),本机 WER 指向 MSVCR90.dll;相同环境下 C 的三种导出均成功。A/B 继续报告上传失败,不跳过身份校验伪造成功。 +5. 现场服务器会话失联的一致故障副本完整入口、Windows 10、自动修复仍未验收。ICDB 自动 Repair 保持关闭。 + +## 复核依据 + +- 最终源代码:1,851 项 Python 测试通过,1 条 pywinauto COM 警告;`full-suite-delivery.xml`。编译检查及 `git diff --check` 通过。 +- 回归保留修复前失败与修复后通过记录:`export-race-*`、`pathless-red.xml`、`address-manifest-*`、`desktop-map-*`、`legacy-backup-*`、`summary-release-*`。 +- R3 同名更新:`final-data/management/management-741e463dc75d4f35acd992ad42200fbf/checkpoint.json`。 +- R5 移除:`management-d83e404f22864885ab57943783897ebe`;同批失败:`management-a900d2b62a544623b499ce55d099dfd2`;同批继续新增:`management-c8a18e3bb8bc4aa19f7dbc982b3602d2`。 +- R7 恢复:`final-data/evidence/backup-restore-90b843115d07/recovery-result.json`。R7 释放按钮状态、原生提示、取消强制结束、最终释放及退出见 `r7-accept.log` 和对应截图。 +- 机器可读索引和指定证据摘要哈希见同目录 `2026-11-12-native-acceptance-validation.json`。大体积原始工程和运行时控制记录保留在本机,不纳入提交。 diff --git a/src/cbb_refresh_verify/backup_recovery.py b/src/cbb_refresh_verify/backup_recovery.py index b06d3ff..9b3d35b 100644 --- a/src/cbb_refresh_verify/backup_recovery.py +++ b/src/cbb_refresh_verify/backup_recovery.py @@ -41,8 +41,8 @@ def _idle_check(library, project, pcb): match = _native_scope_match(command, roots=scope, files=(library, project, pcb)) if match is True: raise ValueError(f'TARGET_NATIVE_OWNER_ACTIVE: 目标工程或共享库有原生会话,PID={pid}') - if match is None: - raise ValueError(f'TARGET_NATIVE_OWNER_UNCONFIRMED: 无法确认原生会话所属工程,PID={pid}') + # Pathless clients do not identify this target. The address and + # exclusive file probes below still reject actual target occupancy. addresses = unreleased_addresses(library, project, pcb) if addresses: raise ValueError(f'TARGET_DATABASE_ADDRESS_UNCONFIRMED: 地址记录需原生确认;未据此判定正在占用:{addresses}') @@ -110,14 +110,15 @@ def _source_check(source, name, original): if not pcb.is_relative_to(source.parent.resolve()): raise ValueError('备份 PCB 引用越出工程目录。') if not all(path.is_file() for path in (pcb, pcb.parent/'Layout/LayoutDB.lyt', - pcb.parent/'pcb.prj', source.parent/'database/icdb.dat')): - raise ValueError('备份不完整:需要原理图数据库、PCB、布局数据库和 PCB 工程文件。') + source.parent/'database/icdb.dat')): + raise ValueError('备份不完整:需要原理图数据库、PCB 和布局数据库。') project_refs = re.findall(r'^KEY ProjectFile "([^"]+)"', _project_text(pcb), re.M) for value in project_refs: require_relative(value) if len(project_refs) != 1 or (pcb.parent/project_refs[0]).resolve() != source.resolve(): raise ValueError('备份 PCB 必须引用所选工程,不能引用其他位置的工程。') - for project in (source, pcb.parent/'pcb.prj'): + from .maintenance_entry import maintenance_project_files + for project in maintenance_project_files(source, pcb): data = _project_text(project) for value in re.findall(r'^KEY iCDBDir "([^"]+)"', data, re.M): require_relative(value) diff --git a/src/cbb_refresh_verify/native_engineering_identity.py b/src/cbb_refresh_verify/native_engineering_identity.py index 33ccedf..e027ca8 100644 --- a/src/cbb_refresh_verify/native_engineering_identity.py +++ b/src/cbb_refresh_verify/native_engineering_identity.py @@ -354,7 +354,11 @@ def _run_exports(project, root, mentor_home, timeout_seconds): if owner['pid'] not in handles: try: handles[owner['pid']] = win32api.OpenProcess(win32con.SYNCHRONIZE, False, owner['pid']) except pywintypes.error as error: - if error.winerror != 87: raise + if error.winerror not in (5, 87): raise + # A dying process can deny OpenProcess. Keep it in + # owners until a fresh snapshot proves it absent. + record.setdefault('process_observation_errors', {})[str(owner['pid'])] = { + 'winerror': error.winerror, 'detail': str(error)} record['observed_pids'] = sorted(descendants | handles.keys()) identities.update({owner['pid']: {key: owner.get(key, '') for key in ('pid', 'created', 'executable')} diff --git a/src/cbb_refresh_verify/residual_sessions.py b/src/cbb_refresh_verify/residual_sessions.py index 8d02341..c9100d6 100644 --- a/src/cbb_refresh_verify/residual_sessions.py +++ b/src/cbb_refresh_verify/residual_sessions.py @@ -181,10 +181,81 @@ def _window_error(snapshot, pid): return getattr(snapshot, 'incomplete', {}).get(pid) +def _desktop_names(): + import ctypes + from ctypes import wintypes + user = ctypes.WinDLL('user32', use_last_error=True) + callback_type = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.LPWSTR, wintypes.LPARAM) + user.GetProcessWindowStation.restype = wintypes.HANDLE + user.EnumDesktopsW.argtypes = [wintypes.HANDLE, callback_type, wintypes.LPARAM] + names = [] + @callback_type + def collect(name, _): + names.append(name) + return len(names) <= 128 + ctypes.set_last_error(0) + if not user.EnumDesktopsW(user.GetProcessWindowStation(), collect, 0) or len(names) > 128: + raise OSError('无法完整枚举当前 Windows 窗口站桌面') + return names + + +@contextmanager +def _window_desktop(name, *, write=False): + """Keep the desktop accessible while reading or messaging its HWNDs.""" + if not name: + yield None + return + import ctypes + from ctypes import wintypes + user = ctypes.WinDLL('user32', use_last_error=True) + user.OpenDesktopW.argtypes = [wintypes.LPCWSTR, wintypes.DWORD, wintypes.BOOL, wintypes.DWORD] + user.OpenDesktopW.restype = wintypes.HANDLE + user.CloseDesktop.argtypes = [wintypes.HANDLE] + desktop = user.OpenDesktopW(name, 0, False, 1 | (128 if write else 0)) + if not desktop: + raise ctypes.WinError(ctypes.get_last_error()) + try: + # OpenDesktop alone does not map a foreign desktop's HWNDs into this + # process. Enumerate while its handle stays open before any ownership + # checks or messages; otherwise GetWindowThreadProcessId returns 0. + _desktop_windows(desktop) + yield desktop + finally: + user.CloseDesktop(desktop) + + +def _desktop_windows(desktop): + import ctypes + from ctypes import wintypes + user = ctypes.WinDLL('user32', use_last_error=True) + callback_type = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM) + user.EnumDesktopWindows.argtypes = [wintypes.HANDLE, callback_type, wintypes.LPARAM] + windows = [] + @callback_type + def collect(hwnd, _): + windows.append(int(hwnd)) + return len(windows) <= 4096 + ctypes.set_last_error(0) + complete = user.EnumDesktopWindows(desktop, collect, 0) + error = ctypes.get_last_error() + # Windows also returns zero with ERROR_SUCCESS for an empty desktop. + if (not complete and (error or windows)) or len(windows) > 4096: + raise OSError('无法完整读取原生桌面窗口') + return windows + + +def _post_window_message(window, hwnd, pid, message): + import win32gui, win32process + with _window_desktop(window.get('desktop', ''), write=True): + if win32process.GetWindowThreadProcessId(hwnd)[1] != pid: + raise ValueError('窗口归属已变化,未发送请求') + win32gui.PostMessage(hwnd, message, 0, 0) + + def _process_windows(pids): result = _WindowSnapshot(pids) if not pids: return result - import win32api, win32con, win32gui, win32process, win32service + import win32api, win32con, win32gui, win32process from .native_repair_ui import _native_output observed = set() def capture(hwnd, _, *, pid, desktop_name): @@ -218,7 +289,7 @@ def _process_windows(pids): except Exception as error: result.incomplete = {pid: str(error)[:500] for pid in pids} return result - desktops = {} + desktops, unresolved = {}, set() for pid in pids: if not threads.get(pid): result.incomplete[pid] = '进程线程已退出或暂时无法读取' @@ -228,31 +299,36 @@ def _process_windows(pids): if desktop: desktops.setdefault(desktop, set()).add(pid) except Exception as error: - result.incomplete.setdefault(pid, str(error)[:500]) - if not any(pid in members for members in desktops.values()): + unresolved.add(pid) + if pid not in unresolved and not any(pid in members for members in desktops.values()): result.incomplete.setdefault(pid, '窗口所属桌面暂时无法确认') - # EnumThreadWindows silently omits windows on other desktops. Enumerate - # only desktops actually assigned to the target processes' threads. - for name, members in desktops.items(): - desktop = None + if unresolved: + # Native PCB threads can deny GetThreadDesktop even when their named + # desktop is readable. Complete a bounded station scan for those PIDs. try: - desktop = win32service.OpenDesktop(name, 0, False, win32con.DESKTOP_READOBJECTS) - win32api.SetLastError(0) - for hwnd in desktop.EnumDesktopWindows(): - pid = None - try: - pid = win32process.GetWindowThreadProcessId(hwnd)[1] - if pid in members: - capture(hwnd, None, pid=pid, desktop_name=name) - except Exception as error: - for affected in (members if pid is None else {pid} & members): - result.incomplete.setdefault(affected, str(error)[:500]) + names = _desktop_names() + if not names: raise OSError('当前窗口站未返回桌面') + for name in names: + desktops.setdefault(name, set()).update(unresolved) + except Exception as error: + for pid in unresolved: + result.incomplete.setdefault(pid, str(error)[:500]) + # Filter by PID before reading window data, including on fallback desktops. + for name, members in desktops.items(): + try: + with _window_desktop(name) as desktop: + for hwnd in _desktop_windows(desktop): + pid = None + try: + pid = win32process.GetWindowThreadProcessId(hwnd)[1] + if pid in members: + capture(hwnd, None, pid=pid, desktop_name=name) + except Exception as error: + for affected in (members if pid is None else {pid} & members): + result.incomplete.setdefault(affected, str(error)[:500]) except Exception as error: for pid in members: result.incomplete.setdefault(pid, str(error)[:500]) - finally: - if desktop is not None: - desktop.CloseDesktop() return result @@ -407,7 +483,7 @@ def inspect_residual_sessions(library, *, block_names=()): def _request_close(row, *, stop=None): - import win32con, win32event, win32gui, win32process + import win32con, win32event with _process_handle(row['pid']) as handle: if win32event.WaitForSingleObject(handle, 0) == win32con.WAIT_OBJECT_0: return {'release_status': 'RELEASED', 'detail': '已退出'} @@ -422,9 +498,10 @@ def _request_close(row, *, stop=None): from .failed_session import _startup_snapshot, _cancel_target for window in windows: if window['class'] != '#32770': continue - target = _cancel_target(_startup_snapshot(window['hwnd'], row['pid'])) + with _window_desktop(window.get('desktop', '')): + target = _cancel_target(_startup_snapshot(window['hwnd'], row['pid'])) if target: - win32gui.PostMessage(target[1].handle, win32con.BM_CLICK, 0, 0) + _post_window_message(window, target[1].handle, row['pid'], win32con.BM_CLICK) deadline = time.monotonic()+3 while time.monotonic() < deadline: if win32event.WaitForSingleObject(handle, 100) == win32con.WAIT_OBJECT_0: @@ -441,9 +518,7 @@ def _request_close(row, *, stop=None): if target is None: return {'release_status': 'WAITING', 'detail': detail} if stop is not None and stop.is_set(): return {'release_status': 'CANCELLED', 'detail': '已停止释放'} - if win32process.GetWindowThreadProcessId(target['hwnd'])[1] != row['pid']: - return {'release_status': 'IDENTITY_CHANGED', 'detail': '窗口归属已变化,未关闭'} - win32gui.PostMessage(target['hwnd'], win32con.WM_CLOSE, 0, 0) + _post_window_message(target, target['hwnd'], row['pid'], win32con.WM_CLOSE) deadline = time.monotonic()+3 while time.monotonic() < deadline: if win32event.WaitForSingleObject(handle, 100) == win32con.WAIT_OBJECT_0: @@ -492,7 +567,7 @@ def _finish_library_release(library, evidence): def _request_native_cancel(row, *, stop=None): """Only click the exact currently visible Cancel control the user confirmed.""" - import win32con, win32gui, win32process + import win32con if row.get('scope_confirmed') is not True: raise ValueError('取消目标归属未确认,请重新检查') fresh = next((r for r in query_process_snapshot() if r['pid'] == row['pid']), None) @@ -510,11 +585,9 @@ def _request_native_cancel(row, *, stop=None): if not prompt or prompt != row.get('cancel_prompt'): raise ValueError('原生取消按钮已变化,请重新检查') button = prompt['button'] - if win32process.GetWindowThreadProcessId(button['hwnd'])[1] != row['pid']: - raise ValueError('原生取消按钮归属已变化') if stop is not None and stop.is_set(): return {'release_status': 'CANCELLED', 'detail': '已停止,未请求原生取消'} - win32gui.PostMessage(button['hwnd'], win32con.BM_CLICK, 0, 0) + _post_window_message(prompt, button['hwnd'], row['pid'], win32con.BM_CLICK) return {'release_status': 'WAITING', 'detail': '已请求原生取消,需重新检查实际结果;未强制结束'} @@ -686,7 +759,7 @@ def answer_save_question(row, choice): def _answer_save_question(row, choice): - import win32con, win32gui + import win32con fresh = next((r for r in query_process_snapshot() if r['pid'] == row['pid']), None) if fresh is None or any(fresh.get(k) != row.get(k) for k in ('created', 'command', 'executable')): raise ValueError('进程已变化,请重新检查') @@ -698,7 +771,4 @@ def _answer_save_question(row, choice): if not prompt or prompt != row.get('prompt'): raise ValueError('原生提示已变化,请重新检查') button = prompt['buttons'][choice] - import win32process - if win32process.GetWindowThreadProcessId(button['hwnd'])[1] != row['pid']: - raise ValueError('保存按钮归属已变化') - win32gui.PostMessage(button['hwnd'], win32con.BM_CLICK, 0, 0) + _post_window_message(prompt, button['hwnd'], row['pid'], win32con.BM_CLICK) diff --git a/src/cbb_refresh_verify/scoped_manifest.py b/src/cbb_refresh_verify/scoped_manifest.py index ab1015c..9df40c9 100644 --- a/src/cbb_refresh_verify/scoped_manifest.py +++ b/src/cbb_refresh_verify/scoped_manifest.py @@ -15,14 +15,14 @@ import stat MANIFEST_VERSION = 1 -MANIFEST_RULE_VERSION = 1 +MANIFEST_RULE_VERSION = 2 _ROOT_RUNTIME_PREFIX = 'work.before-restore-' _ROOT_RUNTIME_PATH = ('projectbackup', 'backups') _NATIVE_RUNTIME_DIRECTORIES = ('log', 'dbcheck', 'dbrestore') _NATIVE_SERVER_DIRECTORY = 'cdbsvr' _PROJECT_PCB_DIRECTORY = 'pcb' _PROJECT_DATABASE_PREFIXES = (('database',), (_PROJECT_PCB_DIRECTORY, 'database')) -_NONPRIMARY_FILENAMES = ('saddress.adr',) +_NONPRIMARY_FILENAMES = ('saddress.adr', 'saddress_.adr') _NONPRIMARY_FILENAME_PREFIXES = ('~$',) _NONPRIMARY_DIRECTORIES = frozenset({ 'log', 'logs', 'temp', 'tmp', '__pycache__', 'backup', 'backups', diff --git a/src/cbb_refresh_verify/ui/main_window.py b/src/cbb_refresh_verify/ui/main_window.py index 52e54e8..9b2af5c 100644 --- a/src/cbb_refresh_verify/ui/main_window.py +++ b/src/cbb_refresh_verify/ui/main_window.py @@ -422,6 +422,12 @@ class MainWindow(QWidget): waiting_library = self._queued_release_library() self.queue_release_button.setVisible(waiting_library is not None) self.queue_release_button.setEnabled(waiting_library is not None and not self._closing) + for task in self.icdb_tasks: + action = getattr(task, 'release_action', None) + if action is not None and isValid(action): + queued_target = bool(waiting_library and _library_path_keys(waiting_library, task.path_lease) + & _library_path_keys(task.requests[0].lmc_file, task.path_lease)) + action.setEnabled(not self._closing and (not self.busy or queued_target)) reasons = [] for operation, widget in (('add', self.add_button), ('update', self.update_button), ('remove', self.remove_button)): reason = self._management_block_reason(operation) @@ -988,8 +994,9 @@ class MainWindow(QWidget): & _library_path_keys(self.mentor_lmc_path or self.loaded_path, self.library_lease)): self.status_label.setText(f'请切回 {task.requests[0].lmc_file} 后释放该检查的残留。') return - self.check_library_release() - summary.addButton('查看残留并释放…', QMessageBox.ActionRole).clicked.connect(release_task) + self.check_library_release(queued=self.busy) + task.release_action = summary.addButton('查看残留并释放…', QMessageBox.ActionRole) + task.release_action.clicked.connect(release_task) if offers: action = summary.addButton('选择副本恢复…', QMessageBox.ActionRole) task.recovery_action = action diff --git a/tests/test_background_icdb.py b/tests/test_background_icdb.py index bf79d62..da9507f 100644 --- a/tests/test_background_icdb.py +++ b/tests/test_background_icdb.py @@ -85,3 +85,28 @@ def test_later_management_invalidates_old_recovery_offer(qtbot, tmp_path, monkey assert action.isEnabled() window._invalidate_check_targets('test.lmc', ['Beta']) assert not action.isEnabled() and not window._reimport_offers + + +def test_check_release_action_tracks_busy_and_retained_queue(qtbot, tmp_path, monkeypatch): + from test_ui_filters import load_window + from test_review326_queue_guidance import retain + from cbb_refresh_verify.verify_runner import VerifyResult + window = load_window(qtbot, tmp_path, monkeypatch, + verifier=lambda _: VerifyResult('FAIL', safe_to_continue=False)) + window._run(['Beta'], maintenance=True) + qtbot.waitUntil(lambda: not window._icdb_active()) + action = next(b for b in window.icdb_summary.buttons() if '释放' in b.text()) + window.busy = True + window._update() + assert not action.isEnabled(), 'A normal native call cannot admit release yet' + retain(monkeypatch, window.mentor_lmc_path) + window._queue_wait_library = window.mentor_lmc_path + window._update() + assert action.isEnabled(), 'Retained-queue release must stay reachable' + opened = [] + monkeypatch.setattr(window, 'check_library_release', lambda **kwargs: opened.append(kwargs)) + action.click() + assert opened == [{'queued': True}] + window.busy = False + window._update() + assert action.isEnabled() diff --git a/tests/test_backup_recovery.py b/tests/test_backup_recovery.py index d2c1243..b9dfffc 100644 --- a/tests/test_backup_recovery.py +++ b/tests/test_backup_recovery.py @@ -71,6 +71,31 @@ def test_invalid_source_does_not_touch_target(recovery_files): assert (original.parent/'database/icdb.dat').read_bytes() == b'damaged' +@pytest.mark.parametrize('linked_to_target', [True, False]) +def test_legacy_backup_without_auxiliary_pcb_project(recovery_files, linked_to_target): + from cbb_refresh_verify.backup_recovery import recover_from_backup + request, original, source = recovery_files + (source.parent/'PCB/pcb.prj').unlink() + if not linked_to_target: + pcb = source.parent/'PCB/A.pcb' + pcb.write_text(pcb.read_text().replace('A.prj', 'OTHER.prj')) + calls = [] + def verify(req, **kwargs): + work = req.lmc_file.parent/'ReusableBlocksLP/A/Work' + assert not (work/'PCB/pcb.prj').exists() + calls.append(req) + return VerifyResult('PASS', library_flag='GREEN') + result = recover_from_backup(request, source, verifier=verify, idle_check=lambda *_: None) + if linked_to_target: + assert result.status == 'PASS', result.stderr + assert len(calls) == 2 + assert (original.parent/'database/icdb.dat').read_bytes() == b'healthy' + else: + assert result.status == 'BLOCKED' + assert not calls + assert (original.parent/'database/icdb.dat').read_bytes() == b'damaged' + + def test_unusable_backup_never_replaces_target(recovery_files): from cbb_refresh_verify.backup_recovery import recover_from_backup request, original, source = recovery_files @@ -177,6 +202,37 @@ def test_idle_guard_rejects_exact_target_process(recovery_files, monkeypatch): _idle_check(request.lmc_file, original, target) +@pytest.mark.parametrize('target_state', ['idle', 'open_file', 'address']) +def test_pathless_external_client_uses_target_resource_proof(recovery_files, monkeypatch, target_state): + import pywintypes + import win32con + import win32file + from cbb_refresh_verify import mentor_adapter + from cbb_refresh_verify.backup_recovery import _idle_check + request, original, _ = recovery_files + monkeypatch.setattr(mentor_adapter, '_process_details', lambda name: + [(123, 'viewdraw.exe', 'viewdraw.exe', 0)] if name == 'viewdraw.exe' else []) + address = original.parent/'database/cdbsvr/sAddress.adr' + handle = None + try: + if target_state == 'open_file': + handle = win32file.CreateFile(str(request.lmc_file), win32con.GENERIC_READ, + win32con.FILE_SHARE_READ, None, win32con.OPEN_EXISTING, 0, None) + with pytest.raises(pywintypes.error) as error: + _idle_check(request.lmc_file, original, original.parent/'PCB/A.pcb') + assert error.value.winerror == 32 + elif target_state == 'address': + address.parent.mkdir(parents=True, exist_ok=True) + address.write_bytes(b'live or unconfirmed native address') + with pytest.raises(ValueError, match='TARGET_DATABASE_ADDRESS_UNCONFIRMED'): + _idle_check(request.lmc_file, original, original.parent/'PCB/A.pcb') + assert address.read_bytes() == b'live or unconfirmed native address' + else: + _idle_check(request.lmc_file, original, original.parent/'PCB/A.pcb') + finally: + if handle is not None: handle.Close() + + def test_prelaunch_recovery_rejection_has_no_unreleased_session(recovery_files): from cbb_refresh_verify.backup_recovery import recover_from_backup request, _, source = recovery_files diff --git a/tests/test_native_engineering_identity.py b/tests/test_native_engineering_identity.py index 21a1d13..36623d0 100644 --- a/tests/test_native_engineering_identity.py +++ b/tests/test_native_engineering_identity.py @@ -221,6 +221,54 @@ def test_export_does_not_adopt_unrelated_existing_native_owner(project, tmp_path assert len(started) == 3 +@pytest.mark.parametrize('remains_alive,database_busy', [(False, False), (True, False), (False, True)]) +def test_export_reobserves_access_denied_child_before_deciding_release( + project, tmp_path, monkeypatch, remains_alive, database_busy): + import json + import pywintypes + import win32api + from cbb_refresh_verify import native_engineering_identity as identity + source, _ = project + root = tmp_path/'exports'; root.mkdir() + launched, seen = [], {} + class Finished: + returncode = 0 + def __init__(self, *args, **kwargs): + self.pid = 980000+len(launched)*2 + launched.append(self) + def poll(self): return 0 + def kill(self): pytest.fail('native owner must not be killed') + def snapshot(): + if not launched: return [] + pid = launched[-1].pid + seen[pid] = seen.get(pid, 0)+1 + if seen[pid] == 1 or remains_alive: + return [{'pid': pid+1, 'parent': pid, 'name': 'conhost.exe', + 'command': '', 'executable': '', 'created': 'creation-identity'}] + return [] + def denied(*args): raise pywintypes.error(5, 'OpenProcess', 'Access is denied') + ticks = iter(i/100 for i in range(1000)) + monkeypatch.setattr(identity.time, 'monotonic', lambda: next(ticks)) + monkeypatch.setattr(identity.time, 'sleep', lambda _: None) + monkeypatch.setattr(identity.subprocess, 'Popen', Finished) + monkeypatch.setattr(identity, '_process_snapshot', snapshot) + monkeypatch.setattr(identity, '_database_released', lambda _: not launched or not database_busy) + monkeypatch.setattr(identity, 'validate_export_output', lambda *_: None) + monkeypatch.setattr(identity, '_retained_exports', []) + monkeypatch.setattr(win32api, 'OpenProcess', denied) + result = identity._run_exports(source, root, tmp_path, .045) + expected = not remains_alive and not database_busy + assert result['success'] is expected + assert result['safe_to_continue'] is expected + record = json.loads((root/'ascii-process.json').read_text('utf-8')) + assert record['process_identities'][0]['pid'] == launched[0].pid+1 + assert record['process_observation_errors'][str(launched[0].pid+1)]['winerror'] == 5 + if expected: + assert len(launched) == 3 and not identity._retained_exports + else: + assert 'TIMEOUT' in result['detail'] and identity._retained_exports + + def test_export_spawn_failure_does_not_manufacture_native_ownership(project, tmp_path, monkeypatch): import cbb_refresh_verify.native_engineering_identity as identity source, _ = project diff --git a/tests/test_private_desktop_discovery.py b/tests/test_private_desktop_discovery.py new file mode 100644 index 0000000..69d34de --- /dev/null +++ b/tests/test_private_desktop_discovery.py @@ -0,0 +1,134 @@ +"""Exercise Windows across real processes; thread-desktop mocks miss access denial.""" +import json +import sys +import time +from uuid import uuid4 +import pytest + + +@pytest.mark.parametrize('thread_access_denied', [False, True]) +def test_foreign_private_desktop_window_is_readable(tmp_path, monkeypatch, thread_access_denied): + import win32con + import win32gui + from cbb_refresh_verify.desktop_worker import DesktopWorker + from cbb_refresh_verify.residual_sessions import _process_windows + from cbb_refresh_verify import residual_sessions + if thread_access_denied: + def denied(_): raise PermissionError(5, 'GetThreadDesktop access denied') + monkeypatch.setattr(residual_sessions, '_thread_desktop_name', denied) + ready = tmp_path/'ready.json' + child = tmp_path/'window.py' + child.write_text(''' +import json,sys,os +from pathlib import Path +import win32api,win32con,win32gui +def procedure(hwnd,message,wparam,lparam): + if message==win32con.WM_CLOSE: + win32gui.DestroyWindow(hwnd); return 0 + if message==win32con.WM_DESTROY: + win32gui.PostQuitMessage(0); return 0 + return win32gui.DefWindowProc(hwnd,message,wparam,lparam) +window=win32gui.WNDCLASS() +window.hInstance=win32api.GetModuleHandle(None) +window.lpszClassName='CbbPrivateDesktopTest' +window.lpfnWndProc=procedure +win32gui.RegisterClass(window) +hwnd=win32gui.CreateWindow(window.lpszClassName,'CBB private desktop discovery', + win32con.WS_OVERLAPPEDWINDOW|win32con.WS_VISIBLE,0,0,300,150,0,0,window.hInstance,None) +Path(sys.argv[1]).write_text(json.dumps({'pid':os.getpid(),'hwnd':hwnd}),'utf-8') +win32gui.PumpMessages() +''', encoding='utf-8') + name = 'CbbDiscoveryTest_'+uuid4().hex[:10] + worker = DesktopWorker([sys.executable, str(child), str(ready)], name) + row = None + try: + deadline = time.monotonic()+10 + while not ready.exists() and worker.poll() is None and time.monotonic()