perf(bom): share validation and reuse the target inventory index

This commit is contained in:
阿白叔 committed 2026-10-15 21:45:05 +08:00
1 parent 6c0ca95d84
commit 45a9cc6e0c
4 files changed
+96 -96

No files matched your search

+32
View File
@@ -97,6 +97,38 @@ def test_scaffolds_skipped_but_header_and_bool_errors_report_excel_rows(batch, t
assert report.failed_rows == 1 and '第 1 行' in report.errors[0] and not calls
def test_strict_preview_rejects_corrupt_workbook_with_domain_error(batch, tmp_path):
service, store, tasks, targets, calls = batch
path = tmp_path / 'corrupt.xlsx'
path.write_bytes(b'not an Excel zip')
with pytest.raises(TaskCenterError) as caught:
service.preview_bom_batch(tasks[0].task_id, path)
assert caught.value.code == 'bom_import'
assert not calls
@pytest.mark.parametrize('strict', [False, True])
def test_cancellation_during_excel_parsing_keeps_operation_cancelled(batch, tmp_path, monkeypatch, strict):
from dx_productivity.trial_task_center import bom_import_report
service, store, tasks, targets, calls = batch
stop = Event()
path = write_bom_template(tmp_path / 'cancel-while-reading.xlsx', records_for(tasks, targets))
parse = bom_import_report.parse_bom_row
def cancel_after_first_row(*args):
record = parse(*args)
stop.set()
return record
monkeypatch.setattr(bom_import_report, 'parse_bom_row', cancel_after_first_row)
with pytest.raises(TaskCenterError) as caught:
if strict:
service.preview_bom_batch(tasks[0].task_id, path, stop_event=stop)
else:
service.inspect_bom_batch(tasks[0].task_id, path, stop_event=stop)
assert caught.value.code == 'operation_cancelled'
assert not calls
assert all(not store.list_target_plan(task.task_id) for task in tasks)
def test_ui_report_is_persistent_and_failure_does_not_stage(batch, tmp_path, qtbot, monkeypatch):
from PySide6.QtWidgets import QFileDialog
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow