9f3cc02148
- _maybe_send_quick_reply() in adapter.py: Dedup via OutboundGate-Flag - outbound_gate.py: quick_reply_sent-Flag in _TurnHandle, mark/check-Methoden - Same-Room: 'Ich bin gerade beschäftigt' (kein Raum-Name) - Cross-Room: 'Ich antworte gerade in #RaumX' - Tests: test_outbound_gate.py +50 Zeilen, test_quick_reply_dedup.py +83 Zeilen Re-Implementierung nach .45 Clean-Install (31.07.2026).
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
"""
|
|
P1: Quick-Reply Dedup — Integration-Tests fuer _maybe_send_quick_reply.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
|
|
from plugin.archivar.outbound_gate import OutboundGate
|
|
|
|
|
|
def _make_bare_adapter():
|
|
from plugin.adapter import RocketChatAdapter
|
|
return RocketChatAdapter.__new__(RocketChatAdapter)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_parallel_tasks_quick_reply_only_once():
|
|
"""Parallele Tasks → Quick-Reply nur 1x (Dedup)."""
|
|
adapter = _make_bare_adapter()
|
|
gate = OutboundGate()
|
|
adapter._outbound_gate = gate
|
|
await gate.try_acquire("ROOM_A", "token-a")
|
|
|
|
call_count = 0
|
|
async def mock_post(room_id, text):
|
|
nonlocal call_count; call_count += 1; return "ok"
|
|
adapter._post_message_unlocked = mock_post
|
|
|
|
results = await asyncio.gather(
|
|
adapter._maybe_send_quick_reply("ROOM_B", "ROOM_A", "Alpha"),
|
|
adapter._maybe_send_quick_reply("ROOM_B", "ROOM_A", "Alpha"),
|
|
)
|
|
assert call_count == 1
|
|
assert sum(1 for r in results if r is not None) == 1
|
|
assert sum(1 for r in results if r is None) == 1
|
|
gate.release("ROOM_A", "token-a")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_same_room_quick_reply_text_no_room_name():
|
|
"""Same-Raum → Text OHNE Raum-Namen."""
|
|
adapter = _make_bare_adapter()
|
|
gate = OutboundGate()
|
|
adapter._outbound_gate = gate
|
|
await gate.try_acquire("ROOM_S", "token-s")
|
|
|
|
posted = []
|
|
async def mock_post(room_id, text):
|
|
posted.append(text); return "ok"
|
|
adapter._post_message_unlocked = mock_post
|
|
|
|
result = await adapter._maybe_send_quick_reply("ROOM_S", "ROOM_S", "Testraum")
|
|
assert result is not None
|
|
assert "Testraum" not in posted[0]
|
|
assert "#" not in posted[0]
|
|
assert "beschäftigt" in posted[0]
|
|
gate.release("ROOM_S", "token-s")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cross_room_quick_reply_text_has_room_name():
|
|
"""Cross-Raum → Text MIT Raum-Namen."""
|
|
adapter = _make_bare_adapter()
|
|
gate = OutboundGate()
|
|
adapter._outbound_gate = gate
|
|
await gate.try_acquire("ROOM_A", "token-c")
|
|
|
|
posted = []
|
|
async def mock_post(room_id, text):
|
|
posted.append(text); return "ok"
|
|
adapter._post_message_unlocked = mock_post
|
|
|
|
result = await adapter._maybe_send_quick_reply("ROOM_T", "ROOM_A", "Gamma")
|
|
assert result is not None
|
|
assert "Gamma" in posted[0]
|
|
assert "#" in posted[0]
|
|
gate.release("ROOM_A", "token-c")
|