Extract durable batch backup coordination from queue execution

This commit is contained in:
阿白叔 committed 2026-10-15 09:33:35 +08:00
1 parent 44b4f5be48
commit 3e45040def
3 files changed
+274 -215

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
"""Backup coordination keeps durable state independent of CAD execution."""
from pathlib import Path
from types import SimpleNamespace
import pytest
from dx_productivity.trial_task_center.errors import TaskCenterError
def test_backup_failure_is_durable_before_propagating(tmp_path):
from dx_productivity.trial_task_center.batch_backup import BatchBackupCoordinator
project = tmp_path / 'board.prj'
project.write_text('project')
root = tmp_path / 'queue'
session = SimpleNamespace(handoff=SimpleNamespace(command_path=root / 'command.tsv'),
commands=(), latest={}, next_index=0)
service = SimpleNamespace(_quick_run_preparer=SimpleNamespace(data_root=tmp_path / 'data'),
_logging=None)
writes = []
def fail(*args):
raise TaskCenterError('quick_run_backup', 'backup failed')
def write(path, task_id, state):
writes.append((path, task_id, dict(state)))
coordinator = BatchBackupCoordinator(service, 't', session,
(SimpleNamespace(path=project),), continue_after_failure=False,
backup=fail, write_state=write)
coordinator.perform_backup = lambda *args: fail()
with coordinator, pytest.raises(TaskCenterError, match='backup failed'):
coordinator.prepare(project, SimpleNamespace())
assert writes[0][1] == 't'
assert next(iter(writes[0][2].values()))['status'] == 'unbacked'