Files
qwenpaw/tests/unit/config/test_channel_shape_consistency.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

55 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
"""Consistency guards for built-in channel shape declarations.
A built-in channel is declared in more than one place, and those places
must stay in sync. ``ChannelConfig`` is the source of truth for the
config shape (this is what doctor already walks), while the registry
and the API layer keep their own lists.
These tests fail loudly when a newly added channel is missing from one
of those lists. That drift is what made ``GET`` on a single channel
answer with an unrelated channel's fields for ``onebot``, and what let
``PUT`` write an unvalidated dict to disk.
"""
# pylint: disable=protected-access
from __future__ import annotations
from typing import get_args
from qwenpaw.app.channels.registry import _BUILTIN_SPECS
from qwenpaw.app.routers.config import _channel_config_class
from qwenpaw.config.config import ChannelConfig, ChannelConfigUnion
def _declared_config_classes() -> set[type]:
"""Config models declared as ``ChannelConfig`` fields."""
return {field.annotation for field in ChannelConfig.model_fields.values()}
def test_builtin_specs_match_channel_config_fields() -> None:
"""Every built-in channel implementation has a config field."""
assert set(_BUILTIN_SPECS) == set(ChannelConfig.model_fields)
def test_channel_config_union_covers_every_builtin_channel() -> None:
"""``ChannelConfigUnion`` must list every built-in config model.
The single-channel endpoints use it as ``response_model``. When a
model is missing, FastAPI cannot match the returned instance and
falls back to coercing it into another member, silently dropping
the channel's own fields.
"""
assert set(get_args(ChannelConfigUnion)) == _declared_config_classes()
def test_channel_config_class_resolves_every_builtin_channel() -> None:
"""PUT validation must find a model for every built-in channel."""
for name, field in ChannelConfig.model_fields.items():
assert _channel_config_class(name) is field.annotation
def test_channel_config_class_returns_none_for_plugin_channel() -> None:
"""Plugin channels are not declared, so they stay untyped dicts."""
assert _channel_config_class("some_plugin_channel") is None