Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
211e993e94 | ||
|
|
8ef40a2e61 |
No files matched your search
@@ -1,31 +0,0 @@
|
|||||||
# Issue 33 D5 · BOM 未知列验收
|
|
||||||
|
|
||||||
现场 B3 的 `INVALID_C1_bad_header_extra_col.xlsx` 带有 `extra_column`。名称归一化将未知列映射为空,后续只复制模板定义的列。导入成功时,工作区原先只报告保存行数与失败行数。
|
|
||||||
|
|
||||||
现在 BOM 导入保留模板列的精确映射,并为每个被忽略的具名列显示来源文件、原始列名与警告计数。详情和任务事件同时记录这些警告。缺失必需列时,导入停止,错误详情列出具体缺失项并对相近列名给出改名建议。
|
|
||||||
|
|
||||||
## Windows 11 重放
|
|
||||||
|
|
||||||
通过 Qt 工作区的“导入 BOM”按钮和真实任务服务运行,测试替换的是文件选择对话框的返回值。现场文件复制到临时目录,仅把第一条记录的工程名称与路径绑定到临时工程,保留了原始表头和替换字段。
|
|
||||||
|
|
||||||
| 工作簿 | 结果 |
|
|
||||||
| --- | --- |
|
|
||||||
| 两个额外列「供应商」「备注」 | 保存 1 行、失败 0 行、警告 2 项。详情逐列列名,任务事件记录同一组警告 |
|
|
||||||
| 现场 B3 `extra_column` | 保存 1 行、失败 0 行、警告 1 项。详情保留该列名 |
|
|
||||||
| 用「新料号编码」替换必需的「新料号」 | 指出缺少「新料号」,并建议将「新料号编码」改为「新料号」 |
|
|
||||||
| 缺少「新料号」 | 指出具体缺失项 |
|
|
||||||
| 表头公式与额外列中的数据公式 | 分别拒绝表头公式和第 2 行公式 |
|
|
||||||
| 原模板 | 保存 1 行、失败 0 行,无警告 |
|
|
||||||
|
|
||||||
BOM 草稿导入时未启动工程位号采集。回归还检查了由监督子进程返回的真实预览报告能携带同样的警告。包含现场工作簿重放的定向回归共通过 110 项。
|
|
||||||
|
|
||||||
## 复跑
|
|
||||||
|
|
||||||
在仓库根目录运行。现场文件从工单附件 `05_实测证据/paper2_bom` 解出。普通回归可省略 `DX_ISSUE33_D5_FIELD`,此时跳过现场文件重放。
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
$env:PYTHONUTF8 = '1'
|
|
||||||
$env:PYTHONPATH = (Resolve-Path src).Path
|
|
||||||
$env:DX_ISSUE33_D5_FIELD = 'C:/path/to/INVALID_C1_bad_header_extra_col.xlsx'
|
|
||||||
python -m pytest -q -s tests/v1_1/test_bom_header_feedback.py tests/v1_1/test_bom_import_report.py tests/v1_1/test_bom_pending.py tests/v1_1/test_bom_sources_supervision.py tests/trial_task_center/test_bom_import_review.py tests/trial_task_center/test_item_value_and_bom_sources.py
|
|
||||||
```
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# #33 六套固定试卷复测清单
|
||||||
|
|
||||||
|
逐项核对原始交付包 `03_试卷与实测` 下六份 `*_实测结果.xlsx` 的题号、结果和备注。下表覆盖原表 101 条未通过记录及卷二 A5 的自动化缺口。历史基线为卷一至六 83、71、49、75、56、39,总计 373/600。原记录把未执行项计作失败,候选包成绩须用逐题实测填写。[原始交付包](G:/dx33/acceptance/field.zip) · [工单 #33 第七、八节](https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement/issues/33)
|
||||||
|
|
||||||
|
## 复测入口
|
||||||
|
|
||||||
|
各卷从发行候选包的 `DxPartReplace.exe --data-root <独立目录>` 进入。**夹具**使用临时任务库、BOM、受控 Win32 窗口或模拟执行器,可先跑源码回归。**Windows 界面**使用候选包和临时任务数据。**独占 CAD**使用工程副本、可用 Mentor 和适用的中心库,回读与资源结论以真实运行证据为准。
|
||||||
|
|
||||||
|
| 原卷题号 | 候选包入口与环境 | 通过证据与失败归属 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 一 A7、B7、C9、E5、E8 | Windows 界面。双击同根与异根,读不存在路径,扫描后移走工程,搜 `zzzz_no_match`,改窗口后重启。 | 保留启动与冲突日志、任务 ID、路径和建议、清除搜索前后截图及布局尺寸。偏离分别归 D1、D2、D4、D3。 |
|
||||||
|
| 一 D7、D8、D9 | Windows 界面。人工打开任务操作或回收站,顺序执行移动、移入、恢复、彻底删除。 | 保存顺序与执行范围、恢复前后规则和证据、彻底删除后的记录及文件清单。控件仅在自动化中无法定位时记驱动限制,人工复现失败再记任务管理。 |
|
||||||
|
| 二 A5、A7、B3、B5 | Windows 界面加 BOM 夹具。人工一次选 5 份,另一次慢导入后取消,再导入额外列和工程名路径不符的表。入口为批量 BOM 导入,可先跑 `test_bom_batch.py`、`test_bom_import_report.py`。 | 5 份清单、取消前后清单一致、未知列提示及不匹配工程零错绑。A5 原表通过,自动化多选失败归驱动,B3 归 D5,其余归导入生命周期或工程关联。 |
|
||||||
|
| 二 C3、C8、C10、C11、D2、D3、D4、D8、D10、E2、E4、E5、E6、E7 | Windows 界面加规则与位号夹具。料号规则、采集、位号计划、切换任务、复制证据。先跑 `test_target_table.py` 等定向用例。C8 真实采集和 C10 实际库封装下拉安排独占 CAD/中心库核对。 | 对照过滤 UID、Cell 留空或非法校验、默认值与手改值、勾选范围、取消时原草稿、完整路径及缩放截图。分别归规则、采集/库、计划或界面,只在真实前置就绪后认定产品失败。 |
|
||||||
|
| 三 A4、A5、A7、D5、E1 | 夹具与 Windows 界面。注入待清理状态,修改未保存计划及策略,取消/重复确认,注入失败和未命中,开始新一轮。可用 `test_service_plan_safety.py`、`test_task_archive.py`。 | 阻断时零派发,确认框策略与草稿一致,取消零副作用,失败未命中与保存明确区分,旧轮计划、命令、快照和日志可追溯。归资源闸门、计划或状态展示。 |
|
||||||
|
| 三 A2、A3、B3、B4、B6、B7、B8、B9、B10、C5、C7、D6、E2、E3、E4、E6 | 独占 CAD。≥2 图页、≥5 替换行、≥10 位号,准备正常、缺料号或未命中、只读或锁定工程副本。走采集 → 单工程位号计划 → 核验并执行 → 新一轮。已准备 `ui-session.json` 的测试根可用 `tools/accept_packaged_ui.py --root <测试根> --stage execute --run-native` 辅助取证。 | 保存逐页位号、各 Value/Cell 策略、Value 位置样式、失败前后设计与回读、关窗退进程、轮次档案、暂停位置和重试次数。缺料输入按预期可控失败,误写或重放归执行/恢复,残留归 D7。 |
|
||||||
|
| 四 A5、A7、C7、C8、D8 | 夹具先跑 8 项队列和逐任务 Value/NC,注入缺计划或资源占用,走失败项重试准备和诊断导出。入口 `tools/measure_task_queue.py --projects 8 --behavior failure_continue --output <目录>` 和候选包批次确认、重试及导出。 | 确认页策略正确,阻断时未启动 CAD,重试仅包含符合条件的项并重新确认,成功项操作 ID 无重放,导出 ZIP 可打开且脱敏。归批次预检、重试选择、D8 或诊断导出。 |
|
||||||
|
| 四 B6、C1、D1、E2、E3 | 独占 CAD。固定卷 8 工程为成功 3、无需替换 1、目标不存在 1、库/身份阻断 1、缺计划 1、已满足 1。完成任务范围确认后无人点击,另用 100 工程跑工单门槛。 | 8/8 队列与任务结论,业务进展时间线核对 B6 的 300 秒要求,缺料号无部分写入且后续推进,收尾核对桌面和自有 PID。D1 原表引用的是 100 工程尝试,8 项需单独完成。归 D6 加载或写入状态、D7 物理清理、D8 后续调度。 |
|
||||||
|
| 五 A5、A7、B5、B6、C4、D4、D5、D6、D7、E2、E4、E5、F1、F2、F3、F5、G1、G2、G3、G4 | Windows 界面加少量任务夹具。125% 缩放下用键盘走任务中心、表格、更多菜单、危险操作、未保存和嵌套弹窗,切换高对比后关闭重启。运行态先用 UI 夹具,也可独占小工程观察。 | 分辨率与缩放截图、表头滚动和就地校验、操作范围及默认按钮、键盘路径与焦点、设置前后对照。C4/D4/G1 对应 D2/D4/D3。菜单以人工结果判定,真实视觉与键盘差异归 UI/可访问性。 |
|
||||||
|
| 六 A1、A2、A3、A5、A6、A7、A8、B7 | 先跑 `tools/measure_task_queue.py --behavior pause_resume --output <目录>`。独占 CAD 用暂停副本在保存/核验边界点击暂停,重复点击并等待,再继续原队列。 | 当前项收尾,下一项暂停期间无派发,复用原队列及授权,继续时已保存 ID 无重放,工程关闭及资源结论明确。异常归暂停边界、D7 清理或 D8 原队列续跑。 |
|
||||||
|
| 六 C5、C6、C7、C8、C9、C10、D1、D2、D3、D4、D5、D6、D7、E2、E3、E4、E6 | 先跑 `test_startup_recovery.py`、`test_interrupted_queue_reconciliation.py`。独占 CAD 用强停、强杀两个不同副本,并用 `tools/probe_frozen_startup_recovery.py --source <副本> --library <库> --executable <候选exe> --output <目录> --failures 2` 辅助验证恢复。按原题执行两次中断与重启、实际打开复核、保存回读关闭、导出诊断、启动下一批。 | 保留中断点与原 queue_id、两次检查点、轮次/工程/UID/料号回读、备份和快照哈希、已保存操作 ID 及次数、UI/DB/日志对照、诊断 ZIP、桌面枚举及 PID 退出。未知写入保留待核验。错误按证据归恢复行为、D7 清理或 D8 续跑。 |
|
||||||
|
|
||||||
|
## 现场完成判据
|
||||||
|
|
||||||
|
工单要求**卷四和卷六各 ≥80,六套完整复跑总分 ≥500/600,六卷均无 P0 复发**。正常批次 `uncertain.flag=0`,结束时桌面与进程残留为 0。另跑 100 工程至队列终态并产出汇总,允许有证据的个别工程 blocked,需验证可续跑及已保存项不重放。逐题记录候选包版本或哈希、输入与环境、预期、实际、得分与证据位置。无法执行时记录缺少的前置,UIA 驱动限制和模型端点 503/504 记测试工具或环境。夹具结果供预验收使用,现场分数以固定卷实测为准。[工单 #33 第八节](https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement/issues/33)
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# 工单 #33 根因分析与 1.3.3 本地预验收
|
||||||
|
|
||||||
|
现场基线为 Windows 便携版 1.3.2,修复基线为 main 的 46deb9c。原始交付包 SHA-256 为 `1ac99eac3cf79bbf1f011d1d5fe833e92b98fba2c01546b3cfaf55a90b82d5b3`,本地逐项复核包内清单的 4,469 个文件全部一致。[工单与附件](https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement/issues/33)
|
||||||
|
|
||||||
|
## 原始记录还原
|
||||||
|
|
||||||
|
1. 在 `05_实测证据/data_full132/task-queues/55e1032ac965453b8adf307da1400511.json` 中,100 项分为 6 completed、3 skipped、2 blocked、89 pending。任务列表中的 92 draft 包含了队列已跳过的三项。09:30:17 的监控显示第 11 项 BOB_Shield 在做替换前快照,09:32:18 显示资源待清理。
|
||||||
|
2. 首批在第 10 项 BOB 的第 23 个操作和第 11 项 BOB_Shield 的第 18 个操作加载 `4885-S033D0-M220` 超时,各自的 native.json 均标记 preflight。第 10 项已写入 isolated_tasks,并实际派发了第 11 项。第 11 项仅写入 blocked。不能把整批归因于“遇到第一个失败就停”。另一个 91 项检查点记录了 WiFi 工程加载 `4885-S018D0-M220` 超时。工具报告的空窗口与这个超时属于不同 generation,尚不能认定窗口引起该次超时。
|
||||||
|
3. 首批资源目录 `1d5d999ec63045b49661466928de9a01` 的 business-result.json 报 paused=true,current_task_id 对应 BOB_Shield。supervisor.json 的 finished 描述监督器退出。session.json 的最终状态是 isolated、blocking=false、mentor_released=true、desktop_released=false。任务隔离、队列暂停、监督器退出、资源是否可再租用分别有自己的证据。后续批次另有 blocking=true 的记录。现场没有足够证据指认持有桌面句柄的外部进程。
|
||||||
|
|
||||||
|
## 单项修复和判据
|
||||||
|
|
||||||
|
| 项 | 已定位的入口或失效条件 | 修改与本地复验 |
|
||||||
|
|---|---|---|
|
||||||
|
| D2 路径错误 | 工程根校验和扫描后登记有不同失败窗口,文件系统异常落到通用错误提示 | 分别注入目录不存在、选择了普通文件、扫描后移走、访问被拒;检查 GUI 中路径、码、修复建议,日志按同类输入统计兜底数并保留真正未知异常的诊断 |
|
||||||
|
| D1 同根双开 | 单工程和队列执行锁在主窗口启动后才生效,两个 GUI 可先打开同一数据库并启动恢复 | 在首次打开数据库之前取得 data-root 级互斥;4 个进程同时打开同根,再试异根、helper 和持有者异常退出,检查持有者 PID、唤醒回执、应用启动次数以及原任务 ID |
|
||||||
|
| D6 原生加载 | 需区分本次加载尚未点击写入与前序位号已暂存。当前预读不能证明整个工程仍无修改;列表控件刷新也可能令旧 HWND 失效 | 使用工程副本分别注入首次/热加载、列表重建、超时前已写/未写、不同 owner 的空弹窗。记录 attempt/generation、写前标记、前后属性、关闭与保存回执。仅在本项未写且身份可证时有限重试;写入可能性跨重启必须保留 |
|
||||||
|
| D7 资源收尾 | 一条历史隔离回执已经可以不拦下一批;同名桌面、租约归还及对象物理消失有不同寿命 | 对照正常关闭、带窗口的自有 writer、仅有外部 OpenDesktop 句柄、证据缺失四组。按 PID 和创建时间确认自有进程退出、关闭自有句柄、重新枚举,再以有界退避重查。外部持有期间不得记 released;外部释放后应自动收敛。记录旧租约与新租约,禁止旧代清理新 owner |
|
||||||
|
| D8 整批停顿 | 第一个不确定工程已被隔离,第二个未获得同等隔离结果;队列持久化暂停后,资源提示变成可用也未推进原队列 | 基于已验收的 D7 结果复验两次连续失败,区分同写源与无关工程、主动暂停与故障等待。只恢复原队列、原计划、未派发项;活 writer、未知归属或同写源仍隔离。比对操作 ID、保存次数、所有任务终态和 UI 文案 |
|
||||||
|
| D5 BOM 列 | 表头映射只读取已知列;“失败 0 行”无法告知额外列未采用 | 实际导入现场 B3 工作簿,再导入带两列、近义列、缺列、重复列、公式和标准模板。额外列一次列出并提示近义列,核对预览、保存结果和持久化规则 |
|
||||||
|
| D3 窗口 | ui-layout.ini 保存分栏和排序,主窗口仍用默认尺寸 | 从真实主窗口调整大小、位置和最大化后退出重启,测 125% 缩放与失去屏幕后的可见区域;损坏 ini 应可启动 |
|
||||||
|
| D4 零结果 | TaskList._render 只更新列表和数值,缺少对空列表原因的呈现 | 用 Qt 键盘输入现场关键词 zzzz_no_match,切换筛选、组合搜索、回收站和空库,清除条件后验证原集合及选择;核对实际显示的关键词、筛选名与匹配数 |
|
||||||
|
|
||||||
|
## 分层复跑与交付口径
|
||||||
|
|
||||||
|
本机复跑以下两条基线命令,分别校验现场原件和生产调度器。第二条使用真实 SQLite、BOM 读取、任务队列及检查点,CAD 执行由夹具驱动。得到 99 completed、1 blocked、199 次操作,耗时 608.3 秒。这个单故障场景在修复前已能跑完,因此不能用它单独验收 D8。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
python tools/inspect_issue33_field.py G:/dx33/acceptance/field.zip
|
||||||
|
python tools/measure_task_queue.py --projects 100 --sheets 1 --rules 1 --behavior uncertain_stop --output build/issue33-baseline100
|
||||||
|
```
|
||||||
|
|
||||||
|
- **本地预验收**使用独立 data-root 和工程副本。每项记录软件提交、输入、触发步骤、期望/实际结果、日志和可复跑命令。重启测试复用同一测试根。验证命令和结果随各单项 PR 提交。工单指定 D6、D7、D8 按序合入,不能用其他批次的通过报告替代当前批次。
|
||||||
|
- **整批故障注入**先跑 8 项混合队列,再跑 100 工程固定顺序。对第 10、11 项连续注入现场两种失败,独立工程继续,另设一个共享 iCDB 的依赖工程以验证隔离。第 23 个位号前后分别中断,复用同一 queue_id 两次重启,逐项比较 saved 的操作 ID 与次数。未知写入不能计入成功。
|
||||||
|
- **现场复测**用发行候选包与六套固定试卷逐题执行。卷六的暂停、重启、不重放和下一批启动优先。验收要求卷四、六各至少 80 分,总分至少 500/600,六卷无 P0 复发。正常批次检查 uncertain.flag=0,收尾核对桌面枚举与活进程。如仅运行夹具或源码,报告应标明该范围并单列真实 Mentor、现场库、物理副屏等待测项。
|
||||||
|
- 本地采集目录为 `G:/dx33/acceptance`。现场 ZIP 留存原样,复验使用副本。原始打分仍是 373/600;菜单驱动、多选自动化和模型端点限流单列,分数只随实际复跑更新。
|
||||||
@@ -48,7 +48,6 @@ class BomImportReport:
|
|||||||
source_map_path: Path | None = None
|
source_map_path: Path | None = None
|
||||||
passed_preview: BomBatchPreview | None = None
|
passed_preview: BomBatchPreview | None = None
|
||||||
deferred: bool = False
|
deferred: bool = False
|
||||||
warnings: tuple[str, ...] = ()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def total_rows(self):
|
def total_rows(self):
|
||||||
|
|||||||
@@ -77,9 +77,7 @@ def resolution_binding(store, task_id):
|
|||||||
|
|
||||||
def import_drafts(service, task_id, sources, *, stop_event=None, on_progress=None, on_phase=None, allow_partial=False):
|
def import_drafts(service, task_id, sources, *, stop_event=None, on_progress=None, on_phase=None, allow_partial=False):
|
||||||
"""Persist routed spreadsheet requests without opening CAD or resolving parts."""
|
"""Persist routed spreadsheet requests without opening CAD or resolving parts."""
|
||||||
warnings = []
|
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress, allow_partial=allow_partial)
|
||||||
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress,
|
|
||||||
allow_partial=allow_partial, warnings=warnings)
|
|
||||||
scope = _scope(service._store, task_id)
|
scope = _scope(service._store, task_id)
|
||||||
paths = tuple(project.path for _, project in scope)
|
paths = tuple(project.path for _, project in scope)
|
||||||
names = {project.path: task.name for task, project in scope}
|
names = {project.path: task.name for task, project in scope}
|
||||||
@@ -95,8 +93,7 @@ def import_drafts(service, task_id, sources, *, stop_event=None, on_progress=Non
|
|||||||
write_routed_bom(normalized, rows, routes, project_names=names)
|
write_routed_bom(normalized, rows, routes, project_names=names)
|
||||||
append_task_event(service._logging, level='INFO', task_id=task_id,
|
append_task_event(service._logging, level='INFO', task_id=task_id,
|
||||||
operation='import_bom_drafts', message='BOM 表格来源记录已保存,工程位号待核验',
|
operation='import_bom_drafts', message='BOM 表格来源记录已保存,工程位号待核验',
|
||||||
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows}),
|
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows})})
|
||||||
'warnings': warnings})
|
|
||||||
try:
|
try:
|
||||||
report = inspect_batch(service, task_id, normalized, stop_event=stop_event, on_progress=on_progress,
|
report = inspect_batch(service, task_id, normalized, stop_event=stop_event, on_progress=on_progress,
|
||||||
on_phase=on_phase, spreadsheet_only=True, allow_partial=allow_partial)
|
on_phase=on_phase, spreadsheet_only=True, allow_partial=allow_partial)
|
||||||
@@ -113,7 +110,7 @@ def import_drafts(service, task_id, sources, *, stop_event=None, on_progress=Non
|
|||||||
if report.deferred and result.project_path not in failed_paths:
|
if report.deferred and result.project_path not in failed_paths:
|
||||||
reason = '表格已保存,执行前核验工程位号'
|
reason = '表格已保存,执行前核验工程位号'
|
||||||
annotated.append(replace(result, source_file=str(source.source), source_row=source.excel_row, reason=reason))
|
annotated.append(replace(result, source_file=str(source.source), source_row=source.excel_row, reason=reason))
|
||||||
report = replace(report, rows=tuple(annotated), source_map_path=mapping, warnings=tuple(warnings))
|
report = replace(report, rows=tuple(annotated), source_map_path=mapping)
|
||||||
if report.deferred:
|
if report.deferred:
|
||||||
accepted_sources = tuple(source for result, source in zip(report.rows, rows, strict=True)
|
accepted_sources = tuple(source for result, source in zip(report.rows, rows, strict=True)
|
||||||
if result.project_path not in failed_paths)
|
if result.project_path not in failed_paths)
|
||||||
|
|||||||
@@ -245,8 +245,7 @@ class TaskCenterService:
|
|||||||
on_phase(BomImportPhase.READING, message)
|
on_phase(BomImportPhase.READING, message)
|
||||||
if on_progress is not None:
|
if on_progress is not None:
|
||||||
on_progress(message)
|
on_progress(message)
|
||||||
warnings = []
|
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress,
|
||||||
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress, warnings=warnings,
|
|
||||||
**({'allow_partial': True} if allow_partial else {}))
|
**({'allow_partial': True} if allow_partial else {}))
|
||||||
scope = _scope(self._store, task_id)
|
scope = _scope(self._store, task_id)
|
||||||
paths = tuple(project.path for _, project in scope)
|
paths = tuple(project.path for _, project in scope)
|
||||||
@@ -279,7 +278,7 @@ class TaskCenterService:
|
|||||||
reason = '位号在 BOM 中重复(' + ';'.join(locations) + ')'
|
reason = '位号在 BOM 中重复(' + ';'.join(locations) + ')'
|
||||||
annotated.append(replace(row, source_file=str(source.source), source_row=source.excel_row,
|
annotated.append(replace(row, source_file=str(source.source), source_row=source.excel_row,
|
||||||
reason=reason + f';来源:{source.source} 第 {source.excel_row} 行'))
|
reason=reason + f';来源:{source.source} 第 {source.excel_row} 行'))
|
||||||
annotated_report = replace(report, rows=tuple(annotated), source_map_path=mapping, warnings=tuple(warnings))
|
annotated_report = replace(report, rows=tuple(annotated), source_map_path=mapping)
|
||||||
return bind_source_report(annotated_report,
|
return bind_source_report(annotated_report,
|
||||||
tuple(dict.fromkeys((str(row.source), row.source_sha256) for row in rows)), mapping)
|
tuple(dict.fromkeys((str(row.source), row.source_sha256) for row in rows)), mapping)
|
||||||
|
|
||||||
@@ -291,8 +290,7 @@ class TaskCenterService:
|
|||||||
write_routed_bom(normalized, rows, routes, project_names=names)
|
write_routed_bom(normalized, rows, routes, project_names=names)
|
||||||
append_task_event(self._logging, level='INFO', task_id=task_id,
|
append_task_event(self._logging, level='INFO', task_id=task_id,
|
||||||
operation='preview_bom_sources', message='BOM 导入来源记录已保存',
|
operation='preview_bom_sources', message='BOM 导入来源记录已保存',
|
||||||
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows}),
|
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows})})
|
||||||
'warnings': warnings})
|
|
||||||
report = inspect_batch(self, task_id, normalized, stop_event=stop_event,
|
report = inspect_batch(self, task_id, normalized, stop_event=stop_event,
|
||||||
on_progress=on_progress, on_phase=inspection_phase, runtime=runtime,
|
on_progress=on_progress, on_phase=inspection_phase, runtime=runtime,
|
||||||
**({'allow_partial': True} if allow_partial else {}))
|
**({'allow_partial': True} if allow_partial else {}))
|
||||||
|
|||||||
@@ -779,22 +779,21 @@ class ProjectPlanPanel(QWidget):
|
|||||||
report = state.report
|
report = state.report
|
||||||
if report is None:
|
if report is None:
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
warning_summary = f' · 警告 {len(report.warnings)} 项' if report.warnings else ''
|
|
||||||
if report.deferred:
|
if report.deferred:
|
||||||
failed_paths = {row.project_path for row in report.rows if row.status == 'failed'}
|
failed_paths = {row.project_path for row in report.rows if row.status == 'failed'}
|
||||||
accepted = tuple(row for row in report.rows if row.project_path not in failed_paths)
|
accepted = tuple(row for row in report.rows if row.project_path not in failed_paths)
|
||||||
summary = (f'BOM 表格已保存,工程位号待核验:{len(accepted)} 行、'
|
summary = (f'BOM 表格已保存,工程位号待核验:{len(accepted)} 行、'
|
||||||
f'{len({row.project_path for row in accepted})} 个工程;失败 {report.failed_rows} 行{warning_summary}。')
|
f'{len({row.project_path for row in accepted})} 个工程;失败 {report.failed_rows} 行。')
|
||||||
details = [summary, *report.warnings, '确认执行后仅核验当前工程;本次导入未读取工程位号。']
|
details = [summary, '确认执行后仅核验当前工程;本次导入未读取工程位号。']
|
||||||
details.extend(f'{row.project_name} · {Path(row.source_file).name} 第 {row.source_row} 行:{row.reason}'
|
details.extend(f'{row.project_name} · {Path(row.source_file).name} 第 {row.source_row} 行:{row.reason}'
|
||||||
for row in report.rows)
|
for row in report.rows)
|
||||||
return summary, '\n'.join(details), f'BOM 已保存 · 待核验{warning_summary} · 详情'
|
return summary, '\n'.join(details), 'BOM 已保存 · 待核验 · 详情'
|
||||||
outcome = '校验通过' if state.phase is BomImportPhase.PREVIEW_READY else '校验未通过'
|
outcome = '校验通过' if state.phase is BomImportPhase.PREVIEW_READY else '校验未通过'
|
||||||
summary = (f'BOM {outcome}:共 {report.total_rows} 行,通过 {report.passed_rows} 行、'
|
summary = (f'BOM {outcome}:共 {report.total_rows} 行,通过 {report.passed_rows} 行、'
|
||||||
f'失败 {report.failed_rows} 行、未检查 {report.unchecked_rows} 行;'
|
f'失败 {report.failed_rows} 行、未检查 {report.unchecked_rows} 行;'
|
||||||
f'共 {report.total_projects} 个工程,通过 {report.passed_projects} 个、'
|
f'共 {report.total_projects} 个工程,通过 {report.passed_projects} 个、'
|
||||||
f'失败 {report.failed_projects} 个、未检查 {report.unchecked_projects} 个{warning_summary}。')
|
f'失败 {report.failed_projects} 个、未检查 {report.unchecked_projects} 个。')
|
||||||
details = [summary, *report.errors, *report.warnings]
|
details = [summary, *report.errors]
|
||||||
if report.source_map_path is not None:
|
if report.source_map_path is not None:
|
||||||
details.append(f'导入来源记录:{report.source_map_path}')
|
details.append(f'导入来源记录:{report.source_map_path}')
|
||||||
details.extend(f'{Path(row.source_file).name + " · " if row.source_file else ""}'
|
details.extend(f'{Path(row.source_file).name + " · " if row.source_file else ""}'
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
"""Safe multi-file BOM loading and project routing for workspace imports."""
|
"""Safe multi-file BOM loading and project routing for workspace imports."""
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from difflib import get_close_matches
|
|
||||||
import hashlib
|
import hashlib
|
||||||
from pathlib import Path, PureWindowsPath
|
from pathlib import Path, PureWindowsPath
|
||||||
|
|
||||||
from openpyxl import load_workbook
|
from openpyxl import load_workbook
|
||||||
|
|
||||||
from .bom_import_report import BomImportReport, BomInspectionError
|
|
||||||
from .bom_plan import BOM_HEADERS, _normal_headers, _part_number_text, write_bom_template
|
from .bom_plan import BOM_HEADERS, _normal_headers, _part_number_text, write_bom_template
|
||||||
from .errors import TaskCenterError
|
from .errors import TaskCenterError
|
||||||
|
|
||||||
@@ -57,37 +55,7 @@ def _selected_xlsx(sources):
|
|||||||
return tuple(sorted(paths, key=lambda path: str(path).casefold()))
|
return tuple(sorted(paths, key=lambda path: str(path).casefold()))
|
||||||
|
|
||||||
|
|
||||||
_REQUIRED_HEADERS = (
|
def load_sources(sources, *, stop_event=None, on_progress=None, allow_partial=False):
|
||||||
('old_part_number', '旧料号'), ('new_part_number', '新料号'), ('refdes', '位号'),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _source_headers(path, cells):
|
|
||||||
headers = _normal_headers(tuple(cell.value for cell in cells))
|
|
||||||
names = tuple(name for name in headers if name)
|
|
||||||
unknown = tuple(str(cell.value).strip() for cell, name in zip(cells, headers, strict=True)
|
|
||||||
if not name and cell.value is not None and str(cell.value).strip())
|
|
||||||
if any(cell.data_type == 'f' for cell in cells):
|
|
||||||
reason = 'BOM 表头不接受公式'
|
|
||||||
elif len(names) != len(set(names)):
|
|
||||||
reason = 'BOM 列名重复'
|
|
||||||
else:
|
|
||||||
missing = [(name, label) for name, label in _REQUIRED_HEADERS if name not in names]
|
|
||||||
if not missing:
|
|
||||||
return {name: index for index, name in enumerate(headers) if name}, unknown
|
|
||||||
labels = '、'.join(label for _, label in missing)
|
|
||||||
hints = []
|
|
||||||
for name, label in missing:
|
|
||||||
matches = (get_close_matches(label, unknown, n=1, cutoff=.7)
|
|
||||||
or get_close_matches(name, unknown, n=1, cutoff=.8))
|
|
||||||
if matches:
|
|
||||||
hints.append(f'请将「{matches[0]}」改为「{label}」')
|
|
||||||
reason = '。'.join([f'BOM 缺少必需列「{labels}」', *hints])
|
|
||||||
message = f'{path.name} 第 1 行:{reason}'
|
|
||||||
raise BomInspectionError(TaskCenterError('bom_import', message), BomImportReport((), (), errors=(message,)))
|
|
||||||
|
|
||||||
|
|
||||||
def load_sources(sources, *, stop_event=None, on_progress=None, allow_partial=False, warnings=None):
|
|
||||||
"""Read every selected workbook before any CAD operation starts."""
|
"""Read every selected workbook before any CAD operation starts."""
|
||||||
from .operation_control import check_cancelled
|
from .operation_control import check_cancelled
|
||||||
|
|
||||||
@@ -106,7 +74,17 @@ def load_sources(sources, *, stop_event=None, on_progress=None, allow_partial=Fa
|
|||||||
if len(workbook.worksheets) != 1:
|
if len(workbook.worksheets) != 1:
|
||||||
raise ValueError('BOM 只能包含一个工作表')
|
raise ValueError('BOM 只能包含一个工作表')
|
||||||
rows = iter(workbook.active.iter_rows())
|
rows = iter(workbook.active.iter_rows())
|
||||||
positions, unknown = _source_headers(path, next(rows, ()))
|
header_cells = next(rows, ())
|
||||||
|
headers = _normal_headers(tuple(cell.value for cell in header_cells))
|
||||||
|
names = tuple(name for name in headers if name)
|
||||||
|
if len(names) != len(set(names)):
|
||||||
|
raise ValueError('BOM 列名重复')
|
||||||
|
required = {'old_part_number', 'new_part_number', 'refdes'}
|
||||||
|
if not required <= set(names):
|
||||||
|
raise ValueError('BOM 必须包含旧料号、新料号和位号列')
|
||||||
|
if any(cell.data_type == 'f' for cell in header_cells):
|
||||||
|
raise ValueError('BOM 表头不接受公式')
|
||||||
|
positions = {name: index for index, name in enumerate(headers) if name}
|
||||||
for excel_row, cells in enumerate(rows, 2):
|
for excel_row, cells in enumerate(rows, 2):
|
||||||
check_cancelled(stop_event)
|
check_cancelled(stop_event)
|
||||||
formula = any(cell.data_type == 'f' for cell in cells)
|
formula = any(cell.data_type == 'f' for cell in cells)
|
||||||
@@ -138,8 +116,6 @@ def load_sources(sources, *, stop_event=None, on_progress=None, allow_partial=Fa
|
|||||||
result.append(SourceRow(path, excel_row, values, value_mode, source_sha256))
|
result.append(SourceRow(path, excel_row, values, value_mode, source_sha256))
|
||||||
if hashlib.sha256(path.read_bytes()).hexdigest() != source_sha256:
|
if hashlib.sha256(path.read_bytes()).hexdigest() != source_sha256:
|
||||||
raise ValueError('BOM 来源在读取期间已改变,请重新导入')
|
raise ValueError('BOM 来源在读取期间已改变,请重新导入')
|
||||||
if warnings is not None:
|
|
||||||
warnings.extend(f'{path.name}:已忽略未知列「{name}」' for name in unknown)
|
|
||||||
except TaskCenterError:
|
except TaskCenterError:
|
||||||
raise
|
raise
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
import json
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
from openpyxl import load_workbook
|
|
||||||
from PySide6.QtWidgets import QFileDialog
|
|
||||||
|
|
||||||
from test_bom_batch import batch, records_for
|
|
||||||
from dx_productivity.trial_task_center.bom_plan import write_bom_template
|
|
||||||
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('case', ['extra', 'near', 'missing', 'header_formula', 'row_formula', 'original'])
|
|
||||||
def test_bom_header_feedback_through_workspace(case, batch, tmp_path, qtbot, monkeypatch):
|
|
||||||
service, _, tasks, targets, inventory_calls = batch
|
|
||||||
task = tasks[0]
|
|
||||||
record = records_for(tasks, targets)[0]
|
|
||||||
source = write_bom_template(tmp_path / f'{case}.xlsx', [record])
|
|
||||||
workbook = load_workbook(source)
|
|
||||||
sheet = workbook.active
|
|
||||||
if case == 'extra':
|
|
||||||
sheet['L1'], sheet['L2'] = '供应商', 'Example supplier'
|
|
||||||
sheet['M1'], sheet['M2'] = '备注', 'Example note'
|
|
||||||
elif case == 'near':
|
|
||||||
sheet['D1'] = '新料号编码'
|
|
||||||
elif case == 'missing':
|
|
||||||
sheet['D1'] = None
|
|
||||||
elif case == 'header_formula':
|
|
||||||
sheet['L1'] = '=1+1'
|
|
||||||
elif case == 'row_formula':
|
|
||||||
sheet['L1'], sheet['L2'] = '备注', '=1+1'
|
|
||||||
workbook.save(source)
|
|
||||||
workbook.close()
|
|
||||||
assert_workspace_import(case, source, task, service, inventory_calls, qtbot, monkeypatch)
|
|
||||||
|
|
||||||
|
|
||||||
def test_field_extra_column_through_workspace(batch, tmp_path, qtbot, monkeypatch):
|
|
||||||
field = os.environ.get('DX_ISSUE33_D5_FIELD')
|
|
||||||
if not field:
|
|
||||||
pytest.skip('set DX_ISSUE33_D5_FIELD to replay the field attachment')
|
|
||||||
service, _, tasks, targets, inventory_calls = batch
|
|
||||||
source = tmp_path / Path(field).name
|
|
||||||
workbook = load_workbook(field)
|
|
||||||
sheet = workbook.active
|
|
||||||
# Rebind to the local fixture project. Keep the original Excel header and BOM cells.
|
|
||||||
sheet['A2'] = tasks[0].name
|
|
||||||
sheet['B2'] = str(targets[tasks[0].task_id][0].project_path)
|
|
||||||
workbook.save(source)
|
|
||||||
workbook.close()
|
|
||||||
assert_workspace_import('field', source, tasks[0], service, inventory_calls, qtbot, monkeypatch)
|
|
||||||
|
|
||||||
|
|
||||||
def assert_workspace_import(case, source, task, service, inventory_calls, qtbot, monkeypatch):
|
|
||||||
window = TrialTaskCenterWindow(service)
|
|
||||||
window.auto_intervention_check.setChecked(False)
|
|
||||||
qtbot.addWidget(window)
|
|
||||||
window.open_task(task.task_id)
|
|
||||||
panel = window.plan_panel
|
|
||||||
qtbot.waitUntil(panel.import_bom_button.isEnabled, timeout=5000)
|
|
||||||
monkeypatch.setattr(QFileDialog, 'getOpenFileNames', lambda *args: ([str(source)], 'Excel (*.xlsx)'))
|
|
||||||
panel.import_bom_button.click()
|
|
||||||
qtbot.waitUntil(lambda: not window._workers, timeout=8000)
|
|
||||||
status = window.run_panel.operator_band.text()
|
|
||||||
print(status)
|
|
||||||
pending = service.pending_bom(task.task_id)
|
|
||||||
assert not inventory_calls
|
|
||||||
if case in {'extra', 'field', 'original', 'near', 'missing', 'header_formula'}:
|
|
||||||
panel.report_toggle.setChecked(True)
|
|
||||||
assert panel.report_dialog is not None
|
|
||||||
details = panel.report_dialog.view.toPlainText()
|
|
||||||
print(details)
|
|
||||||
if case in {'extra', 'field', 'original'}:
|
|
||||||
assert len(pending) == 1
|
|
||||||
assert panel.last_bom_report.failed_rows == 0 and panel.last_bom_report.deferred
|
|
||||||
if case == 'extra':
|
|
||||||
assert '失败 0 行' in status and '警告 2 项' in status
|
|
||||||
assert all(text in details for text in ('已忽略', '供应商', '备注', source.name))
|
|
||||||
assert pending[0].record.new == 'NEW-0'
|
|
||||||
events = (service._logging.root / 'tasks' / task.task_id / 'events.jsonl').read_text(encoding='utf-8')
|
|
||||||
entries = [json.loads(line) for line in events.splitlines()]
|
|
||||||
entry = next(event for event in entries if event['operation'] == 'import_bom_drafts')
|
|
||||||
assert tuple(entry['details']['warnings']) == panel.last_bom_report.warnings
|
|
||||||
elif case == 'field':
|
|
||||||
assert '警告 1 项' in status and 'extra_column' in details
|
|
||||||
else:
|
|
||||||
assert '警告' not in status and '已忽略' not in details
|
|
||||||
else:
|
|
||||||
assert not pending
|
|
||||||
if case == 'near':
|
|
||||||
assert '缺少必需列「新料号」' in status
|
|
||||||
assert '「新料号编码」' in details and '改为「新料号」' in details
|
|
||||||
elif case == 'missing':
|
|
||||||
assert '缺少必需列「新料号」' in status and '新料号' in details
|
|
||||||
elif case == 'header_formula':
|
|
||||||
assert 'BOM 表头不接受公式' in status and 'BOM 表头不接受公式' in details
|
|
||||||
else:
|
|
||||||
assert '第 2 行不接受公式' in status
|
|
||||||
window.close()
|
|
||||||
@@ -9,8 +9,6 @@ from test_bom_batch import batch
|
|||||||
|
|
||||||
|
|
||||||
def test_real_supervised_sources_roundtrip_origin_metadata_and_preview(batch, tmp_path):
|
def test_real_supervised_sources_roundtrip_origin_metadata_and_preview(batch, tmp_path):
|
||||||
from openpyxl import load_workbook
|
|
||||||
|
|
||||||
from dx_productivity.trial_task_center.bom_plan import write_bom_template
|
from dx_productivity.trial_task_center.bom_plan import write_bom_template
|
||||||
service, store, tasks, targets, calls = batch
|
service, store, tasks, targets, calls = batch
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
@@ -19,14 +17,9 @@ def test_real_supervised_sources_roundtrip_origin_metadata_and_preview(batch, tm
|
|||||||
'project_name': task.name, 'project_path': str(targets[task.task_id][0].project_path),
|
'project_name': task.name, 'project_path': str(targets[task.task_id][0].project_path),
|
||||||
'old_part_number': 'OLD', 'new_part_number': 'NEW', 'refdes': 'R1', 'value_mode': 'part_number',
|
'old_part_number': 'OLD', 'new_part_number': 'NEW', 'refdes': 'R1', 'value_mode': 'part_number',
|
||||||
},)) for index, task in enumerate(tasks))
|
},)) for index, task in enumerate(tasks))
|
||||||
workbook = load_workbook(sources[0])
|
|
||||||
workbook.active['M1'] = '备注'
|
|
||||||
workbook.save(sources[0])
|
|
||||||
workbook.close()
|
|
||||||
service._supervised = True
|
service._supervised = True
|
||||||
report = service.preview_bom_sources(tasks[0].task_id, sources)
|
report = service.preview_bom_sources(tasks[0].task_id, sources)
|
||||||
assert report.passed_rows == 2 and report.preview is not None
|
assert report.passed_rows == 2 and report.preview is not None
|
||||||
assert report.warnings == ('source-0.xlsx:已忽略未知列「备注」',)
|
|
||||||
assert tuple(row.source_file for row in report.rows) == tuple(str(path.resolve()) for path in sources)
|
assert tuple(row.source_file for row in report.rows) == tuple(str(path.resolve()) for path in sources)
|
||||||
assert all(row.source_row == 2 for row in report.rows)
|
assert all(row.source_row == 2 for row in report.rows)
|
||||||
assert report.source_map_path.is_file()
|
assert report.source_map_path.is_file()
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
"""Verify the original issue 33 evidence and summarize queues without running enclosed scripts."""
|
||||||
|
import argparse
|
||||||
|
from collections import Counter
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
|
|
||||||
|
def summarize(path):
|
||||||
|
with path.open('rb') as stream:
|
||||||
|
sha = hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||||
|
if sha != '1ac99eac3cf79bbf1f011d1d5fe833e92b98fba2c01546b3cfaf55a90b82d5b3':
|
||||||
|
raise ValueError('Expected the original 1.3.2 field bundle from issue 33')
|
||||||
|
queues = {}
|
||||||
|
batches = {}
|
||||||
|
with ZipFile(path) as archive:
|
||||||
|
manifest = next(n for n in archive.namelist() if n.endswith('/SHA256SUMS.txt'))
|
||||||
|
prefix = manifest.rsplit('/', 1)[0] + '/'
|
||||||
|
entries = archive.read(manifest).decode('utf-8-sig').splitlines()
|
||||||
|
for line in entries:
|
||||||
|
digest, member = line.split(None, 1)
|
||||||
|
with archive.open(prefix + member.strip().replace('\\', '/')) as stream:
|
||||||
|
if hashlib.file_digest(stream, 'sha256').hexdigest() != digest.lower():
|
||||||
|
raise ValueError('File checksum mismatch: ' + member)
|
||||||
|
for member in archive.namelist():
|
||||||
|
if '/data_full132/task-queues/' in member and member.endswith('.json'):
|
||||||
|
queue = json.loads(archive.read(member))
|
||||||
|
queues[Path(member).stem] = dict(
|
||||||
|
total=len(queue['task_ids']), phase=queue['phase'],
|
||||||
|
states=dict(Counter(row['state'] for row in queue['entries'].values())),
|
||||||
|
isolated=list(queue.get('isolated_tasks', {})))
|
||||||
|
if '/data_full132/batch-resources/' in member and member.endswith('/business-result.json'):
|
||||||
|
result = json.loads(archive.read(member))
|
||||||
|
fields = (result['payload'].get('result') or {}).get('fields', {})
|
||||||
|
if 'queue_id' in fields:
|
||||||
|
batches[result['batch_id']] = {key: fields.get(key) for key in
|
||||||
|
('queue_id', 'paused', 'current_task_id')}
|
||||||
|
return dict(sha256=sha, verified_files=len(entries), queues=queues, batch_results=batches)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument('bundle', type=Path)
|
||||||
|
print(json.dumps(summarize(parser.parse_args().bundle), ensure_ascii=False, indent=2))
|
||||||
Reference in new issue
Block a user