fix: address final review findings for provider migration

- Add SessionCoordinator regression test covering switch from an
  authenticated ABox profile to Local experience: remote session is
  logged out and cleared, only Local is the active/observable session,
  credentials are cleared, auto-login disabled, and gateway state stays
  isolated (verified to fail when switch cleanup is removed).
- Replace if/else provider dispatch with exhaustive when over
  ProviderType in all three routing gateways so future enum additions
  fail compilation.
- Silence the known ExperimentalCoroutinesApi opt-in warning in
  ProviderSelectionViewModelTest with a class-level @OptIn.
This commit is contained in:
2026-08-24 23:28:48 +08:00
parent d7f8f8c8e9
commit ae5bc871e8
3 changed files with 51 additions and 7 deletions
@@ -153,11 +153,47 @@ class SessionCoordinatorTest {
assertTrue(!fixture.profiles.loginPreferences(remoteProfile.id).autoLoginEnabled)
}
@Test
fun switchingFromAuthenticatedAboxToLocalClearsRemoteSessionAndIsolatesState() = runTest {
val fixture = Fixture()
fixture.coordinator.selectProvider(remoteProfile)
val loginResult = fixture.coordinator.login(
remoteProfile.id,
credentials,
rememberUsername = true,
autoLogin = true,
)
val switchResult = fixture.coordinator.selectProvider(localProfile)
assertTrue(loginResult is DomainResult.Success)
assertTrue(switchResult is DomainResult.Success)
assertEquals(
localProfile.id,
(switchResult as DomainResult.Success).value?.profileId,
)
assertEquals(localProfile.id, fixture.profiles.activeProfile()?.id)
assertEquals(
localProfile.id,
fixture.coordinator.observeActiveSession().first()?.profileId,
)
assertNull(fixture.remote.observeSession(remoteProfile.id).first())
assertNull(fixture.remote.observeSession(localProfile.id).first())
assertEquals(
localProfile.id,
fixture.local.observeSession(localProfile.id).first()?.profileId,
)
assertNull(
(fixture.credentials.loadCredentials(remoteProfile.id) as DomainResult.Success).value,
)
assertTrue(!fixture.profiles.loginPreferences(remoteProfile.id).autoLoginEnabled)
}
private class Fixture {
val profiles = FakeProviderProfileStore()
val credentials = FakeCredentialStore()
val remote = FakeSessionGateway()
private val local = FakeLocalSessionGateway()
val local = FakeLocalSessionGateway()
val coordinator = SessionCoordinator(profiles, credentials, remote, local)
}