import pytest from pydantic import ValidationError from src.core.config import Settings def test_fastgpt_backend_accepts_legacy_environment_names(): settings = Settings( _env_file=None, ZNJJ_ENVIRONMENT="test", AGENT_BACKEND="fastgpt", ANALYSIS_AUTH_TOKEN="test-fastgpt-key", ANALYSIS_SERVICE_URL="http://fastgpt.test", APP_ID="test-app", ) assert settings.environment == "test" assert settings.agent_backend == "fastgpt" assert settings.has_fastgpt_config assert settings.fastgpt_api_key.get_secret_value() == "test-fastgpt-key" def test_fastgpt_backend_rejects_incomplete_configuration(): with pytest.raises(ValidationError, match="FastGPT backend requires"): Settings( _env_file=None, environment="test", agent_backend="fastgpt", fastgpt_api_key="test-key", ) def test_langgraph_backend_requires_only_minimal_llm_configuration(): settings = Settings( _env_file=None, environment="test", agent_backend="langgraph", langgraph_checkpointer="memory", llm_api_key="test-llm-key", llm_model="test-model", ) assert settings.agent_backend == "langgraph" assert settings.langgraph_checkpointer == "memory" assert not settings.has_fastgpt_config def test_langgraph_backend_rejects_missing_llm_configuration(): with pytest.raises(ValidationError, match="LLM_API_KEY, LLM_MODEL"): Settings( _env_file=None, environment="test", agent_backend="langgraph", ) def test_production_cannot_use_memory_checkpointer(): with pytest.raises(ValidationError, match="cannot use the memory checkpointer"): Settings( _env_file=None, environment="production", agent_backend="langgraph", langgraph_checkpointer="memory", llm_api_key="test-llm-key", llm_model="test-model", ) def test_secret_values_are_masked_in_settings_repr(): settings = Settings( _env_file=None, environment="test", agent_backend="langgraph", llm_api_key="never-print-this-key", llm_model="test-model", ) assert "never-print-this-key" not in repr(settings)