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): 清理取消授权并统一订阅默认模型

Dash2ec4edcd1457
diff --git a/apps/desktop/src/main/maker-host/__tests__/activeCatalogDiscovery.test.ts b/apps/desktop/src/main/maker-host/__tests__/activeCatalogDiscovery.test.ts
index 0bcb821821..91c938f019 100644
--- a/apps/desktop/src/main/maker-host/__tests__/activeCatalogDiscovery.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/activeCatalogDiscovery.test.ts
@@ -89,6 +89,35 @@ function legacyCatalog(): Catalog {
}
describe('active-catalog discovered augment', () => {
+ it.each([
+ ['anthropic', 'claude', 'claude-sonnet-4-5', 'claude-sonnet-4-6'],
+ ['xai', 'xai', 'grok-4.5', 'grok-4.6'],
+ ] as const)('uses the same default selection for builtin and independent %s accounts', (id, native, oldId, newId) => {
+ const catalog = bundledWithoutRegistry();
+ const builtin = catalog.providers.find(provider => provider.id === id)!;
+ const models = [fake(oldId), fake(newId)].map(model => ({ ...model, group: id === 'anthropic' ? 'claude' : 'grok' }));
+ builtin.models = { codex: models, 'claude-code': models, pi: models };
+ const account = { ...builtin, id: `${id}-second`, source: 'user' as const,
+ auth: { method: 'oauth' as const, native } };
+ const api = { ...builtin, id: `${id}-api`, source: 'user' as const,
+ auth: { method: 'apiKey' as const } };
+ setActiveCatalog({ ...catalog, providers: [builtin, account, api] });
+ if (id === 'anthropic') setAnthropicDiscoveredModels(models);
+ const actual = getActiveCatalog();
+ for (const agent of ['codex', 'claude-code', 'pi'] as const) {
+ const listed = (providerId: string) => actual.providers.find(provider => provider.id === providerId)!.models[agent]!;
+ expect(listed(account.id).map(model => [model.id, model.defaultEnabled]))
+ .toEqual(listed(builtin.id).map(model => [model.id, model.defaultEnabled]));
+ for (const providerId of [builtin.id, account.id]) {
+ expect(listed(providerId).find(model => model.id === oldId)?.defaultEnabled,
+ `${providerId}/${agent}: ${listed(providerId).map(model => model.id).join(',')}`).toBe(false);
+ // Claude's Codex bridge is explicitly disabled by default; keep it disabled.
+ expect(listed(providerId).find(model => model.id === newId)?.defaultEnabled)
+ .toBe(!(id === 'anthropic' && agent === 'codex'));
+ }
+ expect(listed(api.id).find(model => model.id === oldId)?.defaultEnabled).toBe(true);
+ }
+ });
it('clears only the selected Grok account until the owner boundary is cleared', () => {
const account = buildUserProvider({
id: 'grok-second', name: 'Second Grok', auth: { method: 'oauth', native: 'xai' },
@@ -135,6 +164,7 @@ describe('active-catalog discovered augment', () => {
setActiveCatalog(BUNDLED_CATALOG);
clearDiscoveredProviderModels();
setDiscoveredCodexModels([]);
+ setAnthropicDiscoveredModels([]);
setXaiDiscoveredModels(null);
setDiscoveredProviderMediaModels('xai', null);
});
diff --git a/apps/desktop/src/main/maker-host/active-catalog.ts b/apps/desktop/src/main/maker-host/active-catalog.ts
index c360c87bdc..c56378cb48 100644
--- a/apps/desktop/src/main/maker-host/active-catalog.ts
+++ b/apps/desktop/src/main/maker-host/active-catalog.ts
@@ -1490,8 +1490,9 @@ function computeMerged(): Catalog {
// Subscription providers use the same small default selection, scoped per harness so
// chatgpt/ aliases never hide their sibling Codex route. Explicit user visibility stays external.
providers = providers.map((provider) => {
+ const catalogId = providerCatalogId(provider);
if (!isOpenAiSubscriptionProvider(provider) &&
- (provider.source === 'user' || !['anthropic', 'xai'].includes(provider.id)))
+ ((provider.source === 'user' && !provider.auth.native) || !['anthropic', 'xai'].includes(catalogId)))
return provider;
return {
...provider,
diff --git a/apps/desktop/src/renderer/__tests__/addProviderWizardOpenAiAuth.test.tsx b/apps/desktop/src/renderer/__tests__/addProviderWizardOpenAiAuth.test.tsx
index 54e33ae206..efb6123e86 100644
--- a/apps/desktop/src/renderer/__tests__/addProviderWizardOpenAiAuth.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/addProviderWizardOpenAiAuth.test.tsx
@@ -181,6 +181,45 @@ afterEach(() => {
});
describe('AddProviderWizard — OpenAI 授权边界', () => {
+ it.each(['openai', 'anthropic', 'xai'].flatMap(id =>
+ ['cancel', 'unmount'].map(exit => ({ id, exit })),
+ ))('removes $id when login succeeds after $exit', async ({ id, exit }) => {
+ let finish!: (value: { ok: boolean }) => void;
+ providerOAuthLogin.mockReturnValue(new Promise(resolve => { finish = resolve; }));
+ const onDone = vi.fn();
+ const { unmount } = render(<AddProviderWizard providers={[{ ...OPENAI_PROVIDER, id, name: id }]}
+ entry={{ kind: 'builtin', providerId: id }} onOpenCustomForm={vi.fn()} onClose={vi.fn()} onDone={onDone} />);
+ fireEvent.click(screen.getByText(id === 'openai'
+ ? 'settings.providers.openai.addIndependentAccount'
+ : 'settings.providers.button.authorize'));
+ await waitFor(() => expect(providerOAuthLogin).toHaveBeenCalledTimes(1));
+ const [accountId, options] = providerOAuthLogin.mock.calls[0];
+ if (exit === 'unmount') unmount();
+ else fireEvent.click(screen.getByText('settings.providers.wizard.cancel'));
+ expect(providerOAuthCancel).toHaveBeenCalledWith(accountId, { ownerId: options.ownerId, releaseOwner: true });
+ await act(async () => { finish({ ok: true }); });
+ expect(deleteAccount).toHaveBeenCalledExactlyOnceWith(accountId);
+ expect(onDone).not.toHaveBeenCalled();
+ });
+ it('keeps the retry account when the cancelled login succeeds later', async () => {
+ let finishOld!: (value: { ok: boolean }) => void;
+ providerOAuthLogin.mockReturnValueOnce(new Promise(resolve => { finishOld = resolve; }));
+ const onDone = vi.fn();
+ render(<AddProviderWizard providers={[OPENAI_PROVIDER]}
+ entry={{ kind: 'builtin', providerId: 'openai' }} onOpenCustomForm={vi.fn()} onClose={vi.fn()} onDone={onDone} />);
+ fireEvent.click(screen.getByText('settings.providers.openai.addIndependentAccount'));
+ await waitFor(() => expect(providerOAuthLogin).toHaveBeenCalledTimes(1));
+ const oldId = providerOAuthLogin.mock.calls[0][0];
+ fireEvent.click(screen.getByText('settings.providers.wizard.cancel'));
+ fireEvent.click(screen.getByText('settings.providers.openai.addIndependentAccount'));
+ await waitFor(() => expect(onDone).toHaveBeenCalledTimes(1));
+ const newId = providerOAuthLogin.mock.calls[1][0];
+ expect(newId).not.toBe(oldId);
+ expect(onDone).toHaveBeenCalledWith(newId);
+ await act(async () => { finishOld({ ok: true }); });
+ expect(deleteAccount).toHaveBeenCalledExactlyOnceWith(oldId);
+ expect(onDone).toHaveBeenCalledTimes(1);
+ });
it.each(['anthropic', 'xai'])('cancels only the pending independent %s authorization', async id => {
let finish!: (value: { ok: boolean; reason: string }) => void;
providerOAuthLogin.mockReturnValue(new Promise(resolve => { finish = resolve; }));
diff --git a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
index 9e2c7fd14c..77814592a5 100644
--- a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
+++ b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
@@ -717,8 +717,10 @@ export function AddProviderWizard({
created = true;
if (accountLoginRef.current !== login) return;
const result = await window.electronAPI.maker.providerOAuthLogin(id, { ownerId: login.ownerId });
- ok = result.ok;
if (accountLoginRef.current !== login || result.reason === 'login_cancelled') return;
+ // A late success belongs to a cancelled wizard until ownership is checked.
+ // Keep ok false so finally also removes credentials committed before cancellation.
+ ok = result.ok;
} finally {
if (accountLoginRef.current === login) accountLoginRef.current = null;
if (created && !ok) await deleteCustomProvider(id);