Files
qwenpaw/tests/unit/cli/test_doctor_connectivity.py
agent-radar 1a3a4ccde1
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:01:50 +08:00

110 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import pytest
from qwenpaw.cli import doctor_connectivity
from qwenpaw.config.config import OneBotConfig, TelegramConfig
def test_probe_telegram_uses_custom_base_url(monkeypatch) -> None:
captured: dict[str, object] = {}
def _fake_get_ok(url: str, timeout: float) -> None:
captured["url"] = url
captured["timeout"] = timeout
monkeypatch.setattr(doctor_connectivity, "_http_get_ok", _fake_get_ok)
# pylint: disable-next=protected-access
result = doctor_connectivity._probe_telegram(
"default",
TelegramConfig(base_url=" https://tg-api.example.com/ "),
3.0,
)
assert not result
assert captured == {
"url": "https://tg-api.example.com",
"timeout": 3.0,
}
def _probe_onebot(cfg: OneBotConfig, monkeypatch) -> tuple[list[str], list]:
"""Run the OneBot probe with a stubbed TCP check.
Returns the emitted notes and the hosts that were probed.
"""
probed: list = []
def _fake_tcp_check(host: str, port: int, timeout: float) -> None:
# Returning None tells the probe that the port is reachable.
probed.append((host, port, timeout))
monkeypatch.setattr(doctor_connectivity, "_tcp_check", _fake_tcp_check)
# pylint: disable-next=protected-access
notes = doctor_connectivity._probe_onebot("default", cfg, 3.0)
return notes, probed
def test_probe_onebot_warns_when_exposed_without_token(monkeypatch) -> None:
notes, _ = _probe_onebot(
OneBotConfig(enabled=True, ws_host="0.0.0.0", access_token=""),
monkeypatch,
)
assert len(notes) == 1
assert "access_token is empty" in notes[0]
@pytest.mark.parametrize(
"ws_host, access_token",
[
("127.0.0.1", ""),
("0.0.0.0", "s3cret-token"),
],
)
def test_probe_onebot_stays_quiet_when_safe(
ws_host: str,
access_token: str,
monkeypatch,
) -> None:
notes, _ = _probe_onebot(
OneBotConfig(
enabled=True,
ws_host=ws_host,
access_token=access_token,
),
monkeypatch,
)
assert not notes
@pytest.mark.parametrize(
"ws_host, expected",
[
("0.0.0.0", "127.0.0.1"),
("", "127.0.0.1"),
# Winsock rejects a wildcard connect target, so :: must be
# probed via the loopback address of its own family.
("::", "::1"),
("[::1]", "::1"),
],
)
def test_probe_onebot_probe_target(
ws_host: str,
expected: str,
monkeypatch,
) -> None:
_, probed = _probe_onebot(
OneBotConfig(
enabled=True,
ws_host=ws_host,
access_token="s3cret-token",
),
monkeypatch,
)
assert probed == [(expected, 6199, 3.0)]