Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(auth): propagate saved credential write failures

xd-boboe8f12976d4fe
diff --git a/apps/desktop/src/main/__tests__/authLoginFlowReset.test.ts b/apps/desktop/src/main/__tests__/authLoginFlowReset.test.ts
index 7af8f5b7db..c3fb9f963f 100644
--- a/apps/desktop/src/main/__tests__/authLoginFlowReset.test.ts
+++ b/apps/desktop/src/main/__tests__/authLoginFlowReset.test.ts
@@ -185,6 +185,7 @@ describe('auth login-flow reset', () => {
expect(source).toContain("'CREDENTIAL_STORE_UNAVAILABLE'");
expect(source).toContain('isPersistedSecretAbsent(AUTH_ACCOUNT_VAULT_KEY)');
expect(source).toContain('readAuthAccountVault({ allowUnreadable: true })');
+ expect(source).toContain('writeAuthAccountVaultOrThrow(vault);');
const syncStart = source.indexOf('export async function syncSavedAccounts()');
const syncEnd = source.indexOf('\n}\n\nexport async function switchSavedAccount', syncStart);
diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.ts
index 61d503452c..98c8bac5a7 100644
--- a/apps/desktop/src/main/authManager.ts
+++ b/apps/desktop/src/main/authManager.ts
@@ -637,6 +637,15 @@ function writeAuthAccountVault(vault: AuthAccountVault): boolean {
return writeSafe(AUTH_ACCOUNT_VAULT_KEY, JSON.stringify(vault));
}
+function writeAuthAccountVaultOrThrow(vault: AuthAccountVault): void {
+ if (writeAuthAccountVault(vault)) return;
+ throw new AuthApiError(
+ 'CREDENTIAL_STORE_UNAVAILABLE',
+ 503,
+ 'Could not persist saved account credentials',
+ );
+}
+
function metadataFromMembership(
membership: AuthMembership | AccountMembership,
passportId: string,
@@ -674,7 +683,7 @@ function rememberResourceSession(
lastUsedAt: options.lastUsedAt ?? Date.now(),
};
if (options.markActive !== false) vault.activeAccountKey = key;
- writeAuthAccountVault(vault);
+ writeAuthAccountVaultOrThrow(vault);
}
function rememberPassportSession(input: {
@@ -685,7 +694,7 @@ function rememberPassportSession(input: {
}): void {
const vault = readAuthAccountVault();
writePassportSessionToVault(vault, input);
- writeAuthAccountVault(vault);
+ writeAuthAccountVaultOrThrow(vault);
}
function writePassportSessionToVault(
@@ -830,14 +839,14 @@ function rememberUpdatedMembershipMetadata(
memberships: [metadataFromMembership(membership, passportId)],
passportMode: 'patch-known',
});
- if (changed) writeAuthAccountVault(vault);
+ if (changed) writeAuthAccountVaultOrThrow(vault);
}
function removeVaultAccount(accountKey: string): void {
const vault = readAuthAccountVault();
delete vault.resources[accountKey];
if (vault.activeAccountKey === accountKey) vault.activeAccountKey = null;
- writeAuthAccountVault(vault);
+ writeAuthAccountVaultOrThrow(vault);
}
function bindResourcePairToSavedAccount(
@@ -2945,7 +2954,7 @@ export async function clearLocalSessionAfterAccountDeletion(): Promise<boolean>
}
}
delete vault.passports[passportVaultKey(deletedRealm, deletedPassportId)];
- writeAuthAccountVault(vault);
+ writeAuthAccountVaultOrThrow(vault);
}
await withAccountFreeOwnerCommit({
reason: 'account-deletion',
diff --git a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
index 99238be1de..2ebad4c675 100644
--- a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
+++ b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
@@ -415,6 +415,17 @@ describe('mobile auth-server login', () => {
);
});
+ it('does not block add-account while saved accounts sync in the background', () => {
+ const sheetSource = readFileSync(
+ resolve(process.cwd(), 'src/session/AccountSwitcherSheet.tsx'),
+ 'utf8',
+ );
+ expect(sheetSource).toContain('disabled={switchingKey !== null}');
+ expect(sheetSource).not.toContain(
+ 'disabled={auth.accountsLoading || switchingKey !== null}',
+ );
+ });
+
it('clears every Device Link account projection when accountGeneration changes', () => {
const source = readFileSync(
resolve(process.cwd(), 'src/device-link/DeviceLinkContext.tsx'),
diff --git a/apps/mobile/src/session/AccountSwitcherSheet.tsx b/apps/mobile/src/session/AccountSwitcherSheet.tsx
index 0e27936929..ec4d92f1bf 100644
--- a/apps/mobile/src/session/AccountSwitcherSheet.tsx
+++ b/apps/mobile/src/session/AccountSwitcherSheet.tsx
@@ -98,7 +98,7 @@ export function AccountSwitcherSheet({
const footer = (
<Pressable
accessibilityRole="button"
- disabled={auth.accountsLoading || switchingKey !== null}
+ disabled={switchingKey !== null}
onPress={() => confirmBoundary(onAddAccount)}
style={({ pressed }) => [
styles.addButton,