fix(slack): avoid logging block text previews

This commit is contained in:
luyifan 2026-07-05 03:49:38 +08:00 committed by Teknium
parent 93102e91cf
commit ece3dd1a4f
2 changed files with 48 additions and 2 deletions

View file

@ -4419,8 +4419,8 @@ class SlackAdapter(BasePlatformAdapter):
if stripped_blocks and stripped_blocks not in text.strip():
logger.debug(
"Slack: extracted additional text from blocks "
"(likely quoted/forwarded content): %s",
stripped_blocks[:300],
"(likely quoted/forwarded content; chars=%d)",
len(stripped_blocks),
)
text = (text.strip() + "\n" + stripped_blocks).strip()

View file

@ -6,8 +6,11 @@ Follows the same pattern as test_whatsapp_group_gating.py.
import sys
import inspect
import logging
from unittest.mock import MagicMock
import pytest
from gateway.config import Platform, PlatformConfig
@ -802,6 +805,49 @@ def test_allowed_channels_env_var_blocks_channel(monkeypatch):
assert _would_process(adapter, channel_id=CHANNEL_ID, mentioned=True) is True
@pytest.mark.asyncio
async def test_block_extraction_debug_log_does_not_include_message_preview(caplog):
secret_block_text = "private incident token: customer-id-12345"
adapter = _make_adapter(allowed_channels=[CHANNEL_ID])
adapter._dedup = MagicMock(is_duplicate=MagicMock(return_value=False))
adapter._lookup_assistant_thread_metadata = MagicMock(return_value={})
adapter._channel_team = {}
event = {
"channel": OTHER_CHANNEL_ID,
"channel_type": "channel",
"ts": "1710000000.000100",
"team": "T1",
"user": "U_USER",
"text": "<@U_BOT_123> see quoted message",
"blocks": [
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_quote",
"elements": [
{
"type": "rich_text_section",
"elements": [
{"type": "text", "text": secret_block_text}
],
}
],
}
],
}
],
}
with caplog.at_level(logging.DEBUG, logger="plugins.platforms.slack.adapter"):
await adapter._handle_slack_message(event)
assert "extracted additional text from blocks" in caplog.text
assert "chars=" in caplog.text
assert secret_block_text not in caplog.text
# ---------------------------------------------------------------------------
# Tests: config bridging for allowed_channels
# ---------------------------------------------------------------------------