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(providers): preserve independent drafts when shared fields overlap

xda21ffcee6211
diff --git a/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx b/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
index a4c7592866..e828f9b251 100644
--- a/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
@@ -1610,7 +1610,7 @@ describe('identified provider handoff', () => {
it('returns shared URL/key edits without replacing an independent engine draft', async () => {
const onReturnCustom = vi.fn();
const shared = detected.config.runtimes.pi;
- const handoff = { ...detected, keys: { pi: 'fake-key', codex: 'fake-key', 'claude-code': 'independent-key' },
+ const handoff = { ...detected, preset: { ...detected.preset, runtimes: { ...detected.preset.runtimes, codex: { ...detected.preset.runtimes.pi, baseUrl: 'https://relay.example/codex/v1' } } }, keys: { pi: 'fake-key', codex: 'fake-key', 'claude-code': 'independent-key' },
config: { ...detected.config, runtimes: { pi: shared, codex: { ...shared },
'claude-code': { baseUrl: 'https://independent.example/anthropic', models: [{ id: 'own-model', name: 'Own' }] },
} },
@@ -1625,6 +1625,21 @@ describe('identified provider handoff', () => {
expect(returned.config.runtimes['claude-code']).toEqual(handoff.config.runtimes['claude-code']);
expect(returned.catalog).toBeUndefined();
});
+ it.each([true, false])('keeps an excluded runtime unchanged even when its key and address overlap: %s', async sameAddress => {
+ const own = { ...detected.config.runtimes.pi,
+ baseUrl: sameAddress ? detected.config.runtimes.pi.baseUrl : 'https://independent.example/v1',
+ requestPath: '/independent/messages',
+ };
+ const handoff = { ...detected, keys: { pi: 'fake-key', 'claude-code': 'fake-key' },
+ config: { ...detected.config, runtimes: { ...detected.config.runtimes, 'claude-code': own } } };
+ const onReturnCustom = vi.fn();
+ render(<AddProviderWizard providers={[]} detected={handoff} onReturnCustom={onReturnCustom} onClose={vi.fn()} onDone={vi.fn()} onOpenCustomForm={vi.fn()} />);
+ fireEvent.change(await screen.findByPlaceholderText('sk-…'), { target: { value: 'new-shared-key' } });
+ fireEvent.change(screen.getByDisplayValue(detected.config.runtimes.pi.baseUrl), { target: { value: 'https://new.example/v1' } });
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.wizard.back' }));
+ expect(onReturnCustom.mock.calls[0][0].keys['claude-code']).toBe('fake-key');
+ expect(onReturnCustom.mock.calls[0][0].config.runtimes['claude-code']).toEqual(own);
+ });
it('returns the draft instead of navigating to the provider gallery, keeping edited credentials', async () => {
const onReturnCustom = vi.fn();
render(<AddProviderWizard providers={[]} detected={detected} onReturnCustom={onReturnCustom} onClose={vi.fn()} onDone={vi.fn()} onOpenCustomForm={vi.fn()} />);
diff --git a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
index c5a1821bd8..2d6629d576 100644
--- a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
+++ b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
@@ -2236,6 +2236,8 @@ export function AddProviderWizard({
const original = runtimes[target]!;
const followsAddress = original.baseUrl === previous.baseUrl;
const bound = sel.preset.runtimes[target];
+ // Excluded engines are independent drafts, even if a field matches.
+ if (!bound) continue;
const targetInput = bound ? presetRuntimeBaseUrl(sel.preset, target, presetBaseUrls) : undefined;
const targetBase = targetInput && targetInput !== bound?.baseUrl ? targetInput
: followsAddress ? baseUrl : original.baseUrl;
diff --git a/apps/desktop/src/renderer/components/settings/ProviderConnectionDialog.tsx b/apps/desktop/src/renderer/components/settings/ProviderConnectionDialog.tsx
index 5fc53382cb..2ca441389c 100644
--- a/apps/desktop/src/renderer/components/settings/ProviderConnectionDialog.tsx
+++ b/apps/desktop/src/renderer/components/settings/ProviderConnectionDialog.tsx
@@ -757,7 +757,7 @@ export function ProviderConnectionDialog({
if (simpleAdding) {
const source = activeTab;
for (const agent of AGENTS) {
- if (agent === source) continue;
+ if (agent === source || !followsDefaultConnection(agent, prev[agent], prev[source])) continue;
const next = { ...updated[agent] };
for (const field of ['baseUrl', 'apiKey', 'headers', 'models'] as const) {
if (JSON.stringify(prev[agent][field]) === JSON.stringify(prev[source][field]) &&
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/CustomProviderDialogAccessibility.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/CustomProviderDialogAccessibility.test.tsx
index a2afd61e82..9eb50cfc33 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/CustomProviderDialogAccessibility.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/CustomProviderDialogAccessibility.test.tsx
@@ -2259,6 +2259,22 @@ describe('new-connection identification', () => {
expect(onDetected.mock.calls[0][0].config.runtimes.codex).toMatchObject(independent);
expect(onDetected.mock.calls[0][0].preset.runtimes.codex).toBeUndefined();
});
+ it.each([true, false])('does not sync shared edits to an independent runtime with overlapping fields: %s', async sameAddress => {
+ const own = { baseUrl: sameAddress ? 'https://api.deepseek.com' : 'https://independent.example/v1',
+ models: [{ id: 'one', name: 'One' }], requestPath: '/independent/messages' };
+ render(<ProviderConnectionDialog onDetected={vi.fn()} onClose={vi.fn()} onSaved={vi.fn()}
+ draft={{ preset, agent: 'pi', apiKey: 'fake-key', keys: { pi: 'fake-key', 'claude-code': 'fake-key' },
+ config: { id: 'draft', name: 'Draft', runtimes: {
+ pi: { baseUrl: 'https://api.deepseek.com', models: [{ id: 'one', name: 'One' }] }, 'claude-code': own,
+ } } }} />);
+ fireEvent.change(screen.getByPlaceholderText('settings.providers.custom.fields.apiKeyPlaceholder'), { target: { value: 'new-shared-key' } });
+ fireEvent.change(screen.getByPlaceholderText('settings.providers.custom.fields.baseUrlPlaceholder'), { target: { value: 'https://new.example/v1' } });
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.connection.saveProvider' }));
+ await act(async () => {});
+ const [config, keys] = customProviderMocks.createCustomProvider.mock.calls[0];
+ expect(keys['claude-code']).toBe('fake-key');
+ expect(config.runtimes['claude-code']).toMatchObject(own);
+ });
it('opens manual entry and focuses its error when saving without models', async () => {
await openIdentification();
fireEvent.click(screen.getByRole('button', { name: 'settings.providers.detection.keepCustom' }));