- 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
92 lines
3.1 KiB
Python
92 lines
3.1 KiB
Python
"""Shared test fixtures and utilities."""
|
|
|
|
from steward.config import (
|
|
AnalysisConfig,
|
|
MemoryConfig,
|
|
OpenAIConfig,
|
|
Settings,
|
|
TelegramConfig,
|
|
ToolsConfig,
|
|
)
|
|
|
|
|
|
def make_settings(**kwargs) -> Settings:
|
|
"""Create a Settings instance from old-style kwargs.
|
|
|
|
Maps legacy parameter names to the new nested structure:
|
|
- telegram_bot_token -> telegram.bot_token
|
|
- telegram_allowed_user_ids -> telegram.allowed_user_ids
|
|
- telegram_group_ids -> telegram.group_ids
|
|
- openai_api_key -> openai.api_key
|
|
- openai_base_url -> openai.base_url
|
|
- openai_model -> openai.model
|
|
- openai_system_prompt -> openai.system_prompt
|
|
- analysis_target_url -> analysis.target_url
|
|
- analysis_target_api_key -> analysis.target_api_key
|
|
- analysis_cron_hour -> analysis.cron_hour
|
|
- analysis_cron_minute -> analysis.cron_minute
|
|
- thread_memory_path -> memory.thread_memory_path
|
|
- mcp_server_url -> tools.mcp_server_url
|
|
- mcp_server_api_key -> tools.mcp_server_api_key
|
|
|
|
Args:
|
|
**kwargs: Legacy-style configuration parameters
|
|
|
|
Returns:
|
|
Settings: A fully constructed Settings instance
|
|
"""
|
|
# Extract telegram config
|
|
telegram_config = TelegramConfig(
|
|
bot_token=kwargs.pop("telegram_bot_token", ""),
|
|
allowed_user_ids=kwargs.pop("telegram_allowed_user_ids", []),
|
|
group_ids=kwargs.pop("telegram_group_ids", []),
|
|
)
|
|
|
|
# Extract OpenAI config
|
|
openai_config = OpenAIConfig(
|
|
api_key=kwargs.pop("openai_api_key", ""),
|
|
base_url=kwargs.pop("openai_base_url", "https://api.openai.com/v1"),
|
|
model=kwargs.pop("openai_model", "gpt-4o"),
|
|
system_prompt=kwargs.pop(
|
|
"openai_system_prompt",
|
|
(
|
|
"You are Steward, a persistent, trustworthy AI-assisted personal operations platform. "
|
|
"You reduce cognitive load by observing, remembering, planning, and proposing actions. "
|
|
"You are conservative, transparent, and policy-aware. "
|
|
"Always explain your reasoning."
|
|
),
|
|
),
|
|
)
|
|
|
|
# Extract analysis config
|
|
analysis_config = AnalysisConfig(
|
|
target_url=kwargs.pop("analysis_target_url", ""),
|
|
target_api_key=kwargs.pop("analysis_target_api_key", ""),
|
|
cron_hour=kwargs.pop("analysis_cron_hour", 8),
|
|
cron_minute=kwargs.pop("analysis_cron_minute", 0),
|
|
)
|
|
|
|
# Extract memory config
|
|
memory_config = MemoryConfig(
|
|
thread_memory_path=kwargs.pop("thread_memory_path", "thread_memory.json"),
|
|
)
|
|
|
|
# Extract tools config
|
|
tools_config = ToolsConfig(
|
|
mcp_server_url=kwargs.pop("mcp_server_url", ""),
|
|
mcp_server_api_key=kwargs.pop("mcp_server_api_key", ""),
|
|
)
|
|
|
|
# Any remaining kwargs should be rejected
|
|
if kwargs:
|
|
raise TypeError(f"Unexpected keyword arguments: {', '.join(kwargs.keys())}")
|
|
|
|
# Create and return Settings instance
|
|
return Settings(
|
|
telegram=telegram_config,
|
|
openai=openai_config,
|
|
analysis=analysis_config,
|
|
memory=memory_config,
|
|
tools=tools_config,
|
|
)
|