Slice 1: Path resolution engine & config loading #22

Closed
opened 2026-06-04 09:29:14 +02:00 by AlexKucera · 1 comment
AlexKucera commented 2026-06-04 09:29:14 +02:00 (Migrated from github.com)

Parent

#21 — Feature: XDG config path resolution with CWD fallback

What to build

Build the path resolution engine and wire it into the config loader. A new internal function resolves a filename by checking ~/.config/librofm-downloader/ (XDG) first, then falling back to the current working directory. The XDG parent directory is auto-created on demand with mkdir(parents=True, exist_ok=True). Returns the resolved Path if found, None if absent from both locations.

Wire this resolver into load_config() so that passing None for either path triggers search. When config.yaml is missing everywhere: non-fatal — return a fully-defaulted Config instance and raise no exception. When secrets.yaml is missing everywhere: fatal — raise a domain error (ConfigError subclass) with a message listing every path searched in order. All raw FileNotFoundError / OSError from file I/O are caught internally and converted to domain errors — no OS exceptions leak to callers.

Acceptance criteria

  • _resolve_config_file(filename) exists, searches XDG then CWD, returns Path | None
  • XDG directory ~/.config/librofm-downloader/ is auto-created when resolution runs
  • load_config(None, None) with only secrets present → returns Config with built-in defaults for format/output_dir/extras/covers
  • load_config(None, None) with neither file → raises domain error listing searched paths (not FileNotFoundError)
  • load_config(explicit_path, None) with explicit config path → skips search for config, still searches for secrets if None
  • Missing config.yaml always produces detectable signal (exception or sentinel) so CLI can print "using defaults" message
  • All existing tests pass unchanged (they pass explicit fixture paths)
  • New tests cover: XDG-only, CWD-only, both present (XDG wins), neither present, auto-creation of dir, explicit path bypasses search

Blocked by

None - can start immediately

## Parent #21 — Feature: XDG config path resolution with CWD fallback ## What to build Build the path resolution engine and wire it into the config loader. A new internal function resolves a filename by checking `~/.config/librofm-downloader/` (XDG) first, then falling back to the current working directory. The XDG parent directory is auto-created on demand with `mkdir(parents=True, exist_ok=True)`. Returns the resolved `Path` if found, `None` if absent from both locations. Wire this resolver into `load_config()` so that passing `None` for either path triggers search. When `config.yaml` is missing everywhere: non-fatal — return a fully-defaulted `Config` instance and raise no exception. When `secrets.yaml` is missing everywhere: fatal — raise a domain error (`ConfigError` subclass) with a message listing every path searched in order. All raw `FileNotFoundError` / `OSError` from file I/O are caught internally and converted to domain errors — no OS exceptions leak to callers. ## Acceptance criteria - [ ] `_resolve_config_file(filename)` exists, searches XDG then CWD, returns `Path | None` - [ ] XDG directory `~/.config/librofm-downloader/` is auto-created when resolution runs - [ ] `load_config(None, None)` with only secrets present → returns Config with built-in defaults for format/output_dir/extras/covers - [ ] `load_config(None, None)` with neither file → raises domain error listing searched paths (not FileNotFoundError) - [ ] `load_config(explicit_path, None)` with explicit config path → skips search for config, still searches for secrets if None - [ ] Missing config.yaml always produces detectable signal (exception or sentinel) so CLI can print "using defaults" message - [ ] All existing tests pass unchanged (they pass explicit fixture paths) - [ ] New tests cover: XDG-only, CWD-only, both present (XDG wins), neither present, auto-creation of dir, explicit path bypasses search ## Blocked by None - can start immediately
AlexKucera commented 2026-06-04 10:01:36 +02:00 (Migrated from github.com)

Implemented in commit 3ba9f25. XDG→CWD path resolution, missing-config notice, OS→domain error wrapping. 9 new tests, 181 total pass. All 8 AC met.

Implemented in commit 3ba9f25. XDG→CWD path resolution, missing-config notice, OS→domain error wrapping. 9 new tests, 181 total pass. All 8 AC met.
Sign in to join this conversation.