diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py index c27a65b2d1..b83b70d61d 100644 --- a/plugins/platforms/slack/adapter.py +++ b/plugins/platforms/slack/adapter.py @@ -85,13 +85,32 @@ def _slack_unfurl_kwargs(extra: Optional[Dict[str, Any]]) -> Dict[str, bool]: Omitting a key preserves Slack's existing default. Passing ``False`` suppresses only the automatic preview while leaving the link text and URL in the message untouched. + + String booleans are coerced the same way as the relay plane's + ``_slack_unfurl_hints``: ``hermes config set`` and Railway persist YAML + ``"true"``/``"false"`` as strings, and a silently dropped string would + make the knob a no-op on the native plane only. Unrecognized values are + dropped (NOT coerced to False) so junk config keeps Slack's default + instead of accidentally suppressing previews. """ settings = extra or {} - return { - key: settings[key] - for key in ("unfurl_links", "unfurl_media") - if isinstance(settings.get(key), bool) - } + kwargs: Dict[str, bool] = {} + for key in ("unfurl_links", "unfurl_media"): + val = settings.get(key) + if isinstance(val, bool): + kwargs[key] = val + elif isinstance(val, str) and val.strip().lower() in { + "1", + "0", + "true", + "false", + "yes", + "no", + "on", + "off", + }: + kwargs[key] = val.strip().lower() in {"1", "true", "yes", "on"} + return kwargs async def _read_error_text_limited( diff --git a/tests/gateway/test_slack.py b/tests/gateway/test_slack.py index 29709db40f..055b6ed35a 100644 --- a/tests/gateway/test_slack.py +++ b/tests/gateway/test_slack.py @@ -3519,6 +3519,36 @@ class TestMessageSplitting: assert "unfurl_links" not in kwargs assert "unfurl_media" not in kwargs + @pytest.mark.asyncio + async def test_send_coerces_string_unfurl_options(self, adapter): + """`hermes config set` / Railway persist YAML booleans as strings. + + Relay-plane parity: string "false"/"true" must coerce instead of + being silently dropped (which would leave previews on with no error). + """ + adapter.config.extra["unfurl_links"] = "false" + adapter.config.extra["unfurl_media"] = "true" + adapter._app.client.chat_postMessage = AsyncMock(return_value={"ts": "ts1"}) + + await adapter.send("C123", "https://example.com") + + kwargs = adapter._app.client.chat_postMessage.call_args.kwargs + assert kwargs["unfurl_links"] is False + assert kwargs["unfurl_media"] is True + + @pytest.mark.asyncio + async def test_send_drops_junk_unfurl_values(self, adapter): + """Unrecognized values keep Slack's default rather than suppressing.""" + adapter.config.extra["unfurl_links"] = "maybe" + adapter.config.extra["unfurl_media"] = 0 + adapter._app.client.chat_postMessage = AsyncMock(return_value={"ts": "ts1"}) + + await adapter.send("C123", "https://example.com") + + kwargs = adapter._app.client.chat_postMessage.call_args.kwargs + assert "unfurl_links" not in kwargs + assert "unfurl_media" not in kwargs + @pytest.mark.asyncio async def test_send_passes_unfurl_options_to_every_chunk(self, adapter): adapter.config.extra["unfurl_links"] = False @@ -3532,18 +3562,6 @@ class TestMessageSplitting: assert call.kwargs["unfurl_links"] is False assert call.kwargs["unfurl_media"] is False - @pytest.mark.asyncio - async def test_send_ignores_non_boolean_unfurl_options(self, adapter): - adapter.config.extra["unfurl_links"] = "false" - adapter.config.extra["unfurl_media"] = 0 - adapter._app.client.chat_postMessage = AsyncMock(return_value={"ts": "ts1"}) - - await adapter.send("C123", "https://example.com") - - kwargs = adapter._app.client.chat_postMessage.call_args.kwargs - assert "unfurl_links" not in kwargs - assert "unfurl_media" not in kwargs - @pytest.mark.asyncio async def test_send_does_not_double_escape_entities(self, adapter): """Pre-escaped & in sent messages must not become &."""