9c53995f23
- Tier S → google/gemini-3-flash-preview ($0.50/$3.00) - Tier A/B → deepseek/deepseek-v4-flash ($0.14/$0.28) - Tier C → qwen/qwen3-235b-a22b-2507 ($0.071/$0.10) — Phase 2 target - Tier D → openai/gpt-oss-20b ($0.03/$0.14) Aggiornato cost_tracker con prezzi reali per tier. Defaults config.py ora rispecchiano .env corrente per evitare divergenze dead-code. Tier S/A/B/D restano cablati ma non ancora invocati nel loop Phase 2 (solo Hypothesis tier C attivo). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
82 lines
3.5 KiB
Python
82 lines
3.5 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("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 == "google/gemini-3-flash-preview"
|
|
assert s.llm_model_tier_a == "deepseek/deepseek-v4-flash"
|
|
assert s.llm_model_tier_b == "deepseek/deepseek-v4-flash"
|
|
assert s.llm_model_tier_c == "qwen/qwen3-235b-a22b-2507"
|
|
assert s.llm_model_tier_d == "openai/gpt-oss-20b"
|
|
assert s.openrouter_base_url == "https://openrouter.ai/api/v1"
|