"""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'