mirror of
https://github.com/nexu-io/open-design.git
synced 2026-10-27 09:51:12 +01:00
The saved-key badge was wired to `isSavedState = apiKeyConfigured && !hasPendingEdit`, which made it disappear on the first keystroke as soon as the user started typing a draft replacement. Users reading the settings panel saw the saved key indicator vanish before they had clicked Save and reasonably assumed the stored credential had already been overwritten or removed. Credential editing is a high-trust workflow; a UI that fakes a state change before the durable write is the wrong default. Replaced the boolean derivation with a single helper `deriveComposioCredentialState` returning one of `empty | pending-new | saved | saved-pending`. The component now shows the saved-key badge for both `saved` and `saved-pending`, so the indicator stays anchored while the user types. The hint text differentiates all four states so the unsaved-replacement case is still clearly called out. Helper is exported and unit-tested in `apps/web/tests/components/SettingsDialog.test.ts` against the empty, pending-new, saved, and saved-pending states plus the whitespace-only-draft edge case that should still resolve to `saved`. Co-authored-by: Nagendhra <nagendhra405@gmail.com>
This commit is contained in:
co-authored by
Nagendhra
parent
a383b4bd3a
commit
d4b547caa7
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
agentRefreshOptionsForConfig,
|
||||
canRunProviderConnectionTest,
|
||||
deriveComposioCredentialState,
|
||||
isValidApiBaseUrl,
|
||||
shouldShowCustomModelInput,
|
||||
switchApiProtocolConfig,
|
||||
@@ -326,3 +327,51 @@ describe('SettingsDialog agent CLI env settings', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('deriveComposioCredentialState', () => {
|
||||
// Issue #741: when a Composio API key is already saved and the user
|
||||
// starts typing a draft replacement, the saved-key indicator must
|
||||
// stay visible. The previous code conflated `saved + draft` with
|
||||
// `draft only` and made the badge vanish on the first keystroke.
|
||||
|
||||
it('returns "empty" when nothing is configured and the field is empty', () => {
|
||||
expect(deriveComposioCredentialState({})).toBe('empty');
|
||||
expect(deriveComposioCredentialState(null)).toBe('empty');
|
||||
expect(deriveComposioCredentialState(undefined)).toBe('empty');
|
||||
expect(deriveComposioCredentialState({ apiKey: '' })).toBe('empty');
|
||||
expect(deriveComposioCredentialState({ apiKey: ' ' })).toBe('empty');
|
||||
});
|
||||
|
||||
it('returns "saved" when a key is configured and no draft is being typed', () => {
|
||||
expect(
|
||||
deriveComposioCredentialState({ apiKeyConfigured: true }),
|
||||
).toBe('saved');
|
||||
expect(
|
||||
deriveComposioCredentialState({ apiKey: '', apiKeyConfigured: true }),
|
||||
).toBe('saved');
|
||||
expect(
|
||||
deriveComposioCredentialState({ apiKey: ' ', apiKeyConfigured: true }),
|
||||
).toBe('saved');
|
||||
});
|
||||
|
||||
it('returns "pending-new" when only a draft is being typed (no saved key)', () => {
|
||||
expect(deriveComposioCredentialState({ apiKey: 'sk-draft' })).toBe('pending-new');
|
||||
expect(
|
||||
deriveComposioCredentialState({ apiKey: 'sk-draft', apiKeyConfigured: false }),
|
||||
).toBe('pending-new');
|
||||
});
|
||||
|
||||
it('returns "saved-pending" when a key is saved AND a draft is being typed', () => {
|
||||
// Regression: this is the state that previously masqueraded as
|
||||
// "pending-new" and made the saved-key badge disappear.
|
||||
expect(
|
||||
deriveComposioCredentialState({ apiKey: 'sk-replacement', apiKeyConfigured: true }),
|
||||
).toBe('saved-pending');
|
||||
});
|
||||
|
||||
it('treats whitespace-only drafts as no draft so the badge is anchored on "saved"', () => {
|
||||
expect(
|
||||
deriveComposioCredentialState({ apiKey: ' \t\n', apiKeyConfigured: true }),
|
||||
).toBe('saved');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user