7482600146
LLM_MODEL_TIER_C, LLM_MODEL_TIER_B e OPENROUTER_BASE_URL ora override-abili via env. Default invariati (back-compat). LLMClient accetta i tre valori come kwargs opzionali; run_phase1 li propaga da Settings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
71 lines
2.9 KiB
Python
71 lines
2.9 KiB
Python
"""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("ANTHROPIC_API_KEY", "an-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_C", "deepseek/deepseek-chat")
|
|
monkeypatch.setenv("LLM_MODEL_TIER_B", "claude-opus-4-7")
|
|
monkeypatch.setenv("OPENROUTER_BASE_URL", "https://example.com/api/v1")
|
|
|
|
s = Settings(_env_file=None) # type: ignore[call-arg]
|
|
|
|
assert s.llm_model_tier_c == "deepseek/deepseek-chat"
|
|
assert s.llm_model_tier_b == "claude-opus-4-7"
|
|
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_C", raising=False)
|
|
monkeypatch.delenv("LLM_MODEL_TIER_B", raising=False)
|
|
monkeypatch.delenv("OPENROUTER_BASE_URL", raising=False)
|
|
|
|
s = Settings(_env_file=None) # type: ignore[call-arg]
|
|
|
|
assert s.llm_model_tier_c == "qwen/qwen-2.5-72b-instruct"
|
|
assert s.llm_model_tier_b == "claude-sonnet-4-6"
|
|
assert s.openrouter_base_url == "https://openrouter.ai/api/v1"
|