mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
The cherry-picked model_picker test installed its own discord mock at module-import time via a local _ensure_discord_mock(), overwriting sys.modules['discord'] with a mock that lacked attributes other gateway tests needed (Intents.default(), File, app_commands.Choice). On pytest-xdist workers that collected test_discord_model_picker.py first, the shared mock in tests/gateway/conftest.py got clobbered and downstream tests failed with AttributeError / TypeError against missing mock attrs. Classic sys.modules cross-test pollution (see xdist-cross-test-pollution skill). Fix: - Extend the canonical _ensure_discord_mock() in tests/gateway/conftest.py to cover everything the model_picker test needs: real View/Select/ Button/SelectOption classes (not MagicMock sentinels), an Embed class that preserves title/description/color kwargs for assertion, and Color.greyple. - Strip the duplicated mock-setup block from test_discord_model_picker.py and rely on the shared mock that conftest installs at collection time. Regression check: scripts/run_tests.sh tests/gateway/ tests/hermes_cli/ -k 'discord or model or copilot or provider' -o 'addopts=' 1291 passed (was 1288 passed + 3 xdist-ordered failures before this commit).
83 lines
2.5 KiB
Python
83 lines
2.5 KiB
Python
"""Regression tests for the Discord /model picker.
|
|
|
|
Uses the shared discord mock from tests/gateway/conftest.py (installed
|
|
at collection time via _ensure_discord_mock()). Previously this file
|
|
installed its own mock at module-import time and clobbered sys.modules,
|
|
breaking other gateway tests under pytest-xdist.
|
|
"""
|
|
|
|
from types import SimpleNamespace
|
|
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
|
|
from gateway.platforms.discord import ModelPickerView
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_model_picker_clears_controls_before_running_switch_callback():
|
|
events: list[object] = []
|
|
|
|
async def on_model_selected(chat_id: str, model_id: str, provider_slug: str) -> str:
|
|
events.append(("switch", chat_id, model_id, provider_slug))
|
|
return "Model switched"
|
|
|
|
async def edit_message(**kwargs):
|
|
events.append(
|
|
(
|
|
"initial-edit",
|
|
kwargs["embed"].title,
|
|
kwargs["embed"].description,
|
|
kwargs["view"],
|
|
)
|
|
)
|
|
|
|
async def edit_original_response(**kwargs):
|
|
events.append((
|
|
"final-edit",
|
|
kwargs["embed"].title,
|
|
kwargs["embed"].description,
|
|
kwargs["view"],
|
|
))
|
|
|
|
view = ModelPickerView(
|
|
providers=[
|
|
{
|
|
"slug": "copilot",
|
|
"name": "GitHub Copilot",
|
|
"models": ["gpt-5.4"],
|
|
"total_models": 1,
|
|
"is_current": True,
|
|
}
|
|
],
|
|
current_model="gpt-5-mini",
|
|
current_provider="copilot",
|
|
session_key="session-1",
|
|
on_model_selected=on_model_selected,
|
|
allowed_user_ids=set(),
|
|
)
|
|
view._selected_provider = "copilot"
|
|
|
|
interaction = SimpleNamespace(
|
|
user=SimpleNamespace(id=123),
|
|
channel_id=456,
|
|
data={"values": ["gpt-5.4"]},
|
|
response=SimpleNamespace(
|
|
defer=AsyncMock(),
|
|
send_message=AsyncMock(),
|
|
edit_message=AsyncMock(side_effect=edit_message),
|
|
),
|
|
edit_original_response=AsyncMock(side_effect=edit_original_response),
|
|
)
|
|
|
|
await view._on_model_selected(interaction)
|
|
|
|
assert events == [
|
|
("initial-edit", "⚙ Switching Model", "Switching to `gpt-5.4`...", None),
|
|
("switch", "456", "gpt-5.4", "copilot"),
|
|
("final-edit", "⚙ Model Switched", "Model switched", None),
|
|
]
|
|
interaction.response.edit_message.assert_awaited_once()
|
|
interaction.response.defer.assert_not_called()
|
|
interaction.edit_original_response.assert_awaited_once()
|