From 2b6b90c2a1ea1c6722bd2591b54e549d51340a84 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Tue, 10 Nov 2026 00:34:35 -0300 Subject: [PATCH] fix: fall back to the bundled config file when DEEPWIKI_CONFIG_DIR lacks it With DEEPWIKI_CONFIG_DIR set, every JSON config was read only from that directory, so a directory holding just a custom generator.json left embedder.json, repo.json and lang.json empty: no embedder, no file filters. Read each file from DEEPWIKI_CONFIG_DIR when it is there and from api/config otherwise. Signed-off-by: Lucas Barros --- api/config.py | 18 +++++++++++++----- tests/test_config.py | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/api/config.py b/api/config.py index ae293f4f8..225a1369c 100644 --- a/api/config.py +++ b/api/config.py @@ -128,15 +128,23 @@ def replacer(match: re.Match[str]) -> str: return config +DEFAULT_CONFIG_DIR = Path(__file__).parent / "config" + + # Load JSON configuration file def load_json_config(filename): try: - # If environment variable is set, use the directory specified by it + config_path = DEFAULT_CONFIG_DIR / filename + # A file in DEEPWIKI_CONFIG_DIR overrides the bundled one. Files that are + # not there (e.g. only generator.json is customized) keep the defaults. if CONFIG_DIR: - config_path = Path(CONFIG_DIR) / filename - else: - # Otherwise use default directory - config_path = Path(__file__).parent / "config" / filename + custom_path = Path(CONFIG_DIR) / filename + if custom_path.exists(): + config_path = custom_path + else: + logger.info( + f"{filename} not found in DEEPWIKI_CONFIG_DIR ({CONFIG_DIR}), using the bundled default" + ) logger.info(f"Loading configuration from {config_path}") diff --git a/tests/test_config.py b/tests/test_config.py index c4f013238..b08ab1667 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -81,3 +81,30 @@ def test_iterate_files_included_dirs_ignores_directories_above_root(tmp_path): files = set(iterate_files(root_dir=str(root), included_dirs=["folder"])) assert files == {"folder/code.py"} + + +def test_load_json_config_prefers_file_in_config_dir(monkeypatch, tmp_path): + import json + + import api.config as config + + (tmp_path / "generator.json").write_text( + json.dumps({"default_provider": "ollama", "providers": {}}) + ) + monkeypatch.setattr(config, "CONFIG_DIR", str(tmp_path)) + + assert config.load_json_config("generator.json") == { + "default_provider": "ollama", + "providers": {}, + } + + +def test_load_json_config_falls_back_to_bundled_file(monkeypatch, tmp_path): + import api.config as config + + (tmp_path / "generator.json").write_text("{}") + monkeypatch.setattr(config, "CONFIG_DIR", str(tmp_path)) + + embedder = config.load_json_config("embedder.json") + assert "embedder" in embedder + assert embedder["embedder"]["client_class"] == "OpenAIClient"