diff --git a/src/main/native-chat/claude-structured-managed-account-support.test.ts b/src/main/native-chat/claude-structured-managed-account-support.test.ts index 86054b9aab2..64248100429 100644 --- a/src/main/native-chat/claude-structured-managed-account-support.test.ts +++ b/src/main/native-chat/claude-structured-managed-account-support.test.ts @@ -70,6 +70,20 @@ describe('structuredClaudeMatchesActiveManagedAccount', () => { ).toBe(false) }) + /** Absent is not empty. An empty array is a real answer — the user has no managed accounts, so + * nothing claims an identity and the ambient path is legitimate. Settings with no accounts field + * are settings we failed to parse, which is the same epistemic state as unreadable. */ + it('separates an empty account list from an absent one', () => { + expect( + structuredClaudeMatchesActiveManagedAccount(settings({ claudeManagedAccounts: [] })) + ).toBe(true) + expect( + structuredClaudeMatchesActiveManagedAccount({ + activeClaudeManagedAccountId: null + } as unknown as ClaudeManagedAccountGateSettings) + ).toBe(false) + }) + it('fails closed when the settings cannot be read at all', () => { expect(structuredClaudeMatchesActiveManagedAccount(null)).toBe(false) expect(structuredClaudeMatchesActiveManagedAccount(undefined)).toBe(false) diff --git a/src/main/native-chat/claude-structured-managed-account-support.ts b/src/main/native-chat/claude-structured-managed-account-support.ts index cd3afa473ca..46967809641 100644 --- a/src/main/native-chat/claude-structured-managed-account-support.ts +++ b/src/main/native-chat/claude-structured-managed-account-support.ts @@ -27,6 +27,8 @@ export function structuredClaudeMatchesActiveManagedAccount( settings: ClaudeManagedAccountGateSettings | null | undefined ): boolean { const accounts = settings?.claudeManagedAccounts + // Absent is not empty: an empty list is a real "no managed accounts" answer, but a missing field + // is settings we failed to parse, which is the same unknown as unreadable. Do not merge these. if (!settings || !Array.isArray(accounts)) { return false }