test: improve deterministic unit test coverage
This commit is contained in:
@@ -1016,6 +1016,8 @@ async def test_validate_allow_from_allows_empty_list():
|
||||
|
||||
# Should not raise — empty list defers to pairing store
|
||||
mgr._validate_allow_from()
|
||||
assert list(mgr.channels) == ["test"]
|
||||
assert mgr.channels["test"].config.allow_from == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1033,6 +1035,8 @@ async def test_validate_allow_from_passes_with_asterisk():
|
||||
|
||||
# Should not raise
|
||||
mgr._validate_allow_from()
|
||||
assert list(mgr.channels) == ["test"]
|
||||
assert mgr.channels["test"].config.allow_from == ["*"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1049,6 +1053,8 @@ async def test_validate_allow_from_allows_empty_dict_allow_from():
|
||||
mgr._dispatch_task = None
|
||||
|
||||
mgr._validate_allow_from()
|
||||
assert list(mgr.channels) == ["test"]
|
||||
assert mgr.channels["test"].config["allow_from"] == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1079,6 +1085,8 @@ async def test_validate_allow_from_allows_missing_allow_from():
|
||||
|
||||
# Should not raise — pairing-only mode
|
||||
mgr._validate_allow_from()
|
||||
assert list(mgr.channels) == ["test"]
|
||||
assert "allow_from" not in mgr.channels["test"].config
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1206,6 +1214,8 @@ async def test_start_channel_logs_error_on_failure():
|
||||
|
||||
# Should not raise, just log error
|
||||
await mgr._start_channel("failing", ch)
|
||||
assert mgr.channels == {}
|
||||
assert mgr._dispatch_task is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1237,6 +1247,8 @@ async def test_stop_all_handles_channel_exception():
|
||||
|
||||
# Should not raise even if channel.stop() raises
|
||||
await mgr.stop_all()
|
||||
assert list(mgr.channels) == ["stopfailing"]
|
||||
assert mgr._dispatch_task is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -105,6 +105,7 @@ class TestRemoveReactionSync:
|
||||
|
||||
# Should not raise
|
||||
ch._remove_reaction_sync("om_001", "rx_42")
|
||||
ch._client.im.v1.message_reaction.delete.assert_called_once()
|
||||
|
||||
def test_handles_exception_gracefully(self):
|
||||
ch = _make_channel()
|
||||
@@ -112,6 +113,7 @@ class TestRemoveReactionSync:
|
||||
|
||||
# Should not raise
|
||||
ch._remove_reaction_sync("om_001", "rx_42")
|
||||
ch._client.im.v1.message_reaction.delete.assert_called_once()
|
||||
|
||||
|
||||
# ── _remove_reaction (async) ────────────────────────────────────────────────
|
||||
|
||||
@@ -118,11 +118,13 @@ async def test_send_exception_caught_not_raised() -> None:
|
||||
channel = QQChannel(QQConfig(app_id="app", secret="secret", allow_from=["*"]), MessageBus())
|
||||
channel._client = _FakeClient()
|
||||
|
||||
with patch.object(channel, "_send_text_only", new_callable=AsyncMock, side_effect=RuntimeError("boom")):
|
||||
with patch.object(
|
||||
channel, "_send_text_only", new_callable=AsyncMock, side_effect=RuntimeError("boom")
|
||||
) as send_text:
|
||||
await channel.send(
|
||||
OutboundMessage(channel="qq", chat_id="user1", content="hello")
|
||||
)
|
||||
# No exception raised — test passes if we get here.
|
||||
send_text.assert_awaited_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -260,6 +262,8 @@ async def test_on_message_exception_caught_not_raised() -> None:
|
||||
bad_data = SimpleNamespace(id="x1", content="hi")
|
||||
# Should not raise
|
||||
await channel._on_message(bad_data, is_group=False)
|
||||
assert channel._client.api.c2c_calls == []
|
||||
assert channel._client.api.group_calls == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -686,6 +686,7 @@ async def test_send_missing_connection_is_noop_without_error() -> None:
|
||||
channel = WebSocketChannel({"enabled": True, "allowFrom": ["*"]}, bus, gateway=_basic_handler(bus))
|
||||
msg = OutboundMessage(channel="websocket", chat_id="missing", content="x")
|
||||
await channel.send(msg)
|
||||
assert channel._subs == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1006,7 +1007,7 @@ async def test_send_reasoning_without_subscribers_is_noop() -> None:
|
||||
|
||||
await channel.send_reasoning_delta("unattached", "thinking", None)
|
||||
await channel.send_reasoning_end("unattached", None)
|
||||
# No subscribers, no exception, no send.
|
||||
assert channel._subs == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1299,6 +1300,7 @@ async def test_send_delta_missing_connection_is_noop() -> None:
|
||||
channel = WebSocketChannel({"enabled": True, "allowFrom": ["*"], "streaming": True}, bus, gateway=_basic_handler(bus))
|
||||
# No exception, no error — just a no-op
|
||||
await channel.send_delta("nonexistent", "chunk", {"_stream_delta": True, "_stream_id": "s1"})
|
||||
assert channel._subs == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1308,6 +1310,7 @@ async def test_stop_is_idempotent() -> None:
|
||||
# stop() before start() should not raise
|
||||
await channel.stop()
|
||||
await channel.stop()
|
||||
assert channel._subs == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -420,7 +420,7 @@ async def test_send_exception_caught_not_raised() -> None:
|
||||
await channel.send(
|
||||
OutboundMessage(channel="wecom", chat_id="chat1", content="fail test")
|
||||
)
|
||||
# No exception — test passes if we reach here.
|
||||
client.reply_stream.assert_called_once()
|
||||
|
||||
|
||||
# ── _process_message() ──────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user