fix(cli): remove the temp catalog when the atomic replace fails

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
jesus 2026-09-09 22:36:09 +00:00
parent d1653fa40d
commit 96bf276ab9
2 changed files with 12 additions and 1 deletions

View file

@ -453,7 +453,11 @@ def _replace_file(path: Path, text: str) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile("w", encoding="utf-8", dir=path.parent, delete=False) as tmp:
_ = tmp.write(text)
os.replace(tmp.name, path)
try:
os.replace(tmp.name, path)
except OSError:
Path(tmp.name).unlink(missing_ok=True)
raise
def codex_model_sync_args(

View file

@ -481,6 +481,13 @@ class TestCodexModelSync:
assert isinstance(result, ModelSyncSkipped)
assert "could not write" in result.reason
def test_failed_replace_is_reported_and_leaves_no_temp_file(self, tmp_path):
(tmp_path / "litellm-models.json").mkdir()
_, result = self._sync(self._listing(self._row("m")), tmp_path)
assert isinstance(result, ModelSyncSkipped)
assert "could not write" in result.reason
assert [p.name for p in tmp_path.iterdir()] == ["litellm-models.json"]
def test_unreachable_proxy_is_reported_not_raised(self, tmp_path):
def boom(*a, **k):
raise requests.ConnectionError("refused")