feat: add safe native Mentor PDF exporter and tested portable UI

This commit is contained in:
Codex committed 2026-10-09 21:32:31 +08:00
1 parent 10a87d2cee
commit d4928af5b6
33 files changed
+2267 -13

No files matched your search

@@ -17,24 +17,34 @@
### Task 1: Native feasibility and safe core
Files: tests/test_scanner.py, tests/test_profiles.py, tests/test_workspace.py, src/mentor_pdf_export/{models,scanner,profiles,workspace,engine}.py, tools/live_smoke.py.
Interfaces: scan_projects(root, excluded_roots=()) -> list[ProjectInfo]; ExportOptions; prepare_workspace(project, run_dir, options) -> Path; build_command(engine, project, output, options) -> list[str].
- [ ] Write failing tests for recursive discovery/pruning, profile values and safe isolated workspace.
- [ ] Run pytest and confirm intended import/behavior failures.
- [ ] Implement core, rerun tests until passing.
- [ ] Export the local PON example ONLY from a copied workspace; retain logs and compare source hashes.
- [ ] Investigate config/ICT/font behavior and record actual evidence/limits.
- [x] Write failing tests for recursive discovery/pruning, profile values and safe isolated workspace.
- [x] Run pytest and confirm intended import/behavior failures.
- [x] Implement core, rerun tests until passing.
- [x] Export the local PON example ONLY from a copied workspace; retain logs and compare source hashes.
- [x] Investigate config/ICT/font behavior and record actual evidence/limits.
### Task 2: Reliable export transaction
Files: tests/test_exporter.py, tests/test_engine.py, src/mentor_pdf_export/{exporter,validation}.py.
Interfaces: Exporter.export(ProjectInfo, output_root, ExportOptions, cancel_event, event_callback) -> ExportResult; discover_engine(explicit=None) -> Path.
- [ ] Write failing tests for valid/invalid PDF, old output preservation, source changes, timeout/cancel and duplicate names.
- [ ] Run red, implement, then run green.
- [ ] Include isolated output staging, JSON run report and retained stdout/stderr.
- [x] Write failing tests for valid/invalid PDF, old output preservation, source changes, timeout/cancel and duplicate names.
- [x] Run red, implement, then run green.
- [x] Include isolated output staging, JSON run report and retained stdout/stderr.
### Task 3: Simple UI and portable release
Files: tests/test_ui.py, src/mentor_pdf_export/{ui,__main__,cli}.py, packaging/mentor_pdf.spec, README.md, Start-MentorPDF.cmd.
Interfaces: MainWindow(root=None, output=None); CLI --self-check/--export/--ui-smoke.
- [ ] Write failing Qt tests: scan checkbox state, settings locking, background signals, cancel, result display.
- [ ] Implement minimal usable UI; run Qt tests and capture window PNG.
- [ ] Run real UI batch on sample copy, render native PDF and check pages/text/colors visually.
- [ ] Build PyInstaller onedir and ZIP; execute packaged --self-check and UI smoke.
- [ ] Run full tests, review diff and document release limitations/evidence.
- [x] Write failing Qt tests: scan checkbox state, settings locking, background signals, cancel, result display.
- [x] Implement minimal usable UI; run Qt tests and capture window PNG.
- [x] Run real UI batch on sample copy, render native PDF and check pages/text/colors visually.
- [x] Build PyInstaller onedir and ZIP; execute packaged --self-check and UI smoke.
- [x] Run full tests, review diff and document release limitations/evidence.
## Safety review fix ledger
- Findings 1/2: whole-queue output/run path preflight and protected CLI report/screenshot destinations; unknown existing JSON is never overwritten. Added red/green regressions.
- Finding 3: suspended Windows process creation, explicit inherited handle whitelist, Job assignment before ResumeThread; worker scope engine.py/test_engine.py only, 20 engine tests passing.
- Findings 4/5: final source check before publication; fsync atomic commit/result pre-record, old output backup; post-commit record failures return traceable uncertain status. Batch pre-record prevents running without durable queue identity.
- Cleanup residual: staging exists/stat is inside guarded cleanup so result recording still happens after filesystem errors. Red/green test added.
- Full test suite after fixes: 63 passed; final rebuilt executable QA remains the release gate.
- Ruling: preserve the new feat/pdf-export repository in the requested directory, without merge/push/worktree cleanup; this task is local test-tool delivery, not shared-branch integration.
Final release gate: rebuilt exe native UI queue success2/failure0 (17 pages each), source209 files and library hashes unchanged, ZIP CRC and extracted clean-PATH self-check passed. Independent scoped review found no remaining blockers in the reported cases.
@@ -22,3 +22,7 @@ ui.py PySide6 工程表、配置栏、后台串行任务、日志、停止、结
## 验收
自动测试覆盖扫描、配置、复制路径安全、错误处理、输出冲突、取消超时、PDF 校验、UI 按钮与后台任务。真实副本导出记录参数、配置、日志、页数与源工程前后指纹,并渲染检查。UI 做 offscreen 行为测试及真实窗口截图。打包后 exe 至少做自检和 UI 启动,不以源码运行替代 exe 验收。
## 验证后补充的约束
实际示例工程的网络中心库不可达;提供用户显式指定对应本地 .lmc 的配置,仅覆盖副本的 CentralLibrary。白底彩色样张部分中文批注乱码与低对比度未消除,版本标为测试版,不能宣称出图质量全部通过。
全队列统一校验输出/运行路径,CLI 报告和截图不能写入源工程;CLI 不覆盖非工具 JSON。所有决定发布的源核验在提交之前完成;预先 fsync/原子记录提交状态,覆盖旧输出先留备份。提交后记录故障返回可追溯待核验,不丢弃当前结果。Windows 引擎必须在执行前进入自有 Job,不允许先启动再绑定的子进程逃逸竞态。
+28
View File
@@ -0,0 +1,28 @@
# Mentor PDF 测试版验收记录
## 真实工程与前置条件
本机 Windows 11、Mentor EE 7.9.5,原生 sch2pdf 报告 V6.0。参考工程 PON.prj 原引用 192.168.0.252 网络库;SMB 连接探测超时。未强行保存或关闭用户 CAD,仅对独立工作副本导出。
## 探测结果
1. 原网络库配置:180 秒超时,零字节 PDF,被验证器拒绝,没有发布正式输出。
2. 显式对应本地 .lmc:正常退出,24 页、约 6 MB PDF,结构验证通过。源工程复制范围哈希不变。
3. 原生 `-u All` 实际失败(Incorrect font name null);`-uAll` 实测正常,命令构建已使用后者。笔画模式也没有消除样张中的中文乱码。
4. PDF 第 1/12/24 页已渲染检查;部分中文批注乱码,浅色对象低对比度,不能按最终出图质量交付。外部 URL 链接数为零。
## UI 与打包
源代码 UI 用 PON 工程两个独立副本做实际串行队列:各 24 页,27.6/18.1 秒,同名工程输出文件不同。原工程全部209个文件以及本地 .lmc 内容哈希一致。便携 exe 原范围 PON 的初次真实 UI 队列各 17 页,说明 Block 与整工程范围不同。
初版打包误收集 PATH 中 Poppler 的 ICU,导致 QtWidgets DLL 缺符号;通过模块导入符号与系统 ICU 对照定位。排除第三方 ICU 后 packaged 自检通过,并加入打包策略回归测试。
## 安全审查
独立审查确认并修复报告覆盖源文件、跨队列目录保护、Job 绑定竞态、发布后才否决源核验、结果记录失败丢失当前结果以及清理 stat 错误绕过结果记录。所有修复有红绿测试证据;最新完整测试63项通过。Windows engine 专项20项,覆盖早期子进程逃逸、取消/超时、标准句柄白名单、启动失败清理及不误杀独立进程。
## 交付边界
仅本机 Windows 11 与本机 EE 7.9.5 真实验收;没有声称全部工程、中文字体、掩盖效果、其他 Windows/Mentor 版本均通过。最终安全修复后的 rebuilt exe 和 ZIP 自检/UI 验收结果在下方追加。
## 最终安全修复后的交付验收
- 最终 rebuilt exe 自检退出码0;实际 UI 串行处理两个独立 PON 副本,每项指定 PON 范围17页,42.9/44.8秒,成功2/失败0。
- 两项均有 commit.json 与最终 status=success 的 result.json,正式 PDF 重新解析为17页。
- 原工程全部209个文件与本地 .lmc 内容摘要保持一致。
- ZIP CRC 检查通过;解压后清除 PYTHONPATH/PYTHONHOME/Qt 路径,仅保留 Windows PATH,exe 自检仍退出0。
- 便携包250个文件,54,992,126字节。没有 Mentor 二进制、CAD 工程、中心库、原文档或测试 PDF。
- 独立定界复核:最初5项 Important 及 cleanup stat 残留,针对已报告触发条件均实质解决。