fix(send_message): accept E.164 phone numbers for signal/sms/whatsapp (#12936)

Follow-up to #12704. The SignalAdapter can resolve +E164 numbers to
UUIDs via listContacts, but _parse_target_ref() in the send_message
tool rejected '+' as non-digit and fell through to channel-name
resolution — which fails for contacts without a prior session entry.

Adds an E.164 branch in _parse_target_ref for phone-based platforms
(signal, sms, whatsapp) that preserves the leading '+' so downstream
adapters keep the format they expect. Non-phone platforms are
unaffected.

Reported by @qdrop17 on Discord after pulling #12704.
This commit is contained in:
Teknium 2026-04-20 03:02:44 -07:00 committed by GitHub
parent 8f4db7bbd5
commit be472138f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 0 deletions

View file

@ -770,6 +770,46 @@ class TestParseTargetRefMatrix:
assert is_explicit is False
class TestParseTargetRefE164:
"""_parse_target_ref accepts E.164 phone numbers for phone-based platforms."""
def test_signal_e164_preserves_plus_prefix(self):
"""signal:+E164 is explicit and preserves the leading '+' for signal-cli."""
chat_id, thread_id, is_explicit = _parse_target_ref("signal", "+41791234567")
assert chat_id == "+41791234567"
assert thread_id is None
assert is_explicit is True
def test_sms_e164_is_explicit(self):
chat_id, _, is_explicit = _parse_target_ref("sms", "+15551234567")
assert chat_id == "+15551234567"
assert is_explicit is True
def test_whatsapp_e164_is_explicit(self):
chat_id, _, is_explicit = _parse_target_ref("whatsapp", "+15551234567")
assert chat_id == "+15551234567"
assert is_explicit is True
def test_signal_bare_digits_still_work(self):
"""Bare digit strings continue to match the generic numeric branch."""
chat_id, _, is_explicit = _parse_target_ref("signal", "15551234567")
assert chat_id == "15551234567"
assert is_explicit is True
def test_signal_invalid_e164_rejected(self):
"""Too-short, too-long, and non-numeric E.164 strings are not explicit."""
assert _parse_target_ref("signal", "+123")[2] is False
assert _parse_target_ref("signal", "+1234567890123456")[2] is False
assert _parse_target_ref("signal", "+12abc4567890")[2] is False
assert _parse_target_ref("signal", "+")[2] is False
def test_e164_prefix_only_matches_phone_platforms(self):
"""'+' prefix must NOT be treated as explicit for non-phone platforms."""
assert _parse_target_ref("telegram", "+15551234567")[2] is False
assert _parse_target_ref("discord", "+15551234567")[2] is False
assert _parse_target_ref("matrix", "+15551234567")[2] is False
class TestSendDiscordThreadId:
"""_send_discord uses thread_id when provided."""