feat: auto-prefix bare email recipients with user: in scion message#335
Conversation
Instead of returning an error when a bare email address (without the "user:" prefix) is passed as a recipient to `scion message`, auto-resolve it as a user recipient by internally prepending "user:". This matches the existing behavior of classifyRecipient() for group (set[]) recipients. Fixes #159
There was a problem hiding this comment.
Code Review
This pull request updates the recipient parsing logic in cmd/message.go to automatically prepend the user: prefix to bare email addresses instead of returning an error. The corresponding tests in cmd/message_test.go have been updated to reflect this change. Feedback on the tests suggests strengthening the assertions to ensure that bare emails are indeed parsed as user recipients (by asserting the specific "sending messages to users requires Hub mode" error) rather than just asserting the absence of the previous email-specific error.
| if err != nil { | ||
| assert.NotContains(t, err.Error(), "looks like an email address") | ||
| assert.NotContains(t, err.Error(), "missing the \"user:\" prefix") | ||
| } |
There was a problem hiding this comment.
The current assertions only verify that the error does not contain email-specific prefix messages. However, if the email parsing logic were broken and fell through to treating the email as an agent name, the test would still pass because the resulting error (agent '...' not found or not running) also does not contain those substrings.
To make this test robust and ensure that the bare email is actually parsed as a user recipient, assert that the command fails with the expected user-recipient error (sending messages to users requires Hub mode).
require.Error(t, err)
assert.Contains(t, err.Error(), "sending messages to users requires Hub mode")
Instead of returning an error when a bare email address (without the "user:" prefix) is passed as a recipient to
scion message, auto-resolve it as a user recipient by internally prepending "user:". This matches the existing behavior of classifyRecipient() for group (set[]) recipients.Fixes #159
Fixes #<issue_number_goes_here>