From 263ffec1b03114ec98671919943fb61de7ebf1bf Mon Sep 17 00:00:00 2001 From: fesalfayed Date: Mon, 1 Jun 2026 03:33:19 -0400 Subject: [PATCH] fix(whatsapp): resolve LID aliases on modern platforms/ session layout expand_whatsapp_aliases hardcoded get_hermes_home()/whatsapp/session, but the adapter writes lid-mapping files via get_hermes_dir("platforms/whatsapp/ session", "whatsapp/session"). On installs without the legacy directory the two paths diverge, so the resolver finds no mappings and returns the bare LID, which misses the allowlist and silently drops the message. Resolve through the same helper so both sides stay in lockstep on new and legacy layouts. --- gateway/whatsapp_identity.py | 4 +-- tests/gateway/test_whatsapp_identity.py | 37 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/gateway/test_whatsapp_identity.py diff --git a/gateway/whatsapp_identity.py b/gateway/whatsapp_identity.py index 7a0efe4e9f9..19fade10b4e 100644 --- a/gateway/whatsapp_identity.py +++ b/gateway/whatsapp_identity.py @@ -42,7 +42,7 @@ logger = logging.getLogger(__name__) # full-width digits / Unicode word chars can't sneak through. _SAFE_IDENTIFIER_RE = re.compile(r"^[A-Za-z0-9@.+\-]+$") -from hermes_constants import get_hermes_home +from hermes_constants import get_hermes_dir def normalize_whatsapp_identifier(value: str) -> str: @@ -133,7 +133,7 @@ def expand_whatsapp_aliases(identifier: str) -> Set[str]: if not normalized: return set() - session_dir = get_hermes_home() / "whatsapp" / "session" + session_dir = get_hermes_dir("platforms/whatsapp/session", "whatsapp/session") resolved: Set[str] = set() queue = [normalized] diff --git a/tests/gateway/test_whatsapp_identity.py b/tests/gateway/test_whatsapp_identity.py new file mode 100644 index 00000000000..6fa6f840364 --- /dev/null +++ b/tests/gateway/test_whatsapp_identity.py @@ -0,0 +1,37 @@ +"""Tests for gateway.whatsapp_identity alias resolution path.""" + +import json + +from gateway.whatsapp_identity import expand_whatsapp_aliases + + +def test_aliases_resolve_on_modern_platforms_layout(tmp_path, monkeypatch): + tmp_home = tmp_path / "hermes-home" + mapping_dir = tmp_home / "platforms" / "whatsapp" / "session" + mapping_dir.mkdir(parents=True, exist_ok=True) + (mapping_dir / "lid-mapping-999999999999999.json").write_text( + json.dumps("15551234567@s.whatsapp.net"), + encoding="utf-8", + ) + monkeypatch.setenv("HERMES_HOME", str(tmp_home)) + + assert expand_whatsapp_aliases("999999999999999@lid") == { + "999999999999999", + "15551234567", + } + + +def test_aliases_resolve_on_legacy_layout(tmp_path, monkeypatch): + tmp_home = tmp_path / "hermes-home" + mapping_dir = tmp_home / "whatsapp" / "session" + mapping_dir.mkdir(parents=True, exist_ok=True) + (mapping_dir / "lid-mapping-999999999999999.json").write_text( + json.dumps("15551234567@s.whatsapp.net"), + encoding="utf-8", + ) + monkeypatch.setenv("HERMES_HOME", str(tmp_home)) + + assert expand_whatsapp_aliases("999999999999999@lid") == { + "999999999999999", + "15551234567", + }