fix(slack): coerce string unfurl knobs on the native plane
Relay-plane parity: hermes config set / Railway persist YAML booleans as strings, and _slack_unfurl_kwargs silently dropped them — so 'unfurl_links: "false"' was a no-op on native while working on relay. Coerce recognized string booleans exactly as _slack_unfurl_hints does; unrecognized values still drop so junk config keeps Slack's default instead of accidentally suppressing previews. Replaces test_send_ignores_non_boolean_unfurl_options (which froze the dropped-string behavior) with coercion + junk-drop tests.
This commit is contained in:
@@ -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(
|
||||
|
||||
+30
-12
@@ -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 &."""
|
||||
|
||||
Reference in New Issue
Block a user