- Add tests/conftest.py with make_settings() helper that maps legacy config parameter names to new nested OmegaConf structure - Update all test files to use the conftest fixture - All 73 tests now pass with new config system - Maintains backward compatibility via Settings class properties Also add AGENTS.md with comprehensive AI agent guidelines: - Project overview and key technologies - Directory structure reference - Development workflow and common tasks - Testing strategy and patterns - CI/CD pipeline overview - Common pitfalls and best practices - Debugging guide for agents working on the project
5.1 KiB
Test Settings Migration Notes
Overview
Updated all test files to work with the new OmegaConf-based configuration system while maintaining backward compatibility through a helper function.
What Changed
1. Created tests/conftest.py (new file)
- Implements
make_settings(**kwargs)helper function - Maps legacy parameter names to the new nested structure
- Used as a shared utility across all test files
2. Updated Test Files
Updated the following test files to use the new helper:
tests/test_bot.pytests/test_llm_client.pytests/test_proposals.pytests/test_thread_memory.pytests/test_tools.py
Each file now:
- Imports
make_settingsfromtests.conftest - Keeps local
_make_settings()wrapper for compatibility - Calls the shared
make_settings()function internally
Parameter Mapping
The make_settings() function handles the following legacy-to-new mappings:
Telegram Config
telegram_bot_token→telegram.bot_tokentelegram_allowed_user_ids→telegram.allowed_user_idstelegram_group_ids→telegram.group_ids
OpenAI Config
openai_api_key→openai.api_keyopenai_base_url→openai.base_url(default:"https://api.openai.com/v1")openai_model→openai.model(default:"gpt-4o")openai_system_prompt→openai.system_prompt(uses default if not provided)
Analysis Config
analysis_target_url→analysis.target_urlanalysis_target_api_key→analysis.target_api_keyanalysis_cron_hour→analysis.cron_hour(default:8)analysis_cron_minute→analysis.cron_minute(default:0)
Memory Config
thread_memory_path→memory.thread_memory_path(default:"thread_memory.json")
Tools Config
mcp_server_url→tools.mcp_server_urlmcp_server_api_key→tools.mcp_server_api_key
Usage Examples
Before (would fail with new Settings class)
settings = Settings(
telegram_bot_token="token",
openai_api_key="key",
telegram_allowed_user_ids=[1, 2, 3]
)
After (with new helper)
from tests.conftest import make_settings
settings = make_settings(
telegram_bot_token="token",
openai_api_key="key",
telegram_allowed_user_ids=[1, 2, 3]
)
# Now settings.telegram.bot_token == "token"
# And settings.telegram.allowed_user_ids == [1, 2, 3]
# And backward-compat properties still work:
# settings.telegram_bot_token == "token"
# settings.telegram_allowed_user_ids == [1, 2, 3]
How Test Files Use It
Each test file has a local _make_settings() wrapper that:
- Defines default values specific to that test module
- Merges any provided kwargs
- Delegates to the shared
make_settings()function
Example from test_bot.py:
def _make_settings(**kwargs) -> Settings:
"""Wrapper for test compatibility."""
defaults = dict(
telegram_bot_token="test-token",
openai_api_key="test-key",
)
defaults.update(kwargs)
return make_settings(**defaults)
This allows tests to override defaults while reusing the mapping logic:
# Uses defaults
settings = _make_settings()
# Override specific values
settings = _make_settings(telegram_allowed_user_ids=[1, 2, 3])
Error Handling
The make_settings() function will raise a TypeError if any unexpected keyword arguments are passed:
make_settings(invalid_param="value")
# Raises: TypeError: Unexpected keyword arguments: invalid_param
This helps catch typos and unexpected parameters early in tests.
Backward Compatibility
The Settings class retains backward-compatible properties:
settings.telegram_bot_token→ returnssettings.telegram.bot_tokensettings.openai_api_key→ returnssettings.openai.api_key- etc.
This means existing code that reads from Settings using the old property names continues to work.
Files Modified
-
tests/conftest.py(NEW)- 91 lines
- Core mapping logic for legacy-to-new Settings structure
-
tests/test_bot.py- Added import:
from tests.conftest import make_settings - Updated
_make_settings()to call shared function
- Added import:
-
tests/test_llm_client.py- Added import:
from tests.conftest import make_settings - Updated
_make_settings()to call shared function
- Added import:
-
tests/test_proposals.py- Added import:
from tests.conftest import make_settings - Updated
_make_settings()to call shared function
- Added import:
-
tests/test_thread_memory.py- Added import:
from tests.conftest import make_settings - Updated
_make_settings()to call shared function
- Added import:
-
tests/test_tools.py- Added import:
from tests.conftest import make_settings - Updated
_make_llm_settings()to call shared function
- Added import:
Testing
To verify the changes work:
# Install dev dependencies
pip install -e ".[dev]"
# Run all tests
pytest tests/
# Run specific test file
pytest tests/test_bot.py -v
# Run specific test
pytest tests/test_bot.py::TestIsAllowed::test_allowlist_accepts_known_user -v
All tests should pass with these changes as the Settings class:
- Accepts the new nested structure from
make_settings() - Provides backward-compatible properties for old code