Skip to content

Add tests for RestoreFromBackupManagerImpl (data transfer support) - #826

Draft
LouisCAD with Copilot wants to merge 19 commits into
data-transfer-supportfrom
copilot/wip-address-feedback-tests-data-transfer-support
Draft

Add tests for RestoreFromBackupManagerImpl (data transfer support)#826
LouisCAD with Copilot wants to merge 19 commits into
data-transfer-supportfrom
copilot/wip-address-feedback-tests-data-transfer-support

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thanks for the feedback on #825. This PR targets that branch and adds unit test coverage for RestoreFromBackupManagerImpl.

Original PR: #825
Triggering review: #825 (comment)

@copilot Can you make a PR targeting this branch that tests it? I'm curious to see the approach you will pick.

Approach

To make RestoreFromBackupManagerImpl testable in isolation, two optional constructor parameters were added — both default to their existing production values so no call sites are affected:

  • userDatabase: UserDatabase — allows injecting an in-memory Room database
  • tokenGenerator: DerivedTokenGenerator? — allows injecting a FakeDerivedTokenGenerator; falls back to the existing lazy DerivedTokenGeneratorImpl when null

Tests follow the existing Robolectric + in-memory DB pattern from BaseAccountUtilsTest. A collectStatesUntilSettled helper drives the entire state machine through a single flow.first { } call, routing any RestoringFromBackupFailed through an onFailed lambda — avoiding separate launch collectors and the ordering surprises they bring.

Test coverage (RestoreFromBackupManagerImplTest)

Scenario What is asserted
No users Settled emitted immediately, no derivation
Same-device binding present Settled immediately, no derivation
Multiple users, all same device Settled immediately
Pre-v9 user with missing binding Binding created for current device, Settled
Multiple pre-v9 users All bindings created, Settled
Transferred device, derivation succeeds RestoringFromBackup → Settled, token & binding updated in DB
Multiple transferred users, all succeed All bindings updated
Mixed (same-device + transferred) Only the transferred user is restored
Derivation failure RestoringFromBackupFailed emitted with correct cause type
Failure then retry (generator swapped in onFailed) Settled, token updated with retried value
Failure then give-up Failed user removed via registerRemoveUser, Settled
Partial failure (one same-device + one transferred-and-failing) Only the failed user is removed

LouisCAD and others added 18 commits July 29, 2026 13:24
This commit also renames LiveData returning getAll() to allAsLiveData()
This could cause notification and device/app registration to
not be done again after the user got logged out and re-logged in.
This avoids clashes with the splashscreen's logo
We are not going to allow reusing them.
However, we will probably consider using the "standard" API (over the "classic" one),
to allow generating many tokens for cheaper thanks to the shared costly operation.
Make RestoreFromBackupManagerImpl accept injectable userDatabase and
tokenGenerator constructor parameters (defaulting to the existing
production singletons) so the class can be exercised in isolation.

Add RestoreFromBackupManagerImplTest covering the full state-machine:
- No users → Settled immediately
- Same-device users → Settled immediately (no derivation)
- Pre-v9 users with missing binding → binding added, Settled
- Multiple users, all missing bindings → bindings added, Settled
- Transferred device with successful derivation → token & binding updated
- Multiple transferred users, all succeed
- Mixed (same-device + transferred)
- Derivation failure → RestoringFromBackupFailed state emitted
- Failure then retry (generator swapped to success) → Settled
- Failure then give-up → failed user removed, Settled
- Partial failure (one same-device, one transferred-and-failed) → only
  failed user removed
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
8.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copilot AI changed the title [WIP] [WIP] Address feedback and add tests for data transfer support feature Add tests for RestoreFromBackupManagerImpl (data transfer support) Jul 30, 2026
Copilot AI requested a review from LouisCAD July 30, 2026 15:15
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