Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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,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
|
||||
passed_preview: BomBatchPreview | None = None
|
||||
deferred: bool = False
|
||||
warnings: tuple[str, ...] = ()
|
||||
|
||||
@property
|
||||
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):
|
||||
"""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, warnings=warnings)
|
||||
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress, allow_partial=allow_partial)
|
||||
scope = _scope(service._store, task_id)
|
||||
paths = tuple(project.path for _, 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)
|
||||
append_task_event(service._logging, level='INFO', task_id=task_id,
|
||||
operation='import_bom_drafts', message='BOM 表格来源记录已保存,工程位号待核验',
|
||||
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows}),
|
||||
'warnings': warnings})
|
||||
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows})})
|
||||
try:
|
||||
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)
|
||||
@@ -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:
|
||||
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:
|
||||
accepted_sources = tuple(source for result, source in zip(report.rows, rows, strict=True)
|
||||
if result.project_path not in failed_paths)
|
||||
|
||||
@@ -245,8 +245,7 @@ class TaskCenterService:
|
||||
on_phase(BomImportPhase.READING, message)
|
||||
if on_progress is not None:
|
||||
on_progress(message)
|
||||
warnings = []
|
||||
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress, warnings=warnings,
|
||||
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress,
|
||||
**({'allow_partial': True} if allow_partial else {}))
|
||||
scope = _scope(self._store, task_id)
|
||||
paths = tuple(project.path for _, project in scope)
|
||||
@@ -279,7 +278,7 @@ class TaskCenterService:
|
||||
reason = '位号在 BOM 中重复(' + ';'.join(locations) + ')'
|
||||
annotated.append(replace(row, source_file=str(source.source), source_row=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,
|
||||
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)
|
||||
append_task_event(self._logging, level='INFO', task_id=task_id,
|
||||
operation='preview_bom_sources', message='BOM 导入来源记录已保存',
|
||||
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows}),
|
||||
'warnings': warnings})
|
||||
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows})})
|
||||
report = inspect_batch(self, task_id, normalized, stop_event=stop_event,
|
||||
on_progress=on_progress, on_phase=inspection_phase, runtime=runtime,
|
||||
**({'allow_partial': True} if allow_partial else {}))
|
||||
|
||||
@@ -779,22 +779,21 @@ class ProjectPlanPanel(QWidget):
|
||||
report = state.report
|
||||
if report is None:
|
||||
return '', '', ''
|
||||
warning_summary = f' · 警告 {len(report.warnings)} 项' if report.warnings else ''
|
||||
if report.deferred:
|
||||
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)
|
||||
summary = (f'BOM 表格已保存,工程位号待核验:{len(accepted)} 行、'
|
||||
f'{len({row.project_path for row in accepted})} 个工程;失败 {report.failed_rows} 行{warning_summary}。')
|
||||
details = [summary, *report.warnings, '确认执行后仅核验当前工程;本次导入未读取工程位号。']
|
||||
f'{len({row.project_path for row in accepted})} 个工程;失败 {report.failed_rows} 行。')
|
||||
details = [summary, '确认执行后仅核验当前工程;本次导入未读取工程位号。']
|
||||
details.extend(f'{row.project_name} · {Path(row.source_file).name} 第 {row.source_row} 行:{row.reason}'
|
||||
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 '校验未通过'
|
||||
summary = (f'BOM {outcome}:共 {report.total_rows} 行,通过 {report.passed_rows} 行、'
|
||||
f'失败 {report.failed_rows} 行、未检查 {report.unchecked_rows} 行;'
|
||||
f'共 {report.total_projects} 个工程,通过 {report.passed_projects} 个、'
|
||||
f'失败 {report.failed_projects} 个、未检查 {report.unchecked_projects} 个{warning_summary}。')
|
||||
details = [summary, *report.errors, *report.warnings]
|
||||
f'失败 {report.failed_projects} 个、未检查 {report.unchecked_projects} 个。')
|
||||
details = [summary, *report.errors]
|
||||
if report.source_map_path is not None:
|
||||
details.append(f'导入来源记录:{report.source_map_path}')
|
||||
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."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from difflib import get_close_matches
|
||||
import hashlib
|
||||
from pathlib import Path, PureWindowsPath
|
||||
|
||||
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 .errors import TaskCenterError
|
||||
|
||||
@@ -57,37 +55,7 @@ def _selected_xlsx(sources):
|
||||
return tuple(sorted(paths, key=lambda path: str(path).casefold()))
|
||||
|
||||
|
||||
_REQUIRED_HEADERS = (
|
||||
('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):
|
||||
def load_sources(sources, *, stop_event=None, on_progress=None, allow_partial=False):
|
||||
"""Read every selected workbook before any CAD operation starts."""
|
||||
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:
|
||||
raise ValueError('BOM 只能包含一个工作表')
|
||||
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):
|
||||
check_cancelled(stop_event)
|
||||
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))
|
||||
if hashlib.sha256(path.read_bytes()).hexdigest() != source_sha256:
|
||||
raise ValueError('BOM 来源在读取期间已改变,请重新导入')
|
||||
if warnings is not None:
|
||||
warnings.extend(f'{path.name}:已忽略未知列「{name}」' for name in unknown)
|
||||
except TaskCenterError:
|
||||
raise
|
||||
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):
|
||||
from openpyxl import load_workbook
|
||||
|
||||
from dx_productivity.trial_task_center.bom_plan import write_bom_template
|
||||
service, store, tasks, targets, calls = batch
|
||||
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),
|
||||
'old_part_number': 'OLD', 'new_part_number': 'NEW', 'refdes': 'R1', 'value_mode': 'part_number',
|
||||
},)) for index, task in enumerate(tasks))
|
||||
workbook = load_workbook(sources[0])
|
||||
workbook.active['M1'] = '备注'
|
||||
workbook.save(sources[0])
|
||||
workbook.close()
|
||||
service._supervised = True
|
||||
report = service.preview_bom_sources(tasks[0].task_id, sources)
|
||||
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 all(row.source_row == 2 for row in report.rows)
|
||||
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