Skip to content

Commit 77512a9

Browse files
fix(config): treat empty backup dir as unset
1 parent ed411c9 commit 77512a9

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

recoleta/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,8 @@ def _normalize_db_path(cls, value: str | Path) -> Path:
16371637
def _normalize_optional_path(cls, value: str | Path | None) -> Path | None:
16381638
if value is None:
16391639
return None
1640+
if isinstance(value, str) and not value.strip():
1641+
return None
16401642
return Path(value).expanduser().resolve()
16411643

16421644
@field_validator("rag_lancedb_dir", mode="before")

tests/test_recoleta_specs_maintenance_cli.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,38 @@ def test_admin_backup_honors_env_backup_output_dir_when_settings_are_skipped(
353353
assert (bundle_dirs[0] / "manifest.json").exists()
354354

355355

356+
def test_admin_backup_falls_back_when_configured_backup_output_dir_is_empty(
357+
tmp_path: Path,
358+
) -> None:
359+
runner = CliRunner()
360+
db_path = tmp_path / "recoleta.db"
361+
config_path = tmp_path / "recoleta.yaml"
362+
config_path.write_text(
363+
"\n".join(
364+
[
365+
f'RECOLETA_DB_PATH: "{db_path}"',
366+
'LLM_MODEL: "openai/gpt-4o-mini"',
367+
'BACKUP_OUTPUT_DIR: ""',
368+
]
369+
),
370+
encoding="utf-8",
371+
)
372+
373+
repository = Repository(db_path=db_path)
374+
repository.init_schema()
375+
376+
result = runner.invoke(
377+
recoleta.cli.app,
378+
["admin", "backup", "--config", str(config_path)],
379+
)
380+
381+
assert result.exit_code == 0
382+
fallback_root = (db_path.parent / "backups").resolve()
383+
bundle_dirs = [path for path in fallback_root.iterdir() if path.is_dir()]
384+
assert len(bundle_dirs) == 1
385+
assert (bundle_dirs[0] / "manifest.json").exists()
386+
387+
356388
def test_restore_exits_when_workspace_lock_is_held(tmp_path: Path) -> None:
357389
runner = CliRunner()
358390
db_path = tmp_path / "recoleta.db"

tests/test_recoleta_specs_settings.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ def test_settings_loads_backup_output_dir_from_env(
4848
assert settings.backup_output_dir == backup_root.resolve()
4949

5050

51+
def test_settings_treats_empty_backup_output_dir_env_as_unset(
52+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
53+
) -> None:
54+
monkeypatch.delenv("RECOLETA_CONFIG_PATH", raising=False)
55+
monkeypatch.setenv("RECOLETA_DB_PATH", str(tmp_path / "recoleta.db"))
56+
monkeypatch.setenv("LLM_MODEL", "openai/gpt-4o-mini")
57+
monkeypatch.setenv("PUBLISH_TARGETS", "markdown")
58+
monkeypatch.setenv("BACKUP_OUTPUT_DIR", "")
59+
60+
settings = Settings() # pyright: ignore[reportCallIssue]
61+
62+
assert settings.backup_output_dir is None
63+
64+
5165
def test_settings_rejects_configured_source_without_enabled(
5266
configured_env, monkeypatch: pytest.MonkeyPatch
5367
) -> None:

0 commit comments

Comments
 (0)