Skip to content

Fix MEGA ug/usl response compatibility - #28

Open
mjc wants to merge 4 commits into
Hirevo:mainfrom
mjc:mjc/userinfo-audit
Open

Fix MEGA ug/usl response compatibility#28
mjc wants to merge 4 commits into
Hirevo:mainfrom
mjc:mjc/userinfo-audit

Conversation

@mjc

@mjc mjc commented May 27, 2026

Copy link
Copy Markdown

Summary

Fix two response compatibility issues against MEGA's current API / SDK behavior:

  • ug / user info: accept empty optional user attributes instead of treating them as populated values
  • usl / list sessions: accept MEGA's positional session-array response shape

What changed

ug / user info

  • treat empty optional base64-encoded attributes as missing
  • correctly handle empty country, birthday, birthmonth, and birthyear
  • keep partial or invalid birth-date data from producing a bogus date
  • move user-info response conversion into a dedicated typed conversion with small internal decoding helpers

usl / list sessions

  • deserialize MEGA's positional session rows
  • tolerate null/empty textual fields the way the MEGA SDK does
  • preserve object-shape fallback compatibility
  • reduce parser overhead while keeping behavior the same

Tests

Added SDK-linked regression coverage for:

  • ug protocol parsing and public UserInfo mapping
  • usl protocol parsing and public SessionInfo mapping
  • empty optional attrs
  • partial / invalid birth-date cases
  • 6 / 8 / 9-field session row shapes
  • null text fields
  • invalid session row lengths

The new tests include links back to the corresponding meganz/sdk parser code used as the source of truth.

Why

MEGA's real response shapes are more permissive than mega-rs previously assumed in these two endpoints. This change makes mega-rs accept valid MEGA output instead of failing on empty optional user-info attrs or positional session responses.

mjc and others added 3 commits May 27, 2026 10:39
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 27, 2026 16:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a dedicated UserInfo module and improves protocol parsing to better match MEGA’s SDK behavior, with regression tests covering edge cases.

Changes:

  • Introduces src/user_info with base64 decoding helpers and a UserInfo model implementing TryFrom<UserInfoResponse>.
  • Refactors Client::user_info to use the new UserInfo conversion and re-exports UserInfo from the crate.
  • Implements a custom Deserialize for protocol::commands::SessionInfo to accept multiple wire shapes (object and positional arrays), plus adds regression tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/user_info/decoding.rs Adds shared base64 decoding utilities for required/optional fields and numeric parsing.
src/user_info.rs Introduces UserInfo and conversion logic from the protocol response, with tests.
src/sessions.rs Adds tests verifying SessionInfo mapping from protocol session info.
src/protocol/commands.rs Adds flexible SessionInfo deserialization and extensive regression tests for response shapes.
src/lib.rs Wires in the new user_info module, re-exports UserInfo, and refactors Client::user_info.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib.rs
NaiveDate::from_ymd_opt(year, month, day)
},
})
UserInfo::try_from(response)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a false positive: in match responses.as_slice() { [Response::UserInfo(response)] => response, ... }, response is already borrowed from the slice, so UserInfo::try_from(response) is passing &UserInfoResponse as intended.

Comment thread src/protocol/commands.rs
Comment thread src/protocol/commands.rs
Comment thread src/sessions.rs Outdated
Comment thread src/user_info/decoding.rs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants