Skip to content

Config file loader: ~/.config/fafycat/config.toml #28

@davidchris

Description

@davidchris

Parent

#26

What to build

A new deep module that loads ~/.config/fafycat/config.toml and feeds path overrides into AppConfig. Affects every command (serve, import, init, and the future query commands). Independent of the CLI surface work — can ship in parallel.

  • Public interface: load_config_file(path: Path | None) -> dict[str, str].
  • Format: TOML via stdlib tomllib. No new dependency.
  • Schema: a [paths] table with optional keys data_dir, db_url, model_dir, export_dir. All keys are optional; missing keys fall through to the next precedence layer.
  • Resolution precedence (highest wins): --data-dir CLI flag > env var (FAFYCAT_DATA_DIR, FAFYCAT_DB_URL, etc.) > config file > built-in default (platformdirs).
  • FAFYCAT_CONFIG env var overrides the config-file location.
  • Missing config file is silent — fall through.
  • Unknown keys produce a warning to stderr; do not crash.
  • Malformed TOML or invalid path syntax fails loudly with a clear error.
  • No auto-creation of the file on first run.

AppConfig is modified so its _default_* factories consult the loader between env vars and the platformdirs default.

Acceptance criteria

  • load_config_file() returns an empty dict when the config file does not exist.
  • load_config_file() returns the declared [paths] keys as a flat dict when the file is present and valid.
  • Unknown keys in [paths] produce a stderr warning naming the key; the loader still returns the recognised keys.
  • Malformed TOML raises a clear exception that is caught at the CLI boundary and surfaced as {"error": "..."} exit 1.
  • Setting FAFYCAT_CONFIG=/some/path/config.toml causes the loader to read that path instead of the default.
  • AppConfig resolves paths in the documented order: CLI flag > env > config file > default.
  • An integration test sets each precedence layer and confirms the expected database URL ends up on AppConfig.database.url.
  • Existing fafycat serve, fafycat import, fafycat init continue to work unchanged when the config file is absent.
  • Tests are written before the implementation (red-green TDD).
  • Pure-function unit tests cover: missing file, valid file, partial schema, unknown keys (warning surfaced via capsys/caplog), malformed TOML.
  • No auto-creation: an integration test confirms the config file is not created when absent.

Blocked by

None - can start immediately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions