ForcePilot/backend/test/unit/channels/plugins/conftest.py
Kris 1022121bee test: add batch of unit tests for channels module
添加了channels限界上下文的大量单元测试文件,包括:
1. 各层级通用与专用的conftest夹具
2. 核心领域模型、事件、服务测试
3. 应用层流水线、扩展处理器测试
4. 适配器与插件层测试
5. 修复并补充了pool manager测试用例
2026-07-02 03:28:19 +08:00

67 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""channels plugins 层单元测试共享 fixture。
提供 ``fake_plugin_host`` 桩,模拟 ``PluginHost`` 协议
``yuxi.channels.contract.plugin.entry.PluginHost``)。插件适配器测试
通过此桩获取被驱动端口与注册扩展点,不依赖真实宿主实现。
桩使用 ``MagicMock()``:所有 ``getXxxPort()`` 返回对应 ``MagicMock`` 桩
(调用方可按需覆盖为带 ``spec`` 的端口桩),``registerXxx()`` /
``declareXxx()`` 返回 ``None````publishEvent`` 为 ``AsyncMock``
(可 ``await``)。单文件独有的 helper 应保留在对应测试文件内
(见 testing-guidelines.md
"""
from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock
import pytest
@pytest.fixture
def fake_plugin_host() -> MagicMock:
"""PluginHost 桩。
``MagicMock()`` 模拟 ``PluginHost``
- 所有 ``getXxxPort()`` 返回 ``MagicMock`` 桩(调用方可覆盖为带
``spec`` 的端口桩,如 ``host.getLoggerPort.return_value = fake_logger``
- ``registerAdapter()`` / ``registerStageSlot()`` / ``registerEventSubscription()``
/ ``registerConfigSource()`` / ``registerMatchTier()`` / ``registerMatcher()``
/ ``declareAccessiblePorts()`` / ``declareInjectablePipelines()`` /
``declareResourceQuota()`` 返回 ``None``
- ``publishEvent`` 为 ``AsyncMock``(可 ``await``),返回 ``None``。
"""
host = MagicMock()
# 端口获取:返回 MagicMock 桩,调用方可覆盖为带 spec 的端口桩
host.getConfigPort.return_value = MagicMock()
host.getLoggerPort.return_value = MagicMock()
host.getPersistencePort.return_value = MagicMock()
host.getCachePort.return_value = MagicMock()
host.getTracerPort.return_value = MagicMock()
host.getQueuePort.return_value = MagicMock()
host.getConversationPort.return_value = MagicMock()
host.getAgentRunPort.return_value = MagicMock()
host.getIdentityResolverPort.return_value = MagicMock()
host.getChannelAccountRepositoryPort.return_value = MagicMock()
host.getChannelSessionRepositoryPort.return_value = MagicMock()
host.getPairingRepositoryPort.return_value = MagicMock()
host.getAuditLogRepositoryPort.return_value = MagicMock()
host.getOutboxRepositoryPort.return_value = MagicMock()
host.getUserIdentityRepositoryPort.return_value = MagicMock()
host.getIdempotencyRepositoryPort.return_value = MagicMock()
host.getPersistenceHealthPort.return_value = MagicMock()
# 扩展点注册:返回 None
host.registerAdapter.return_value = None
host.registerStageSlot.return_value = None
host.registerEventSubscription.return_value = None
host.registerConfigSource.return_value = None
host.registerMatchTier.return_value = None
host.registerMatcher.return_value = None
# 能力边界声明:返回 None
host.declareAccessiblePorts.return_value = None
host.declareInjectablePipelines.return_value = None
host.declareResourceQuota.return_value = None
# 事件发布async def使用 AsyncMock
host.publishEvent = AsyncMock(return_value=None)
return host