11from __future__ import annotations
22
33import asyncio
4+ import os
5+ import tempfile
46import unittest
7+ from pathlib import Path
58from types import SimpleNamespace
69from unittest .mock import AsyncMock , patch
710
811from app .config import ConfigError
9- from app .production_preflight import _check_gemini , _check_telegram , _check_x
12+ from app .production_preflight import (
13+ _check_gemini ,
14+ _check_telegram ,
15+ _check_x ,
16+ _publish_github_provider_state ,
17+ )
1018from app .telegram import TelegramPermanentError
1119from app .x_client import XCollectionError
1220
@@ -27,6 +35,20 @@ def settings(**overrides):
2735
2836
2937class ProductionPreflightTests (unittest .TestCase ):
38+ def test_github_env_records_offline_x_without_error_detail (self ):
39+ with tempfile .TemporaryDirectory () as temp :
40+ path = Path (temp ) / "github-env"
41+ with patch .dict (os .environ , {"GITHUB_ENV" : str (path )}):
42+ _publish_github_provider_state ({"x" : "offline (XCollectionError)" })
43+ self .assertEqual (path .read_text (encoding = "utf-8" ), "X_PROVIDER_PREFLIGHT=offline\n " )
44+
45+ def test_github_env_records_online_x (self ):
46+ with tempfile .TemporaryDirectory () as temp :
47+ path = Path (temp ) / "github-env"
48+ with patch .dict (os .environ , {"GITHUB_ENV" : str (path )}):
49+ _publish_github_provider_state ({"x" : "ok" })
50+ self .assertEqual (path .read_text (encoding = "utf-8" ), "X_PROVIDER_PREFLIGHT=online\n " )
51+
3052 @patch ("app.production_preflight.TelegramBot" )
3153 def test_telegram_is_the_hard_dependency (self , bot_class ):
3254 bot_class .return_value .api .side_effect = TelegramPermanentError ("bad token" )
0 commit comments