diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py index 58ba0d91f10d..fe4b3091b7c5 100644 --- a/plugins/platforms/slack/adapter.py +++ b/plugins/platforms/slack/adapter.py @@ -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() diff --git a/tests/gateway/test_slack_mention.py b/tests/gateway/test_slack_mention.py index eefc54f6d74e..3faaf7fdd3f2 100644 --- a/tests/gateway/test_slack_mention.py +++ b/tests/gateway/test_slack_mention.py @@ -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 # ---------------------------------------------------------------------------