fix: allow replacement without an explicit target cell
This commit is contained in:
1 parent
81a8547352
commit
d12478efd8
10 files changed
+141
-68
No files matched your search
@@ -131,7 +131,7 @@ def transaction_binding(snapshot, metadata, records, library_row, symbol, slot_c
|
||||
if cell is not None:
|
||||
result["target_cell"] = cell
|
||||
if cell_catalog is not None:
|
||||
if cell_catalog.get("selected") != cell or cell_catalog.get("part_partition") != str(library_row[0]):
|
||||
if cell is None or cell_catalog.get("selected") != cell or cell_catalog.get("part_partition") != str(library_row[0]):
|
||||
raise ValueError("Native library row differs from authoritative Cell catalog")
|
||||
result["cell_catalog"] = cell_catalog
|
||||
return result
|
||||
@@ -160,6 +160,8 @@ def require_resumable_transaction(snapshot, report, metadata, records):
|
||||
expected["target_cell"] = cell
|
||||
if not isinstance(binding, dict) or any(binding.get(key) != value for key, value in expected.items()):
|
||||
raise ValueError("Native replacement evidence does not match this snapshot")
|
||||
if cell is None and ("target_cell" in binding or "cell_catalog" in binding):
|
||||
raise ValueError("Unexpected target Cell evidence for an unselected snapshot")
|
||||
library_row = binding.get("library_row")
|
||||
if not isinstance(library_row, list) or len(library_row) < 6:
|
||||
raise ValueError("Native replacement evidence has no target library identity")
|
||||
@@ -511,11 +513,11 @@ def run_native(snapshot, report):
|
||||
from pywinauto import Desktop
|
||||
|
||||
metadata, records = read_snapshot(snapshot)
|
||||
target_cell = snapshot_target_cell(snapshot)
|
||||
target_cell = snapshot_target_cell(snapshot, required=False)
|
||||
require_part_label = snapshot_value_mode(metadata) == "part_label"
|
||||
app, api = attach()
|
||||
check_active_context(app, metadata)
|
||||
cell_proof = target_cell_catalog(app, snapshot, metadata, target_cell)
|
||||
cell_proof = target_cell_catalog(app, snapshot, metadata, target_cell) if target_cell is not None else None
|
||||
components = components_on_sheet(app, api)
|
||||
wanted = {row[1] for row in records}
|
||||
if len(metadata) == 10:
|
||||
@@ -697,7 +699,7 @@ def run_native(snapshot, report):
|
||||
if read_target() != ready:
|
||||
raise ValueError('Native target changed during final context verification')
|
||||
symbol = ready[1]
|
||||
current_cell_proof = target_cell_catalog(app, snapshot, metadata, target_cell)
|
||||
current_cell_proof = target_cell_catalog(app, snapshot, metadata, target_cell) if target_cell is not None else None
|
||||
if current_cell_proof != cell_proof:
|
||||
raise ValueError("Cell catalog changed before native replacement; no replacement submitted")
|
||||
report["transaction"] = transaction_binding(snapshot, metadata, records, columns, symbol, slot_count,
|
||||
|
||||
@@ -86,7 +86,11 @@ def _recovery_copytree(source: Path, destination: Path) -> None:
|
||||
|
||||
|
||||
def require_current_cell_binding(snapshot, binding, project, metadata):
|
||||
cell = snapshot_target_cell(snapshot)
|
||||
cell = snapshot_target_cell(snapshot, required=False)
|
||||
if cell is None:
|
||||
if 'target_cell' in binding or 'cell_catalog' in binding:
|
||||
raise ValueError('Unexpected target Cell evidence for an unselected snapshot')
|
||||
return None
|
||||
if binding.get('target_cell') != cell or not isinstance(binding.get('cell_catalog'), dict):
|
||||
raise ValueError('Recovery has no bound target Cell catalog')
|
||||
from .cell_catalog import project_library_path
|
||||
@@ -160,8 +164,8 @@ def recover(preparer, task_id, projects, rules, *, copy_part_number_to_value=Fal
|
||||
raise ValueError('snapshot target scope missing from command')
|
||||
report = json.loads(snapshot.with_suffix('.tsv.native.json').read_text(encoding='utf-8'))
|
||||
binding = require_resumable_transaction(snapshot, report, metadata, components)
|
||||
selected_cell = _read_command_cells(root / 'command.tsv').get(job_id)
|
||||
if selected_cell != snapshot_target_cell(snapshot):
|
||||
selected_cell = _read_command_cells(root / 'command.tsv').get(job_id) or None
|
||||
if selected_cell != snapshot_target_cell(snapshot, required=False):
|
||||
raise ValueError('snapshot target Cell mismatch')
|
||||
cell_proof = require_current_cell_binding(snapshot, binding, Path(selected[2]), metadata)
|
||||
identity = binding['library_row'][4:6]
|
||||
@@ -213,8 +217,9 @@ def recover(preparer, task_id, projects, rules, *, copy_part_number_to_value=Fal
|
||||
if len(metadata) == 10:
|
||||
header += '\ttarget_scope\ttarget_selectors'
|
||||
row = (*row, 'targets', selectors)
|
||||
header += '\ttarget_cell\trecovery_library_path'
|
||||
row = (*row, _encode_vbs_field(selected_cell), _encode_vbs_field(cell_proof['library_path']))
|
||||
if selected_cell is not None:
|
||||
header += '\ttarget_cell\trecovery_library_path'
|
||||
row = (*row, _encode_vbs_field(selected_cell), _encode_vbs_field(cell_proof['library_path']))
|
||||
(worker / 'command.tsv').write_text(header + '\n' + '\t'.join(row) + '\n', encoding='utf-8')
|
||||
_write_status_details(worker / 'status.tsv', ())
|
||||
from .quick_run import _vbs_worker_paths
|
||||
|
||||
@@ -352,13 +352,6 @@ class TaskCenterService:
|
||||
),
|
||||
)
|
||||
|
||||
def validate_target_cells(self, task_id: str) -> None:
|
||||
"""Cheap draft preflight; the native commit revalidates library authority."""
|
||||
for rule in self._execution_rules(task_id):
|
||||
if rule.enabled and not rule.target_cell.strip():
|
||||
raise TaskCenterError('target_cell_required',
|
||||
f'新料号 {rule.new_part_number} 未选择目标封装,请编辑料号规则并读取选择 Cell Name')
|
||||
|
||||
def target_cell_projects(self, task_id: str) -> tuple[Path, ...]:
|
||||
"""Capture the project scope used to bind asynchronous Cell choices."""
|
||||
from .batch_rules import members
|
||||
|
||||
@@ -59,13 +59,13 @@ class _MappingDialog(QDialog):
|
||||
self._cell_workers = set()
|
||||
self._cell_closed = False
|
||||
self.cell_combo = QComboBox(objectName='targetCellCombo')
|
||||
self.cell_combo.addItem('请选择目标封装', '')
|
||||
self.cell_combo.addItem('不指定封装(可选)', '')
|
||||
if target_cell:
|
||||
self.cell_combo.addItem(target_cell, target_cell)
|
||||
self.cell_combo.setCurrentIndex(1)
|
||||
self.cell_load_button = QPushButton('读取封装', objectName='loadTargetCells')
|
||||
self.cell_load_button.setEnabled(cell_loader is not None)
|
||||
self.cell_status = QLabel('已保存选择;可重新读取核对' if target_cell else '输入新料号后读取并选择封装')
|
||||
self.cell_status = QLabel('已保存选择;可重新读取核对' if target_cell else '未指定时不主动修改封装,可后续与中心库同步')
|
||||
self.new_edit.textChanged.connect(self._new_part_changed)
|
||||
self.cell_combo.currentIndexChanged.connect(self._cell_selection_changed)
|
||||
self.cell_load_button.clicked.connect(self._load_cells)
|
||||
@@ -86,7 +86,7 @@ class _MappingDialog(QDialog):
|
||||
cell_row = QHBoxLayout()
|
||||
cell_row.addWidget(self.cell_combo, 1)
|
||||
cell_row.addWidget(self.cell_load_button)
|
||||
form.addRow('目标封装', cell_row)
|
||||
form.addRow('目标封装(可选)', cell_row)
|
||||
form.addRow('', self.cell_status)
|
||||
form.addRow("执行状态", self.enabled_check)
|
||||
form.addRow("自定义 Value", self.custom_value_check)
|
||||
@@ -119,14 +119,14 @@ class _MappingDialog(QDialog):
|
||||
def _cell_selection_changed(self, _index):
|
||||
self._cell_generation += 1
|
||||
self.cell_load_button.setEnabled(self._cell_loader is not None)
|
||||
self.cell_status.setText('已选择目标封装' if self.target_cell else '未选择目标封装,可保存草稿')
|
||||
self.cell_status.setText('已选择目标封装' if self.target_cell else '未指定时不主动修改封装,可后续与中心库同步')
|
||||
|
||||
def _new_part_changed(self, _text):
|
||||
self._cell_generation += 1
|
||||
with QSignalBlocker(self.cell_combo):
|
||||
self.cell_combo.clear()
|
||||
self.cell_combo.addItem('请选择目标封装', '')
|
||||
self.cell_status.setText('新料号已改变,请重新读取封装')
|
||||
self.cell_combo.addItem('不指定封装(可选)', '')
|
||||
self.cell_status.setText('新料号已改变;如需指定封装,请重新读取')
|
||||
self.cell_load_button.setEnabled(self._cell_loader is not None)
|
||||
|
||||
def _close_cells(self, _result):
|
||||
@@ -166,12 +166,12 @@ class _MappingDialog(QDialog):
|
||||
return
|
||||
with QSignalBlocker(self.cell_combo):
|
||||
self.cell_combo.clear()
|
||||
self.cell_combo.addItem('请选择目标封装', '')
|
||||
self.cell_combo.addItem('不指定封装(可选)', '')
|
||||
for choice in choices:
|
||||
self.cell_combo.addItem(choice, choice)
|
||||
index = self.cell_combo.findData(selected)
|
||||
self.cell_combo.setCurrentIndex(max(0, index))
|
||||
self.cell_status.setText(f'已读取 {len(choices)} 个封装,请明确选择' if choices else '未找到可用封装')
|
||||
self.cell_status.setText(f'已读取 {len(choices)} 个封装;可留空或明确选择' if choices else '未找到可用封装')
|
||||
self.cell_load_button.setEnabled(True)
|
||||
def failed(error):
|
||||
if current():
|
||||
|
||||
@@ -494,11 +494,6 @@ class TrialTaskCenterWindow(QMainWindow):
|
||||
if not self.run_panel.quick_run_button.isEnabled():
|
||||
return
|
||||
context = self._context
|
||||
try:
|
||||
self.service.validate_target_cells(context.task.task_id)
|
||||
except TaskCenterError as error:
|
||||
self._show_error(error)
|
||||
return
|
||||
enabled = sum(row.enabled for row in context.targets) if context.task.target_plan_mode else sum(r.enabled for r in context.rules)
|
||||
if not self._quick_run_confirmer('current', 1, enabled):
|
||||
return
|
||||
@@ -519,12 +514,6 @@ class TrialTaskCenterWindow(QMainWindow):
|
||||
key=lambda t: t.group_position)
|
||||
if not tasks:
|
||||
return
|
||||
try:
|
||||
for task in tasks:
|
||||
self.service.validate_target_cells(task.task_id)
|
||||
except TaskCenterError as error:
|
||||
self._show_error(error)
|
||||
return
|
||||
token, ids = self._project_queues.get(group, (None, tuple(t.task_id for t in tasks)))
|
||||
if self.plan_panel.has_unsaved_plan(ids):
|
||||
self._set_operator_message('本批任务有未保存计划,请先逐个保存。', 'warning')
|
||||
|
||||
Reference in new issue
Block a user