From 9c4ccc5bf5f514578787214726e8894430630cca 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: Fri, 23 Oct 2026 13:57:28 +0800 Subject: [PATCH] fix(packaging): include pywin32 timezone and verify frozen batch supervisor --- README.md | 6 +-- docs/releases/v1.1.4-beta.2.md | 37 +++++++++++++++ packaging/Build-DxPartReplace.ps1 | 3 ++ packaging/DxPartReplace.spec | 2 + packaging/windows-version-info.txt | 8 ++-- pyproject.toml | 2 +- .../trial_task_center/application.py | 20 +++++++++ .../trial_task_center/version.py | 2 +- tests/trial_task_center/test_application.py | 25 +++++++++++ tools/verify_packaged_runtime.py | 45 +++++++++++++++++++ 10 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 docs/releases/v1.1.4-beta.2.md create mode 100644 tools/verify_packaged_runtime.py diff --git a/README.md b/README.md index f4339a9..3b57e74 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 面向 **Windows + DxDesigner / Expedition Enterprise 7.9.5** 的器件批量替换工具。一个工程对应一个任务,可以只替换同料号下的部分位号;支持直接编辑和 Excel BOM 导入,同批工程按顺序执行。 -**最新版本:V1.1.4 Beta 1(预发布)** · [下载便携包](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/releases/download/v1.1.4-beta.1/DxPartReplace-1.1.4-beta.1.zip) · [版本说明与附件](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/releases/tag/v1.1.4-beta.1) · [完整使用说明](docs/user/v1.1.0-project-tasks.md) +**最新版本:V1.1.4 Beta 2(预发布)** · [下载便携包](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/releases/download/v1.1.4-beta.2/DxPartReplace-1.1.4-beta.2.zip) · [版本说明与附件](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/releases/tag/v1.1.4-beta.2) · [完整使用说明](docs/user/v1.1.0-project-tasks.md) 所有发布均标记为 **Beta 预发布**,旧版本标签与下载链接保持可用。 @@ -18,7 +18,7 @@ ### 第 1 步:解压并打开应用 -[下载 V1.1.4 Beta 1 便携包](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/releases/download/v1.1.4-beta.1/DxPartReplace-1.1.4-beta.1.zip),**完整解压**,双击 `DxPartReplace.exe`。保留它与 `_internal` 的相对位置,无需安装 Python;本机需要可用的 DxDesigner、许可证和中央库。 +[下载 V1.1.4 Beta 2 便携包](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/releases/download/v1.1.4-beta.2/DxPartReplace-1.1.4-beta.2.zip),**完整解压**,双击 `DxPartReplace.exe`。保留它与 `_internal` 的相对位置,无需安装 Python;本机需要可用的 DxDesigner、许可证和中央库。 打开后看到下图主窗口。首次使用请准备完整的工程副本,执行前保存并关闭待处理工程。 @@ -194,7 +194,7 @@ DxPartReplace/ ## 验证范围与已知限制 -V1.1.4 Beta 1 新增批次后台资源管理:一次 BOM 导入或顺序执行共用一个私有桌面,CAD 按需启动并在同批工程间复用,批次结束统一退出。若提示 **资源释放待处理**,已保存核验的结果保留,请点击 **重新清理资源**;该操作只清理后台资源,不会再次替换。旧的工程保护锁仍按“核验并恢复”处理。设计、异常边界与实机结果见[批次运行时验收记录](docs/testing/2026-10-21-batch-private-runtime.md)。 +V1.1.4 Beta 2 新增批次后台资源管理:一次 BOM 导入或顺序执行共用一个私有桌面,CAD 按需启动并在同批工程间复用,批次结束统一退出。若提示 **资源释放待处理**,已保存核验的结果保留,请点击 **重新清理资源**;该操作只清理后台资源,不会再次替换。旧的工程保护锁仍按“核验并恢复”处理。设计、异常边界与实机结果见[批次运行时验收记录](docs/testing/2026-10-21-batch-private-runtime.md)。 资源释放会追加日志:在 **替换结果 / 日志 → 完整日志** 查看本批开始释放、释放成功/失败及重新清理的结果。独立文件位于 `data/batch-resources/<批次ID>/resource-release.log`,记录批次、桌面、CAD PID、退出码、释放耗时、句柄关闭和桌面消失的分别确认,以及失败原因;同时保留 `session.json` 的原始释放证明。重启后重新检查也会追加记录,不覆盖原失败日志。 diff --git a/docs/releases/v1.1.4-beta.2.md b/docs/releases/v1.1.4-beta.2.md new file mode 100644 index 0000000..cd17c13 --- /dev/null +++ b/docs/releases/v1.1.4-beta.2.md @@ -0,0 +1,37 @@ +# DxPartReplace V1.1.4 Beta 2 + +发布日期:2026-10-23。**Beta 预发布版**。替代已撤回的 V1.1.4 Beta 1;旧 Git 标签保留供回溯,旧发布不再提供公开下载。 + +## 下载与升级 + +完整解压 `DxPartReplace-1.1.4-beta.2.zip`,运行 `DxPartReplace.exe`。无需安装 Python;本机需要可用的 DxDesigner / Expedition Enterprise 7.9.5、许可证和中央库。 + +升级前关闭旧程序并备份 `data`,保留原数据,配套更新 EXE 与 `_internal`。不要让不同版本同时打开同一数据目录;历史保护锁不会自动解除。 + +[中文图文教程](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/src/tag/v1.1.4-beta.2/README.md)。包内包含离线图文教程、GIF、默认 11 列 BOM 模板、构建清单和 SHA256 校验。教程图片及 GIF 沿用已验收的旧版录制,新增的“重新清理资源”与释放日志以本版界面为准。 + +## Beta 2 修复 + +- 修复工单 #2(DXT-20261023-A1F7FADF):发布包缺失 `win32timezone`,导致 BOM 导入记录采集进程创建时间时失败。显式打包 pywin32 的动态依赖,无需用户安装 Python。 +- 发布门禁改为在完整 EXE 主进程中验证私有桌面、子进程启动、创建时间记录及最终释放,防止源码 Python 的完整环境掩盖打包缺失。 +- 不改变替换、保存回读、保护锁及资源恢复规则。 + +## 继承的批次功能 + +- 每次 BOM 导入和顺序执行分别作为一个批次,共用一个私有桌面;CAD 按需启动,在批内跨工程复用,批末统一退出。 +- 工程之间确认上一工程已关闭,重新核验路径、中心库、图页及目标身份;保留保存、关闭、重开回读流程。 +- 首次可能写入前持久化保护标记。只有明确证明尚未修改且旧资源已释放时,允许重建重试一次;身份冲突、已修改或结果不确定时不自动重放。 +- 释放失败保留已保存并核验的任务结果,阻止新批次,提供“重新清理资源”;清理操作不重复替换,重启后仍检查未收尾批次。 +- 释放日志显示开始、成功、失败和重新检查,包含耗时、CAD退出码、句柄关闭与桌面消失的分别确认、失败原因。同批各任务“完整日志”可见,独立文件位于 `data/batch-resources/<批次ID>/resource-release.log`。 +- 修复 BOM 错误回报与清理错误同时发生时丢失逐行报告的问题;清理失败只保留诊断,不提供可应用的部分预览。 +- 保留原生 CLI 优先采集,减少不必要的 CAD 回退;原生会话重试耗尽时停止整批。 + +## 验证与范围 + +两个全新工程副本完成 BOM 导入、实际替换、保存重开、独立完整属性/连接回读和资源释放。两版本保存结果一致;各工程 57 个组件、103 个引脚连接,56 个非目标组件属性和连接不变,源工程及中心库 `.lmc` 哈希不变。 + +相同样例单次对照:BOM 加执行总耗时 170.860 → 151.859 秒,私有桌面创建 6 → 2 次,CAD 启动 2 → 1 次。该结果不代表固定加速比例;BOM 单次测量 2.250 → 3.187 秒。 + +工单完整库存覆盖的 31 行回放为 20 通过、11 失败,未强行放行不匹配项;其余 406 条替换行、96 个工程未获对应完整库存,不能宣称全部工程已实机通过。用户机器的外部桌面引用残留根因尚未在本机复现。 + +详见[批次运行时验收](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/src/tag/v1.1.4-beta.2/docs/testing/2026-10-21-batch-private-runtime.md)、[实机对照](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/src/tag/v1.1.4-beta.2/docs/testing/2026-10-21-batch-private-runtime-live.md)和[释放日志验证](https://git.simgreek.com/simgreek/dxdesigner-part-replacement/src/tag/v1.1.4-beta.2/docs/testing/2026-10-21-resource-release-logging.md)。 diff --git a/packaging/Build-DxPartReplace.ps1 b/packaging/Build-DxPartReplace.ps1 index c48e5c9..64266da 100644 --- a/packaging/Build-DxPartReplace.ps1 +++ b/packaging/Build-DxPartReplace.ps1 @@ -80,6 +80,9 @@ try { if (-not (Test-Path -LiteralPath $executable -PathType Leaf)) { throw "PyInstaller did not produce $executable" } + $runtimeSmokeRoot = Join-Path $repositoryRoot ("build\frozen-runtime-" + [Guid]::NewGuid().ToString("N")) + & $PythonExecutable tools\verify_packaged_runtime.py $executable $runtimeSmokeRoot + if ($LASTEXITCODE -ne 0) { throw "Frozen supervisor verification failed; build stopped" } $sourceQuickPartReplace = Join-Path $repositoryRoot "integration\dxdesigner795\QuickPartReplace.vbs" $packagedQuickPartReplace = Join-Path $repositoryRoot "dist\DxPartReplace\_internal\legacy-runtime\dxdesigner795\QuickPartReplace.vbs" if (-not (Test-Path -LiteralPath $sourceQuickPartReplace -PathType Leaf)) { diff --git a/packaging/DxPartReplace.spec b/packaging/DxPartReplace.spec index 8a3f3ef..25a7fcb 100644 --- a/packaging/DxPartReplace.spec +++ b/packaging/DxPartReplace.spec @@ -43,6 +43,8 @@ a = Analysis( "win32con", "win32gui", "win32process", + # GetProcessTimes imports this from pywin32's C extension at runtime. + "win32timezone", "pywinauto", "pywinauto.controls.uiawrapper", ], diff --git a/packaging/windows-version-info.txt b/packaging/windows-version-info.txt index e6a481f..d57bf87 100644 --- a/packaging/windows-version-info.txt +++ b/packaging/windows-version-info.txt @@ -1,8 +1,8 @@ # UTF-8 VSVersionInfo( ffi=FixedFileInfo( - filevers=(1, 1, 4, 1), - prodvers=(1, 1, 4, 1), + filevers=(1, 1, 4, 2), + prodvers=(1, 1, 4, 2), mask=0x3f, flags=0x2, OS=0x40004, @@ -15,11 +15,11 @@ VSVersionInfo( StringTable('040904B0', [ StringStruct('CompanyName', 'DxProductivity'), StringStruct('FileDescription', 'DxDesigner Part Replacement'), - StringStruct('FileVersion', '1.1.4.1'), + StringStruct('FileVersion', '1.1.4.2'), StringStruct('InternalName', 'DxPartReplace'), StringStruct('OriginalFilename', 'DxPartReplace.exe'), StringStruct('ProductName', 'DxDesigner Part Replacement'), - StringStruct('ProductVersion', '1.1.4-beta.1') + StringStruct('ProductVersion', '1.1.4-beta.2') ]) ]), VarFileInfo([VarStruct('Translation', [1033, 1200])]) diff --git a/pyproject.toml b/pyproject.toml index ec36f44..734c68e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "dx-productivity" -version = "1.1.4b1" +version = "1.1.4b2" requires-python = ">=3.12,<3.13" dependencies = ["PySide6>=6.7,<7", "pywin32>=306", "pywinauto>=0.6.9,<1", "openpyxl>=3.1,<4"] diff --git a/src/dx_productivity/trial_task_center/application.py b/src/dx_productivity/trial_task_center/application.py index 40b7b91..3e37690 100644 --- a/src/dx_productivity/trial_task_center/application.py +++ b/src/dx_productivity/trial_task_center/application.py @@ -117,6 +117,24 @@ def _flush(context: LoggingContext) -> None: handler.flush() +def _smoke_batch_runtime(data_root: Path, context: LoggingContext) -> None: + """Exercise process tracking inside the frozen supervisor before releasing.""" + from dx_productivity.trial_task_center.batch_runtime import BatchCadRuntime + + with BatchCadRuntime(data_root, 'packaged_runtime_smoke') as runtime: + runtime.bind_logs(context, ()) + with runtime.native_scope(data_root / 'runtime-smoke') as lease: + command = str(Path(os.environ['SystemRoot']) / 'System32/cmd.exe') + process = lease.start_process((command, '/d', '/c', 'exit', '0')) + if not runtime.record['processes'][0]['creation_time']: + raise RuntimeError('Smoke process identity has no creation time') + if process.wait(timeout=15) != 0: + raise RuntimeError('Smoke worker did not exit successfully') + if runtime.record['state'] != 'released': + raise RuntimeError('Smoke resources were not released') + context.logger.info('packaged_runtime_smoke_passed batch_id=%s', runtime.session_id) + + def main(argv: Sequence[str] | None = None) -> int: """Run the Qt shell, returning a conventional process status code.""" arguments = _parse_arguments(argv) @@ -149,6 +167,8 @@ def main(argv: Sequence[str] | None = None) -> int: try: database_path = data_root / "task-center.db" _log_startup(logging_context, data_root, database_path) + if arguments.smoke_test and bool(getattr(sys, 'frozen', False)): + _smoke_batch_runtime(data_root, logging_context) store = TaskStore(database_path) service = TaskCenterService(store, logging_context) qt_application = QApplication([sys.executable, *(argv or ())]) diff --git a/src/dx_productivity/trial_task_center/version.py b/src/dx_productivity/trial_task_center/version.py index b687381..6a7fd20 100644 --- a/src/dx_productivity/trial_task_center/version.py +++ b/src/dx_productivity/trial_task_center/version.py @@ -1 +1 @@ -VERSION = "1.1.4-beta.1" +VERSION = "1.1.4-beta.2" diff --git a/tests/trial_task_center/test_application.py b/tests/trial_task_center/test_application.py index 5957f44..1e0b853 100644 --- a/tests/trial_task_center/test_application.py +++ b/tests/trial_task_center/test_application.py @@ -4,6 +4,8 @@ from pathlib import Path import os import subprocess import sys +import json +import pytest def test_default_data_root_uses_windows_known_folder_without_environment(tmp_path: Path, monkeypatch) -> None: @@ -189,3 +191,26 @@ def test_icon_uses_package_location_for_frozen_script_entrypoint(tmp_path, monke assert not qapp.windowIcon().isNull() assert not qapp.windowIcon().pixmap(32, 32).isNull() assert qapp.applicationVersion() == application.VERSION + + +@pytest.mark.parametrize('missing_dependency', [False, True]) +def test_runtime_smoke_tracks_real_process_and_releases_on_failure(tmp_path, monkeypatch, missing_dependency): + from dx_productivity.trial_task_center.application import _smoke_batch_runtime + from dx_productivity.trial_task_center.logging_setup import configure_logging + import win32process + + if missing_dependency: + def fail(_handle): + raise ModuleNotFoundError("No module named 'win32timezone'") + monkeypatch.setattr(win32process, 'GetProcessTimes', fail) + with pytest.raises(ModuleNotFoundError, match='win32timezone'): + _smoke_batch_runtime(tmp_path, configure_logging(tmp_path)) + else: + _smoke_batch_runtime(tmp_path, configure_logging(tmp_path)) + paths = list((tmp_path / 'batch-resources').glob('*/session.json')) + assert len(paths) == 1 + record = json.loads(paths[0].read_text(encoding='utf-8')) + assert record['state'] == 'released' and record['cad_pid'] is None + assert record['cleanup']['desktop_handle_closed'] + assert record['cleanup']['desktop_confirmation']['released'] + assert not record['cleanup']['errors'] diff --git a/tools/verify_packaged_runtime.py b/tools/verify_packaged_runtime.py new file mode 100644 index 0000000..9fe29b6 --- /dev/null +++ b/tools/verify_packaged_runtime.py @@ -0,0 +1,45 @@ +"""Verify the frozen supervisor, not a source-Python substitute for it.""" +from __future__ import annotations + +import argparse +import json +import os +from pathlib import Path +import subprocess + +from PyInstaller.archive.readers import CArchiveReader + + +def verify(executable: Path, data_root: Path) -> dict: + executable = executable.resolve(strict=True) + if data_root.exists(): + raise ValueError('Use a fresh verification data directory') + archive = CArchiveReader(str(executable)) + assert 'win32timezone' in archive.open_embedded_archive('PYZ.pyz').toc, 'Missing win32timezone in frozen archive' + environment = dict(os.environ, QT_QPA_PLATFORM='offscreen') + for key in ('PYTHONPATH', 'PYTHONHOME', 'DX_TASK_CENTER_HOME'): + environment.pop(key, None) + result = subprocess.run([str(executable), '--smoke-test', '--data-root', str(data_root.resolve())], + env=environment, cwd=executable.parent, timeout=90, + creationflags=subprocess.CREATE_NO_WINDOW, capture_output=True) + assert result.returncode == 0, (result.returncode, result.stderr) + log = (data_root / 'logs/application.log').read_text(encoding='utf-8') + assert 'packaged_runtime_smoke_passed' in log + assert 'application_clean_shutdown exit_code=0' in log + records = [json.loads(p.read_text(encoding='utf-8')) + for p in (data_root / 'batch-resources').glob('*/session.json')] + assert len(records) == 1 and records[0]['state'] == 'released' + cleanup = records[0]['cleanup'] + assert cleanup['desktop_handle_closed'] and cleanup['desktop_confirmation']['released'] + assert not cleanup['errors'] + return {'passed': True, 'frozen_supervisor': True, 'win32timezone_archived': True, + 'process_creation_time_read': True, 'resources_released': True, + 'executable': str(executable), 'data_root': str(data_root.resolve())} + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('executable', type=Path) + parser.add_argument('data_root', type=Path) + args = parser.parse_args() + print(json.dumps(verify(args.executable, args.data_root), ensure_ascii=False, indent=2))