fix(execution): bind explicit target cells to native save and recovery

This commit is contained in:
阿白叔 committed 2026-10-19 14:50:32 +08:00
1 parent 976a72d572
commit bb506a3550
7 files changed
+356 -20

No files matched your search

@@ -79,6 +79,8 @@ def test_invalid_transaction_evidence_never_promotes_pins(monkeypatch, tmp_path)
from types import SimpleNamespace
components = [SimpleNamespace(UID='outside-snapshot')]
(tmp_path / 'snapshot.tsv').write_text('L\tCELL\n')
monkeypatch.setattr(native_helper, 'target_cell_catalog', lambda *args: {})
monkeypatch.setattr(native_helper, 'read_snapshot', lambda path: (['M', 'project', 'OLD', 'NEW', 'sheet'],
[['C', 'recorded', 'R1', '0', '0', '0', '1', 'net']]))
monkeypatch.setattr(native_helper, 'attach', lambda: (object(), object()))
+37 -10
View File
@@ -6,7 +6,7 @@ from types import SimpleNamespace
import pytest
from dx_productivity.trial_task_center.errors import TaskCenterError
from dx_productivity.trial_task_center.native_helper import read_snapshot, transaction_binding
from dx_productivity.trial_task_center.native_helper import read_snapshot, transaction_binding, cell_catalog_binding
from dx_productivity.trial_task_center.quick_run import QuickRunPreparer, _read_commands, _read_status_details
from dx_productivity.trial_task_center.recovery import _is_link_or_reparse, _recovery_hashes, recover
@@ -30,7 +30,15 @@ def test_locked_recovery_files_return_stable_recovery_error(tmp_path, monkeypatc
@pytest.fixture
def interrupted(tmp_path):
def interrupted(tmp_path, monkeypatch):
import sys
library = tmp_path / 'library.lmc'
library.write_text('library fixture')
catalog = SimpleNamespace(library_path=library, part_partition='library', part_number='NEW',
cells=(SimpleNamespace(partition='RES', name='CELL'),), source_fingerprint='source-proof')
monkeypatch.setitem(sys.modules, 'dx_productivity.trial_task_center.cell_catalog', SimpleNamespace(
project_library_path=lambda project: library,
read_library_cell_catalog=lambda *args, **kwargs: catalog))
project = tmp_path / 'project' / 'one.prj'
project.parent.mkdir()
project.write_text('project')
@@ -40,20 +48,21 @@ def interrupted(tmp_path):
preparer = QuickRunPreparer(root, script_source=script, run_token_factory=lambda: 'first',
cscript_resolver=lambda: Path('cscript.exe'))
projects = (SimpleNamespace(path=project, selected=True, available=True),)
rules = (SimpleNamespace(old_part_number='OLD', new_part_number='NEW', enabled=True),)
rules = (SimpleNamespace(old_part_number='OLD', new_part_number='NEW', enabled=True, target_cell='CELL'),)
handoff = preparer.prepare('task', projects, rules, copy_part_number_to_value=True)
job = _read_commands(handoff.command_path)[0][1]
snapshot = handoff.command_path.parent / f'snapshot-{job}.tsv'
snapshot.write_text(f'M\t{project}\tOLD\tNEW\tA:1\tpart_label\nC\tuid\tR1\t0\t0\t0\t1\tpins\n', encoding='utf-8')
snapshot.write_text(f'M\t{project}\tOLD\tNEW\tA:1\tpart_label\nL\tCELL\nC\tuid\tR1\t0\t0\t0\t1\tpins\n', encoding='utf-8')
metadata, components = read_snapshot(snapshot)
cell_proof = cell_catalog_binding(library, 'NEW', 'CELL', snapshot.parent / 'cell-catalog')
report = {'stage': 'native_replace_verified', 'transaction': transaction_binding(
snapshot, metadata, components, ['library', 'NEW', 'symbol', '', 'cap', 'label'], 'symbol')}
snapshot, metadata, components, ['library', 'NEW', 'symbol', '', 'cap', 'label'], 'symbol', cell_catalog=cell_proof)}
snapshot.with_suffix('.tsv.native.json').write_text(json.dumps(report), encoding='utf-8')
handoff.status_path.write_text('job_id\tstate\tcode\tmessage\n' + job + '\tawaiting_native_replace\t\tstarted\n', encoding='utf-8')
lock = handoff.command_path.parent / 'uncertain.flag'
lock.write_text('old timeout')
return SimpleNamespace(preparer=preparer, root=root, projects=projects, rules=rules, snapshot=snapshot,
job=job, handoff=handoff, lock=lock, report=report)
job=job, handoff=handoff, lock=lock, report=report, catalog=catalog, cell_proof=cell_proof)
def invoke(fixture, **kwargs):
@@ -134,7 +143,7 @@ def test_r12_part_number_queue_keeps_recorded_policy_during_recovery(interrupted
metadata, components = read_snapshot(interrupted.snapshot)
report = {'stage': 'native_replace_verified', 'transaction': transaction_binding(
interrupted.snapshot, metadata, components,
['library', 'NEW', 'symbol', '', 'cap', 'label'], 'symbol')}
['library', 'NEW', 'symbol', '', 'cap', 'label'], 'symbol', cell_catalog=interrupted.cell_proof)}
interrupted.snapshot.with_suffix('.tsv.native.json').write_text(json.dumps(report), encoding='utf-8')
def worker(command, timeout):
@@ -154,8 +163,8 @@ def test_r12_part_number_queue_keeps_recorded_policy_during_recovery(interrupted
def test_page_addressed_recovery_keeps_the_original_sheet_binding(interrupted):
project = interrupted.projects[0].path
interrupted.handoff.command_path.write_text(
'task_id\tjob_id\tproject_path\tschematic_name\tsheet_number\told_part\tnew_part\tvalue_mode\n'
f'task\t{interrupted.job}\t{project}\tA\t1\tOLD\tNEW\tpart_label\n',
'task_id\tjob_id\tproject_path\tschematic_name\tsheet_number\told_part\tnew_part\tvalue_mode\ttarget_cell\n'
f'task\t{interrupted.job}\t{project}\tA\t1\tOLD\tNEW\tpart_label\tCELL\n',
encoding='utf-8',
)
(interrupted.handoff.command_path.parent / 'sheets.tsv').write_text(
@@ -270,7 +279,7 @@ def test_service_recovery_updates_queue_and_database(interrupted, initial):
service.set_copy_part_number_to_value(task.task_id, True)
projects = service.scan_projects(task.task_id, interrupted.projects[0].path.parent)
service.set_project_selected(projects[0].project_id, True)
service.add_rule(task.task_id, 'OLD', 'NEW')
service.add_rule(task.task_id, 'OLD', 'NEW', target_cell='CELL')
command_path = interrupted.handoff.command_path
command_path.write_text(command_path.read_text().replace('task\t', task.task_id + '\t'), encoding='utf-8')
if store.get_task(task.task_id).status is TaskStatus.DRAFT:
@@ -286,3 +295,21 @@ def test_service_recovery_updates_queue_and_database(interrupted, initial):
assert store.get_task(task.task_id).status is TaskStatus.COMPLETED
assert service.quick_run_progress(task.task_id).queue_complete
assert not service.has_interrupted_quick_run(task.task_id)
@pytest.mark.parametrize('fault',['source_changed','choice_removed','proof_missing'])
def test_cell_catalog_drift_blocks_recovery_before_worker(interrupted,fault):
calls=[]
interrupted.preparer._process_runner=lambda *args:calls.append(args)
if fault=='source_changed':
interrupted.catalog.source_fingerprint='changed'
elif fault=='choice_removed':
interrupted.catalog.cells=()
else:
interrupted.report['transaction'].pop('cell_catalog')
interrupted.snapshot.with_suffix('.tsv.native.json').write_text(json.dumps(interrupted.report),encoding='utf8')
before=interrupted.handoff.status_path.read_bytes()
with pytest.raises(TaskCenterError,match='quick_run_recovery'):
invoke(interrupted)
assert calls==[]
assert interrupted.lock.exists()
assert interrupted.handoff.status_path.read_bytes()==before