Fence stale feed results and stop guessing at unknown account state

Signing in again keeps the account ID and the context, so a request
already in flight under the previous credential could land afterwards
and write that user's private feed back into the cache and onto disk.
Feed results now carry the account they were requested for and are
dropped if it has moved.

An account with no recorded status was reported as "sign in required".
While the identity scope is unresolved nothing can read the Keychain
under the right scope, so that is the absence of an answer, not one — on
a tokenless or first-seen Apple account it told users with working
logins to sign in again and dropped reads to local data. It is now a
state of its own.

Transport failures mark the account unreachable instead of leaving it
"signed in", which is what the documented local read fallback keys on.
Neither that nor a rejection is overwritten by the Keychain-based
refresh any more: only the server can clear what the server said.

Disabling sync deliberately does not rewrite Keychain items to local.
That means deleting them, and deleting a synchronizable item propagates
to every device — "stop syncing this login" would sign the user out
elsewhere, which is not what the toggle says. The reasoning is recorded
at the call site.
This commit is contained in:
Arkadiusz Fal
2026-08-26 23:55:50 +02:00
parent b37ca40d37
commit cc0fd3e6f4
10 changed files with 140 additions and 15 deletions

View File

@@ -186,6 +186,24 @@ struct AccountsManagerTests {
#expect(manager.context(forLegacyInstanceID: instanceID) == .account(second.id))
}
@Test("An unresolved identity is not a missing credential")
func unknownStatusIsNotSignedOut() {
let defaults = makeDefaults()
let unresolved = AccountsManager(
identityScope: CredentialIdentityScope(fixedScope: nil),
defaults: defaults
)
let account = unresolved.addAccount(instanceID: UUID())
// Nothing can read the Keychain under the right scope yet, so "no
// credential" is not an answer the app is entitled to give.
#expect(unresolved.status(for: account.id) == .checking)
let resolved = makeManager(defaults: defaults, scope: "identity-A")
let other = resolved.addAccount(instanceID: UUID())
#expect(resolved.status(for: other.id) == .credentialMissing)
}
@Test("A fresh device adopts the synced context")
func firstSyncedContextIsAdopted() {
let manager = makeManager()