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。

test(model-default): 补齐模型组 Auto 的正向、负向与回归用例

fmfsaisaid146b78ccdad
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts
index ad4b4f4e49..df0560564a 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts
@@ -58,6 +58,22 @@ describe('movedCindyAutoProviderId', () => {
expect(movedCindyAutoProviderId(movedToPool, route({ providerId: null, agentKind: 'codex' }))).toBeNull();
});
+ it('订阅等内置非 Cindy AI 来源上的 auto/... 不跟随', () => {
+ const subscription = [provider('openai', 'builtin', ['other']), provider('xd', 'builtin', [AUTO])];
+ expect(movedCindyAutoProviderId(subscription, route({ providerId: 'openai' }))).toBeNull();
+ });
+
+ it('Auto 从两份目录都消失时不登记切换,保留原路由交给既有的来源失效提示', () => {
+ const gone = [provider('xd', 'builtin', ['auto']), provider('org-pool', 'organization', ['pool-model'])];
+ expect(movedCindyAutoProviderId(gone, route())).toBeNull();
+ expect(movedCindyAutoProviderId(gone, route({ providerId: null }))).toBeNull();
+ });
+
+ it('回归:预设 auto 的任务不动', () => {
+ expect(movedCindyAutoProviderId(movedToPlatform, route({ model: 'auto', providerId: null }))).toBeNull();
+ expect(movedCindyAutoProviderId(movedToPlatform, route({ model: 'auto', providerId: 'xd' }))).toBeNull();
+ });
+
it('来源没变、普通模型、用户自己接的供应商都不动', () => {
expect(movedCindyAutoProviderId(movedToPlatform, route({ providerId: 'xd' }))).toBeNull();
expect(movedCindyAutoProviderId(movedToPlatform, route({ model: 'pool-model' }))).toBeNull();
diff --git a/apps/desktop/src/main/model-access/__tests__/byokProvider.test.ts b/apps/desktop/src/main/model-access/__tests__/byokProvider.test.ts
index 16a7b0fe08..6295b5430f 100644
--- a/apps/desktop/src/main/model-access/__tests__/byokProvider.test.ts
+++ b/apps/desktop/src/main/model-access/__tests__/byokProvider.test.ts
@@ -62,6 +62,34 @@ describe('buildByokProvider model types', () => {
]);
});
+ it('keeps a model-group Auto as the server named it, with its Pi default marker and Pi route', () => {
+ const groupAuto = {
+ id: 'auto/grp_123',
+ name: 'Auto (研发组)',
+ agents: ['pi'] as Array<'pi'>,
+ mode: 'chat' as const,
+ currency: 'CNY' as const,
+ newSessionDefault: ['pi'] as Array<'pi'>,
+ modalities: { input: ['text', 'image'], output: ['text'] },
+ perAgent: { pi: { wireProtocol: 'openai-responses' as const } },
+ };
+ const result = buildByokProvider({
+ provider: { id: 'byok-a', name: 'Enterprise', connectionRevision: 1, models: [groupAuto] },
+ credential,
+ });
+ expect(result.models.pi?.[0]).toMatchObject({
+ id: 'auto/grp_123',
+ name: 'Auto (研发组)',
+ newSessionDefault: ['pi'],
+ defaultEnabled: true,
+ piApi: 'openai-responses',
+ });
+ expect(byokNativeConfigs([result])[0]?.runtimes.pi?.models[0]).toMatchObject({
+ id: 'auto/grp_123',
+ name: 'Auto (研发组)',
+ });
+ });
+
it('can project an image-only enterprise Provider without chat engines', () => {
const result = buildByokProvider({
provider: { id: 'byok-a', name: 'Enterprise', connectionRevision: 1, models: [imageModel] },
diff --git a/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts b/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts
index d794a52a2d..c5a0eb713e 100644
--- a/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts
+++ b/apps/desktop/src/renderer/__tests__/draftModelCalibration.test.ts
@@ -986,6 +986,48 @@ describe('模型组 Auto:服务端决定默认与来源', () => {
.toEqual({ model: 'custom-model', providerId: 'custom-litellm' });
});
+ it('用户手动选过的模型不被服务端默认覆盖', () => {
+ const gateway = provider('xd', true, { pi: [model('auto'), groupAuto(true)] });
+ const byok = pool('org-pool', [model('pool-model')]);
+ const providers = [gateway, byok];
+ expect(calibrateDraftModel({ providers, agent: 'pi', model: 'pool-model', chosenByUser: true,
+ preferredProviderId: 'org-pool', providersLoading: false }))
+ .toEqual({ model: 'pool-model', providerId: null });
+ expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi',
+ draft: { model: 'pool-model', providerId: 'org-pool', chosenByUser: true } }))
+ .toEqual({ model: 'pool-model', providerId: 'org-pool' });
+ });
+
+ it('Auto 从两份目录都消失:不崩,落到记着的来源里仍可用的模型', () => {
+ const gateway = provider('xd', true, { pi: [model('z-ai/glm-5.3-flash')] });
+ const byok = pool('org-pool', [model('pool-model')]);
+ const providers = [gateway, byok];
+ for (const chosenByUser of [false, true]) {
+ expect(resolveNewTaskDefaultRoute({ providers, agent: 'pi',
+ draft: { model: 'auto/group-1', providerId: 'org-pool', chosenByUser } }))
+ .toEqual({ model: 'pool-model', providerId: 'org-pool' });
+ }
+ expect(calibrateDraftModel({ providers, agent: 'pi', model: 'auto/group-1', chosenByUser: false,
+ preferredProviderId: 'org-pool', providersLoading: false }))
+ .toEqual({ model: 'pool-model', providerId: 'org-pool' });
+ });
+
+ it('回归:订阅、自定义供应商、个人用户与预设 auto 的默认不变', () => {
+ // 个人用户:目录标的是 GLM,默认仍是预设 auto,来源 Cindy AI。
+ const personal = provider('xd', true, { pi: [model('z-ai/glm-5.3-flash', { newSessionDefault: ['pi'] }), model('auto')] });
+ expect(resolveNewTaskDefaultRoute({ providers: [personal], agent: 'pi' }))
+ .toEqual({ model: 'auto', providerId: 'xd' });
+ // 订阅:Codex 订阅在场时 Codex 默认仍是订阅里的 Sol,不受 Pi 侧 Auto 规则影响。
+ const openai = provider('openai', true, { codex: [model('gpt-6.1-sol')] }, 'subscription');
+ expect(resolveNewTaskDefaultRoute({ providers: [openai, personal], agent: 'codex' }))
+ .toEqual({ model: 'gpt-6.1-sol', providerId: 'openai' });
+ // 自定义供应商:记着的自定义来源与模型原样保留。
+ const custom = pool('custom-litellm', [model('custom-model')], 'user');
+ expect(resolveNewTaskDefaultRoute({ providers: [personal, custom], agent: 'pi',
+ draft: { model: 'custom-model', providerId: 'custom-litellm', chosenByUser: true } }))
+ .toEqual({ model: 'custom-model', providerId: 'custom-litellm' });
+ });
+
it('新建任务提交时,Auto 已挪走的旧来源换成解析出的新来源;其它显式来源原样提交', () => {
const gateway = provider('xd', true, { pi: [model('auto'), groupAuto(true)] });
const byok = pool('org-pool', [model('pool-model')]);
diff --git a/apps/desktop/src/renderer/lib/__tests__/newMakerDefaultTuple.test.ts b/apps/desktop/src/renderer/lib/__tests__/newMakerDefaultTuple.test.ts
index c46473dd3a..659a073f9e 100644
--- a/apps/desktop/src/renderer/lib/__tests__/newMakerDefaultTuple.test.ts
+++ b/apps/desktop/src/renderer/lib/__tests__/newMakerDefaultTuple.test.ts
@@ -394,6 +394,22 @@ describe('resolveNewMakerDefaultTuple', () => {
}
});
+ it('订阅等内置非 Cindy AI 来源里被标记的 auto/... 不当组 Auto', () => {
+ const gateway = provider({ id: 'xd', access: 'managed', models: { pi: [model('auto')] } });
+ // 订阅来源(内置、非 Cindy AI)里恰好有个被标记的 auto/...:不参与 Auto 规则。
+ const openai = provider({ id: 'openai', access: 'subscription', models: { pi: [groupAuto(['pi'])] } });
+ expect(resolve([openai, gateway], new Set(['pi']))).toMatchObject({ providerId: 'xd', model: 'auto' });
+ expect(resolve([openai], new Set(['pi']))).toBeNull();
+ });
+
+ it('Auto 从两份目录都消失:不编造默认,交给后续规则或既有空态', () => {
+ const gateway = provider({ id: 'xd', access: 'managed', models: { pi: [model('z-ai/glm-5.3-flash', 'high', ['pi'])] } });
+ const byok = pool('org-pool', [model('pool-model')]);
+ expect(resolve([gateway, byok])).toBeNull();
+ const xai = provider({ id: 'xai', access: 'subscription', models: { pi: [model('grok-4.6')] } });
+ expect(resolve([gateway, byok, xai])).toMatchObject({ providerId: 'xai', model: 'grok-4.6' });
+ });
+
it('个人订阅仍然优先', () => {
const openai = provider({ id: 'openai', access: 'subscription', models: { codex: [model('gpt-6.1-sol')] } });
const byok = pool('org-pool', [groupAuto(['pi'])]);
diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.ts
index f149c38139..b24d7d423a 100644
--- a/apps/mobile/src/__tests__/newSession.test.ts
+++ b/apps/mobile/src/__tests__/newSession.test.ts
@@ -939,6 +939,18 @@ describe('pickAgentDefaultRuntime', () => {
expect(
resolveRecentModelAndProvider(toPool, { model: auto, providerId: 'xd' }, 'pi', true),
).toEqual({ model: auto, providerId: 'org-pool' });
+ // 负向:用户自己接的供应商仍提供同名 auto/... 时原样保留,不被拉去 Cindy 来源。
+ expect(
+ resolveRecentModelAndProvider(toPlatform, { model: auto, providerId: 'custom' }, 'pi', true),
+ ).toEqual({ model: auto, providerId: 'custom' });
+ // 负向:Auto 从两份目录都消失时不崩,按既有规则落到目录首项。
+ const gone = [
+ autoRow('xd', 'builtin', ['auto'], 'auto'),
+ autoRow('org-pool', 'organization', ['pool-model'], 'pool-model'),
+ ];
+ expect(
+ resolveRecentModelAndProvider(gone, { model: auto, providerId: 'org-pool' }, 'pi', true),
+ ).toEqual({ model: 'auto', providerId: 'xd' });
});
});
diff --git a/packages/model-providers/src/__tests__/cindyAutoRelocation.test.ts b/packages/model-providers/src/__tests__/cindyAutoRelocation.test.ts
index 9877768ebc..50f464fb71 100644
--- a/packages/model-providers/src/__tests__/cindyAutoRelocation.test.ts
+++ b/packages/model-providers/src/__tests__/cindyAutoRelocation.test.ts
@@ -103,3 +103,30 @@ describe('movedCindyAutoSourceId:已保存 / 运行中的路由', () => {
expect(movedCindyAutoSourceId(toPool, { agent: 'codex', model: AUTO, providerId: null })).toBeNull();
});
});
+
+describe('负向与回归', () => {
+ it('订阅等内置非 Cindy AI 来源里的 auto/... 不当组 Auto:不从它挪走,也不挪到它', () => {
+ const fromSubscription = [provider('openai', 'builtin', ['other']), provider('xd', 'builtin', [AUTO])];
+ expect(effectiveSourceIdForModel(fromSubscription, 'openai', AUTO, 'pi')).toBeNull();
+ expect(movedCindyAutoSourceId(fromSubscription, { agent: 'pi', model: AUTO, providerId: 'openai' })).toBeNull();
+ const toSubscription = [provider('xd', 'builtin', ['auto']), provider('openai', 'builtin', [AUTO])];
+ expect(effectiveSourceIdForModel(toSubscription, 'xd', AUTO, 'pi')).toBeNull();
+ expect(movedCindyAutoSourceId(toSubscription, { agent: 'pi', model: AUTO, providerId: 'xd' })).toBeNull();
+ });
+
+ it('Auto 从两份目录都消失:不改道,按显式来源失效返回 null(由既有的来源失效提示接手)', () => {
+ const gone = [provider('xd', 'builtin', ['auto']), provider('org-pool', 'organization', ['pool-model'])];
+ expect(effectiveSourceIdForModel(gone, 'org-pool', AUTO, 'pi')).toBeNull();
+ expect(movedCindyAutoSourceId(gone, { agent: 'pi', model: AUTO, providerId: 'org-pool' })).toBeNull();
+ expect(movedCindyAutoSourceId(gone, { agent: 'pi', model: AUTO, providerId: null })).toBeNull();
+ });
+
+ it('回归:预设 auto 与普通模型的来源解析不变', () => {
+ const views = [provider('xd', 'builtin', ['auto', 'glm']), provider('custom', 'user', ['custom-model'])];
+ expect(effectiveSourceIdForModel(views, 'xd', 'auto', 'pi')).toBe('xd');
+ expect(effectiveSourceIdForModel(views, null, 'auto', 'pi')).toBe('xd');
+ expect(movedCindyAutoSourceId(views, { agent: 'pi', model: 'auto', providerId: null })).toBeNull();
+ expect(effectiveSourceIdForModel(views, 'custom', 'custom-model', 'pi')).toBe('custom');
+ expect(effectiveSourceIdForModel(views, 'custom', 'glm', 'pi')).toBeNull();
+ });
+});
diff --git a/packages/model-providers/src/__tests__/unifiedSelection.test.ts b/packages/model-providers/src/__tests__/unifiedSelection.test.ts
index 16841f4031..6b787f23ed 100644
--- a/packages/model-providers/src/__tests__/unifiedSelection.test.ts
+++ b/packages/model-providers/src/__tests__/unifiedSelection.test.ts
@@ -1233,6 +1233,16 @@ describe('unifiedModelEntries', () => {
expect(entries[0].group).toBe('anthropic');
expect(entries[0].sortOrder).toBe(3);
});
+
+ it('模型组 Auto 按服务端给的名称显示,行身份不剥 auto/', () => {
+ const named = { name: 'Auto (研发组)', mode: 'chat' as const };
+ const gateway = view({ id: 'xd', authStrategy: 'gateway-key', models: { pi: [m('auto/grp_123', named)] } });
+ const pool = view({ id: 'org-pool', source: 'organization', models: { pi: [m('auto/grp_456', { ...named, name: 'Auto (销售组)' })] } });
+ const entries = unifiedModelEntries({ providers: [gateway, pool], isVisible: alwaysVisible });
+ expect(find(entries, 'xd', 'auto/grp_123')?.displayName).toBe('Auto (研发组)');
+ expect(find(entries, 'org-pool', 'auto/grp_456')?.displayName).toBe('Auto (销售组)');
+ expect(unifiedModelKeyId('auto/grp_123')).toBe('auto/grp_123');
+ });
});
// ── 原生底座排序 ──────────────────────────────────────────────────────────────