from pathlib import Path import pytest from pydantic import ValidationError from app.config import AccessSettings, Settings from app.texts import load_texts def test_admin_ids_parsed_from_comma_separated_env(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("ADMIN_IDS", "1, 2,3,") assert AccessSettings(_env_file=None).admin_ids == frozenset({1, 2, 3}) # type: ignore[call-arg] def test_admin_ids_default_empty(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.delenv("ADMIN_IDS", raising=False) assert AccessSettings(_env_file=None).admin_ids == frozenset() # type: ignore[call-arg] def test_texts_with_missing_key_fail_fast(tmp_path: Path) -> None: (tmp_path / "texts.yaml").write_text("menu: {commit: x}\n", encoding="utf-8") with pytest.raises(ValidationError): load_texts(tmp_path) def test_ci_runner_env_does_not_break_settings(monkeypatch: pytest.MonkeyPatch) -> None: # Gitea/GitHub runners export CI=true; it must not collide with a settings field monkeypatch.setenv("CI", "true") monkeypatch.setenv("TELEGRAM_BOT_TOKEN", "42:x") assert Settings().uploads_ci.provider == "none"