fix(config): write a migrated config file in place if it is not replaceable

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
Christin
2026-11-20 18:39:14 +01:00
committed by Bobby Noelte
co-authored by Claude Opus 5.5
parent f3773de8f8
commit fed03a0069
2 changed files with 29 additions and 8 deletions
+18 -2
View File
@@ -1,5 +1,6 @@
# Test data directory and known migration pairs
import copy
import errno
import json
import os
import shutil
@@ -180,16 +181,31 @@ class TestConfigMigration:
def test_migrate_config_file_write_failure_keeps_original(
self, tmp_config_file: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""A migrated file that can not replace the old one leaves the old file in place."""
"""A migrated configuration that can not be written leaves the old file in place."""
original = tmp_config_file.read_bytes()
backup_file = tmp_config_file.with_suffix(".bak")
monkeypatch.setattr(os, "replace", Mock(side_effect=OSError("replace failed")))
monkeypatch.setattr(os, "fsync", Mock(side_effect=OSError("disk full")))
assert configmigrate.migrate_config_file(tmp_config_file, backup_file) is False
assert tmp_config_file.read_bytes() == original
assert not list(tmp_config_file.parent.glob("*.tmp"))
def test_migrate_config_file_writes_in_place_if_not_replaceable(
self, tmp_config_file: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""A file that can not be replaced, e.g. a single-file bind mount, is written in place."""
original = tmp_config_file.read_bytes()
backup_file = tmp_config_file.with_suffix(".bak")
monkeypatch.setattr(os, "replace", Mock(side_effect=OSError(errno.EBUSY, "busy")))
assert configmigrate.migrate_config_file(tmp_config_file, backup_file) is True
assert backup_file.read_bytes() == original
migrated_data = json.loads(tmp_config_file.read_text(encoding="utf-8"))
assert migrated_data["general"]["version"] == __version__
assert not list(tmp_config_file.parent.glob("*.tmp"))
@pytest.mark.parametrize("old_file, expected_file", MIGRATION_PAIRS)
def test_migrate_old_version_config(self, tmp_path: Path, old_file: Path, expected_file: Path):