Skip to content

Decode TSession.userRoles with backward compatibility#79

Merged
ps2 merged 3 commits into
devfrom
session-userRoles-decode-backward-compat
Jun 1, 2026
Merged

Decode TSession.userRoles with backward compatibility#79
ps2 merged 3 commits into
devfrom
session-userRoles-decode-backward-compat

Conversation

@ps2

@ps2 ps2 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • TSession.userRoles (added in [LOOP-5150] storing user roles with session #76) is a non-optional [String], so the synthesized Codable decoder throws .keyNotFound when reading a session JSON persisted before that field existed.
  • In downstream consumers (e.g. TidepoolServiceKit.TidepoolService.init?(rawState:)), this throw bubbles up through KeychainManager.getSession(for:) and causes the whole init? to return nil, dropping the saved service entry and forcing the user to re-authenticate (and re-add the Tidepool service) after an upgrade.
  • Provide a custom init(from:) that uses decodeIfPresent for userRoles with a [] default. Old JSON decodes cleanly; new JSON unchanged. The public API stays the same (userRoles remains non-optional [String]), so no caller changes are needed.
  • Adds testDecodingLegacySessionWithoutUserRolesYieldsEmpty to lock this in.

Test plan

  • testDecodingLegacySessionWithoutUserRolesYieldsEmpty passes.
  • Pre-existing testInitializer still passes.
  • The pre-existing testCodableAsJSON failure on dev is unrelated (JSON key-order mismatch — fails on dev before this PR too).

ps2 added 2 commits June 1, 2026 13:35
Sessions persisted before #76 added userRoles lack the key, so the
synthesized Codable decoder throws .keyNotFound. In TidepoolService that
kills init?(rawState:), which drops the saved service entry and forces
the user to re-authenticate on the next upgrade.

Provide a custom init(from:) that uses decodeIfPresent for userRoles
defaulting to []. Keeps the public API unchanged (userRoles stays
non-optional) and adds a backward-compat test.
CircleCI's m4pro.medium resource class does not support Xcode 14.1.0.
Use Xcode 16.4 and drop the OS pin on the simulator destination.
@ps2 ps2 requested review from Camji55 and nhamming June 1, 2026 19:46
Newer Foundation emits Doubles at full IEEE-754 precision (e.g. 2.34 ->
2.3399...) and key order can differ between JSONEncoder and
JSONSerialization output -- both of which broke the previous raw string
comparison even though the data is equivalent. Parse both sides back to
Foundation objects and compare via NSObject equality, which handles
nested values, key ordering, and number equivalence by value.

Brings 46 pre-existing test failures back to green on current SDKs (and
preserves the encode/decode round-trip assertions).
@ps2 ps2 merged commit 290bd04 into dev Jun 1, 2026
2 checks passed
loopkitdev pushed a commit to loopkitdev/LoopWorkspace that referenced this pull request Jun 1, 2026
Includes tidepool-org/TidepoolKit#79 so sessions persisted before
userRoles was added decode cleanly on upgrade -- preserves the
TidepoolService configuration across the dev->sync upgrade instead
of forcing the user to re-authenticate.
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