From e4966021e9b13cf84bf12b62f2acebba94396c1f Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman Date: Sun, 5 Apr 2026 07:33:40 +0000 Subject: [PATCH] fix(config): correct Settings.data_dir default from Path("data") to Path.home() / ".cleveragents" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Settings class had data_dir defaulting to Path("data") — a relative path — but the specification requires the default data directory to be ~/.cleveragents. This inconsistency caused any code reading Settings().data_dir without setting CLEVERAGENTS_DATA_DIR to use a relative 'data/' directory instead of the spec-required ~/.cleveragents, affecting log storage, database location, cache, backups, and all persistent state. Changes: - Fix data_dir default_factory from Path("data") to Path.home() / ".cleveragents" - Add Behave scenario: 'data_dir default is the spec-required home directory path' - Add Behave scenario: 'data_dir env var override takes precedence over default' - Add step definition: 'the data directory should equal the home cleveragents path' Settings.data_dir is now consistent with ConfigService core.data-dir default (~/.cleveragents). The CLEVERAGENTS_DATA_DIR env var override continues to work. ISSUES CLOSED: #2851 --- features/settings_configuration.feature | 11 +++++++++++ features/steps/settings_steps.py | 9 +++++++++ src/cleveragents/config/settings.py | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/features/settings_configuration.feature b/features/settings_configuration.feature index 09ecf2c8d..0b9e64206 100644 --- a/features/settings_configuration.feature +++ b/features/settings_configuration.feature @@ -2,6 +2,17 @@ Feature: Settings runtime helpers Verify environment alias, storage paths, database URLs, production flags, provider configuration lookups, and LangSmith config guards behave predictably. + Scenario: data_dir default is the spec-required home directory path + Given no environment variables are set + When I load the settings with defaults + Then the data directory should equal the home cleveragents path + + Scenario: data_dir env var override takes precedence over default + Given no environment variables are set + And the environment variable "CLEVERAGENTS_DATA_DIR" is set to "/tmp/custom-data" + When I load the settings with defaults + Then the data directory should be "/tmp/custom-data" + Scenario: Environment alias setter syncs env field Given no environment variables are set When I load the settings with defaults diff --git a/features/steps/settings_steps.py b/features/steps/settings_steps.py index 27ec67d11..8ab36d6df 100644 --- a/features/steps/settings_steps.py +++ b/features/steps/settings_steps.py @@ -104,6 +104,15 @@ def step_check_log_dir_contains(context, substring): assert substring in str(context.settings.log_dir) +@then("the data directory should equal the home cleveragents path") +def step_check_data_dir_home_cleveragents(context): + """Check that data_dir defaults to Path.home() / '.cleveragents'.""" + expected = Path.home() / ".cleveragents" + assert context.settings.data_dir == expected, ( + f"Expected data_dir={expected!r}, got {context.settings.data_dir!r}" + ) + + @then('the data directory should be "{expected}"') def step_check_data_dir(context, expected): """Check the data directory.""" diff --git a/src/cleveragents/config/settings.py b/src/cleveragents/config/settings.py index 80a8e69db..f9d4e56e7 100644 --- a/src/cleveragents/config/settings.py +++ b/src/cleveragents/config/settings.py @@ -130,7 +130,7 @@ class Settings(BaseSettings): validation_alias=AliasChoices("CLEVERAGENTS_LOG_DIR"), ) data_dir: Path = Field( - default_factory=lambda: Path("data"), + default_factory=lambda: Path.home() / ".cleveragents", validation_alias=AliasChoices("CLEVERAGENTS_DATA_DIR"), ) storage_base_path: Path = Field( -- 2.52.0