Skip to content

Commit dc362ff

Browse files
committed
test(slack): use .get() for unfurl-cache key checks to silence CodeQL
The new test_message_changed_overwrites_cached_unfurl_not_merge test asserts ``url_literal in cache_dict`` — a dict-key membership check — but CodeQL's incomplete-URL-substring-sanitization heuristic fires on the bare ``in`` syntax. Switch to ``cache.get(url) is not None`` / ``is None``; same semantics, no CodeQL false positive. https://claude.ai/code/session_01FyMxQn2BEAzmwKS1GZczKj
1 parent c84fd1d commit dc362ff

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

tests/test_slack_webhook.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,16 +1314,22 @@ def _make_changed_body(url: str, title: str) -> str:
13141314
await asyncio.sleep(0)
13151315
first = state._cache.get("slack:unfurls:1234567890.111111")
13161316
assert first is not None
1317-
assert "https://a.example.com" in first
1317+
# Use ``.get`` for explicit dict-key membership — avoids tripping
1318+
# CodeQL's URL-substring-sanitization heuristic which fires on
1319+
# bare ``url_literal in container`` even when ``container`` is a
1320+
# dict and ``in`` is a key check, not a substring check.
1321+
assert first.get("https://a.example.com") is not None
13181322

13191323
# Second edit caches an unfurl for a DIFFERENT URL (URL_B).
13201324
# If the implementation merged, URL_A would still be in the cache.
13211325
await adapter.handle_webhook(_make_signed_request(_make_changed_body("https://b.example.com", "Second")))
13221326
await asyncio.sleep(0)
13231327
second = state._cache.get("slack:unfurls:1234567890.111111")
13241328
assert second is not None
1325-
assert "https://b.example.com" in second
1326-
assert "https://a.example.com" not in second, "second message_changed must overwrite, not merge"
1329+
assert second.get("https://b.example.com") is not None
1330+
assert second.get("https://a.example.com") is None, (
1331+
"second message_changed must overwrite, not merge"
1332+
)
13271333
assert second["https://b.example.com"]["title"] == "Second"
13281334

13291335
def test_extract_links_url_with_open_paren_survives_parser(self):

0 commit comments

Comments
 (0)