From 5a7d90ce9fbad2db188eb0c81e43f2bf6da3ab2b Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Wed, 29 Oct 2025 11:46:53 +0200 Subject: [PATCH] Change default location for config from XDG statndatd to use the platform-specific folder we use for the db as well --- docs/configuration.md | 5 +++- src/haiku/rag/config/loader.py | 8 ++++--- tests/test_config_loader.py | 43 +++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index ebc5c82a..1a8acc31 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -30,7 +30,10 @@ This creates a `haiku.rag.yaml` file in your current directory with all availabl 1. Path specified via `--config` flag: `haiku-rag --config /path/to/config.yaml ` 2. `./haiku.rag.yaml` (current directory) -3. `~/.config/haiku.rag/config.yaml` (user config directory) +3. Platform-specific user directory: + - **Linux**: `~/.local/share/haiku.rag/config.yaml` + - **macOS**: `~/Library/Application Support/haiku.rag/config.yaml` + - **Windows**: `C:/Users//AppData/Roaming/haiku.rag/config.yaml` ## Minimal Configuration diff --git a/src/haiku/rag/config/loader.py b/src/haiku/rag/config/loader.py index c200d2f7..0438e544 100644 --- a/src/haiku/rag/config/loader.py +++ b/src/haiku/rag/config/loader.py @@ -10,7 +10,7 @@ def find_config_file(cli_path: Path | None = None) -> Path | None: Search order: 1. CLI-provided path (via HAIKU_RAG_CONFIG_PATH env var or parameter) 2. ./haiku.rag.yaml (current directory) - 3. ~/.config/haiku.rag/config.yaml (user config) + 3. Platform-specific user config directory Returns None if no config file is found. """ @@ -29,8 +29,10 @@ def find_config_file(cli_path: Path | None = None) -> Path | None: if cwd_config.exists(): return cwd_config - user_config_dir = Path.home() / ".config" / "haiku.rag" - user_config = user_config_dir / "config.yaml" + # Use same directory as data storage for config + from haiku.rag.utils import get_default_data_dir + + user_config = get_default_data_dir() / "config.yaml" if user_config.exists(): return user_config diff --git a/tests/test_config_loader.py b/tests/test_config_loader.py index 991d1628..1063dab8 100644 --- a/tests/test_config_loader.py +++ b/tests/test_config_loader.py @@ -1,5 +1,4 @@ import os -from pathlib import Path import pytest @@ -42,13 +41,17 @@ def test_find_config_file_cwd(tmp_path, monkeypatch): def test_find_config_file_user_config(tmp_path, monkeypatch): """Test finding config in user config directory.""" monkeypatch.chdir(tmp_path) - user_config_dir = tmp_path / ".config" / "haiku.rag" - user_config_dir.mkdir(parents=True) - config_file = user_config_dir / "config.yaml" - config_file.write_text("environment: production") - # Mock home directory - monkeypatch.setattr(Path, "home", lambda: tmp_path) + # Mock get_default_data_dir to return tmp_path + def mock_get_default_data_dir(): + return tmp_path + + monkeypatch.setattr( + "haiku.rag.utils.get_default_data_dir", mock_get_default_data_dir + ) + + config_file = tmp_path / "config.yaml" + config_file.write_text("environment: production") found = find_config_file() assert found == config_file @@ -77,7 +80,14 @@ def test_find_config_file_env_var(tmp_path, monkeypatch): def test_find_config_file_not_found(tmp_path, monkeypatch): """Test returning None when no config found.""" monkeypatch.chdir(tmp_path) - monkeypatch.setattr(Path, "home", lambda: tmp_path) + + # Mock get_default_data_dir to return tmp_path + def mock_get_default_data_dir(): + return tmp_path + + monkeypatch.setattr( + "haiku.rag.utils.get_default_data_dir", mock_get_default_data_dir + ) found = find_config_file() assert found is None @@ -152,23 +162,28 @@ def test_load_config_from_env_empty(): def test_config_precedence_cwd_over_user(tmp_path, monkeypatch): """Test that cwd config takes precedence over user config.""" monkeypatch.chdir(tmp_path) - monkeypatch.setattr(Path, "home", lambda: tmp_path) + + # Mock get_default_data_dir to return tmp_path + def mock_get_default_data_dir(): + return tmp_path + + monkeypatch.setattr( + "haiku.rag.utils.get_default_data_dir", mock_get_default_data_dir + ) # Create both configs cwd_config = tmp_path / "haiku.rag.yaml" cwd_config.write_text("environment: from-cwd") - user_config_dir = tmp_path / ".config" / "haiku.rag" - user_config_dir.mkdir(parents=True) - user_config = user_config_dir / "config.yaml" + user_config = tmp_path / "config.yaml" user_config.write_text("environment: from-user") found = find_config_file() assert found == cwd_config assert found is not None - config = load_yaml_config(found) - assert config["environment"] == "from-cwd" + config_data = load_yaml_config(found) + assert config_data["environment"] == "from-cwd" def test_config_precedence_env_var_over_cwd(tmp_path, monkeypatch):