Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

102 lines
2.8 KiB
Python

from __future__ import annotations
import sys
from collections.abc import Callable
from types import SimpleNamespace
from typing import Any
from integrations.discord.verifier import verify_discord
class _FakeIntents:
def __init__(self) -> None:
self.guilds = False
@classmethod
def none(cls) -> _FakeIntents:
return cls()
def _install_fake_discord(
monkeypatch: Any,
*,
run_error_factory: Callable[[type[Exception]], Exception] | None = None,
) -> list[str]:
tokens: list[str] = []
class LoginFailure(Exception):
pass
class Client:
def __init__(self, *, intents: _FakeIntents) -> None:
assert intents.guilds is True
def run(self, token: str) -> None:
tokens.append(token)
if run_error_factory is not None:
raise run_error_factory(LoginFailure)
fake_discord = SimpleNamespace(
Intents=_FakeIntents,
Client=Client,
LoginFailure=LoginFailure,
)
monkeypatch.setitem(sys.modules, "discord", fake_discord)
return tokens
def test_verify_discord_missing_bot_token(monkeypatch: Any) -> None:
_install_fake_discord(monkeypatch)
result = verify_discord("local env", {})
assert result["status"] == "missing"
assert "bot_token" in result["detail"]
def test_verify_discord_reports_login_failure(monkeypatch: Any) -> None:
_install_fake_discord(
monkeypatch,
run_error_factory=lambda login_failure_cls: login_failure_cls("bad token"),
)
result = verify_discord("local env", {"bot_token": "bad-token"})
assert result["status"] == "failed"
assert "Discord login failed" in result["detail"]
def test_verify_discord_reports_api_failure(monkeypatch: Any) -> None:
_install_fake_discord(
monkeypatch,
run_error_factory=lambda _login_failure_cls: RuntimeError("gateway unavailable"),
)
result = verify_discord("local env", {"bot_token": "token"})
assert result["status"] == "failed"
assert "gateway unavailable" in result["detail"]
def test_verify_discord_accepts_running_event_loop_success(monkeypatch: Any) -> None:
_install_fake_discord(
monkeypatch,
run_error_factory=lambda _login_failure_cls: RuntimeError(
"run() cannot be called from a running event loop"
),
)
result = verify_discord("local env", {"bot_token": "token"})
assert result["status"] == "passed"
assert "Discord bot token accepted" in result["detail"]
def test_verify_discord_accepts_token_when_client_run_succeeds(monkeypatch: Any) -> None:
tokens = _install_fake_discord(monkeypatch)
result = verify_discord("local env", {"bot_token": " token "})
assert tokens == ["token"]
assert result["status"] == "passed"