"""Tests for multi_swarm.config.Settings. Note on .env isolation: The happy-path test relies on monkeypatch.setenv to provide values. The "requires tokens" test forces _env_file=None when constructing Settings, so that a developer's local .env (if present and populated) cannot mask the absence of required env vars. This keeps the test deterministic both in CI (no .env) and in local dev (.env may exist). """ import pytest from multi_swarm.config import Settings def test_settings_loads_from_env(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("CERBERO_BASE_URL", "http://test:9000") monkeypatch.setenv("CERBERO_TESTNET_TOKEN", "tok-test") monkeypatch.setenv("CERBERO_MAINNET_TOKEN", "tok-main") monkeypatch.setenv("CERBERO_BOT_TAG", "swarm-poc-phase1") monkeypatch.setenv("OPENROUTER_API_KEY", "or-key") monkeypatch.setenv("RUN_NAME", "test-run") s = Settings() # type: ignore[call-arg] assert s.cerbero_base_url == "http://test:9000" assert s.cerbero_testnet_token.get_secret_value() == "tok-test" assert s.run_name == "test-run" assert s.data_dir.name == "data" assert s.db_path.name == "runs.db" def test_settings_requires_tokens(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.delenv("CERBERO_TESTNET_TOKEN", raising=False) monkeypatch.delenv("OPENROUTER_API_KEY", raising=False) from pydantic import ValidationError with pytest.raises(ValidationError): # Disable .env loading to keep the test deterministic regardless of # whether a developer's local .env exists and is populated. Settings(_env_file=None) # type: ignore[call-arg] def test_settings_loads_llm_model_overrides(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("CERBERO_TESTNET_TOKEN", "tok-test") monkeypatch.setenv("OPENROUTER_API_KEY", "or-key") monkeypatch.setenv("LLM_MODEL_TIER_S", "claude-mega-x") monkeypatch.setenv("LLM_MODEL_TIER_A", "claude-premium-y") monkeypatch.setenv("LLM_MODEL_TIER_B", "claude-opus-4-7") monkeypatch.setenv("LLM_MODEL_TIER_C", "deepseek/deepseek-chat") monkeypatch.setenv("LLM_MODEL_TIER_D", "mistralai/mistral-7b") monkeypatch.setenv("OPENROUTER_BASE_URL", "https://example.com/api/v1") s = Settings(_env_file=None) # type: ignore[call-arg] assert s.llm_model_tier_s == "claude-mega-x" assert s.llm_model_tier_a == "claude-premium-y" assert s.llm_model_tier_b == "claude-opus-4-7" assert s.llm_model_tier_c == "deepseek/deepseek-chat" assert s.llm_model_tier_d == "mistralai/mistral-7b" assert s.openrouter_base_url == "https://example.com/api/v1" def test_settings_llm_model_defaults(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("CERBERO_TESTNET_TOKEN", "tok-test") monkeypatch.setenv("OPENROUTER_API_KEY", "or-key") monkeypatch.delenv("LLM_MODEL_TIER_S", raising=False) monkeypatch.delenv("LLM_MODEL_TIER_A", raising=False) monkeypatch.delenv("LLM_MODEL_TIER_B", raising=False) monkeypatch.delenv("LLM_MODEL_TIER_C", raising=False) monkeypatch.delenv("LLM_MODEL_TIER_D", raising=False) monkeypatch.delenv("OPENROUTER_BASE_URL", raising=False) s = Settings(_env_file=None) # type: ignore[call-arg] assert s.llm_model_tier_s == "anthropic/claude-opus-4-7" assert s.llm_model_tier_a == "anthropic/claude-sonnet-4-6" assert s.llm_model_tier_b == "anthropic/claude-sonnet-4-6" assert s.llm_model_tier_c == "qwen/qwen-2.5-72b-instruct" assert s.llm_model_tier_d == "meta-llama/llama-3.3-70b-instruct" assert s.openrouter_base_url == "https://openrouter.ai/api/v1"