fix(config): validate chat_id and bot_token
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from takopi.exec_bridge import (
|
||||
extract_session_id,
|
||||
prepare_telegram,
|
||||
@@ -8,6 +10,36 @@ from takopi.exec_bridge import (
|
||||
)
|
||||
|
||||
|
||||
def _patch_config(monkeypatch, config):
|
||||
from pathlib import Path
|
||||
|
||||
from takopi import exec_bridge
|
||||
|
||||
monkeypatch.setattr(
|
||||
exec_bridge,
|
||||
"load_telegram_config",
|
||||
lambda: (config, Path("takopi.toml")),
|
||||
)
|
||||
|
||||
|
||||
def test_parse_bridge_config_rejects_empty_token(monkeypatch) -> None:
|
||||
from takopi import exec_bridge
|
||||
|
||||
_patch_config(monkeypatch, {"bot_token": " ", "chat_id": 123})
|
||||
|
||||
with pytest.raises(exec_bridge.ConfigError, match="bot_token"):
|
||||
exec_bridge._parse_bridge_config(final_notify=True, profile=None)
|
||||
|
||||
|
||||
def test_parse_bridge_config_rejects_string_chat_id(monkeypatch) -> None:
|
||||
from takopi import exec_bridge
|
||||
|
||||
_patch_config(monkeypatch, {"bot_token": "token", "chat_id": "123"})
|
||||
|
||||
with pytest.raises(exec_bridge.ConfigError, match="chat_id"):
|
||||
exec_bridge._parse_bridge_config(final_notify=True, profile=None)
|
||||
|
||||
|
||||
def test_extract_session_id_finds_uuid_v7() -> None:
|
||||
uuid = "019b66fc-64c2-7a71-81cd-081c504cfeb2"
|
||||
text = f"resume: `{uuid}`"
|
||||
|
||||
Reference in New Issue
Block a user