Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✅test: add search unit test cases for merging the user model with the base model (#9764)

bbbugg59ea77d74603
diff --git a/packages/database/src/repositories/aiInfra/index.test.ts b/packages/database/src/repositories/aiInfra/index.test.ts
index 2c3a380ac43..3174799380d 100644
--- a/packages/database/src/repositories/aiInfra/index.test.ts
+++ b/packages/database/src/repositories/aiInfra/index.test.ts
@@ -419,6 +419,318 @@ describe('AiInfraRepos', () => {
// For custom provider, when user enables search with no builtin settings, default to 'params'
expect(merged?.settings).toEqual({ searchImpl: 'params' });
});
+
+ // 测试场景:用户模型 abilitie 为空(Empty),而基础模型有搜索能力和设置
+ it('should retain builtin abilities and settings when user model has no abilities (empty) and builtin has settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: {}, // Empty object, no search
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: { search: false }, // 使用 builtin abilities
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin has settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // 使用 builtin abilities
+ expect(merged?.abilities?.search).toEqual(false);
+ // 删去 builtin settings
+ expect(merged?.settings).toBeUndefined();
+ });
+
+ it('should retain builtin abilities and settings when user model has no abilities (empty) and builtin has settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: {}, // Empty object, no search
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: { search: true }, // 使用 builtin abilities
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin has settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // 使用 builtin abilities
+ expect(merged?.abilities?.search).toEqual(true);
+ // 保留 builtin settings
+ expect(merged?.settings).toEqual({ searchImpl: 'params', searchProvider: 'google' });
+ });
+
+ // 测试场景:用户模型未启用搜索(abilities.search 为 undefined),而基础模型有搜索能力和设置
+ it('should retain builtin settings when user model has no abilities.search (undefined) and builtin has settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: { vision: true }, // 启用 vision 能力, no search
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: { search: false }, // builtin abilities 不生效
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin has settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // abilities.search 仍 undefined(兼容老版本)
+ expect(merged?.abilities?.search).toBeUndefined();
+ // 保留 builtin settings
+ expect(merged?.settings).toEqual({ searchImpl: 'params', searchProvider: 'google' });
+ });
+
+ it('should retain builtin settings when user model has no abilities.search (undefined) and builtin has settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: { vision: true }, // 启用 vision 能力, no search
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: { search: true }, // builtin abilities 不生效
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin has settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // abilities.search 仍 undefined(兼容老版本)
+ expect(merged?.abilities?.search).toBeUndefined();
+ // 保留 builtin settings
+ expect(merged?.settings).toEqual({ searchImpl: 'params', searchProvider: 'google' });
+ });
+
+ // 测试场景:用户模型未启用搜索(abilities.search 为 undefined),而基础模型也无搜索能力和设置
+ it('should retain no settings when user model has no abilities.search (undefined) and builtin has no settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: {}, // 无 search
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: {},
+ // builtin 无 settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities?.search).toBeUndefined();
+ // 无 settings
+ expect(merged?.settings).toBeUndefined();
+ });
+
+ // 测试:用户模型有 abilities.search: true
+ it('should inject defaults when user has search: true, no existing settings (builtin none)', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: { search: true }, // 用户启用 search
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: {},
+ // 无 settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toEqual({ search: true });
+ // 注入 defaults (openai: params)
+ expect(merged?.settings).toEqual({ searchImpl: 'params' });
+ });
+
+ it('should retain existing settings when user has search: true and builtin has settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: { search: true },
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ settings: { searchImpl: 'tool' }, // builtin 有 settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toEqual({ search: true });
+ // 使用 builtin settings
+ expect(merged?.settings).toEqual({ searchImpl: 'tool' });
+ });
+
+ // 测试:用户模型有 abilities.search: false
+ it('should remove settings when user has search: false and builtin has settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: { search: false }, // 用户禁用 search
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ settings: { searchImpl: 'tool', extendParams: [] }, // builtin 有 settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toEqual({ search: false });
+ // 移除 search 相关,保留其他
+ expect(merged?.settings).toEqual({ extendParams: [] });
+ });
+
+ it('should keep no settings when user has search: false and no existing settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ];
+
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: { search: false },
+ };
+
+ const builtinModel = {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ // 无 settings
+ };
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([builtinModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toEqual({ search: false });
+ // 无 settings
+ expect(merged?.settings).toBeUndefined();
+ });
});
describe('getAiProviderModelList', () => {
@@ -614,6 +926,350 @@ describe('AiInfraRepos', () => {
// For custom provider, when user enables search with no builtin settings, default to 'params'
expect(merged.settings).toEqual({ searchImpl: 'params' });
});
+
+ // 测试场景:用户模型 abilitie 为空(Empty),而基础模型有搜索能力和设置
+ it('should retain builtin abilities and settings when user model has no abilities (empty) and builtin has settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: {}, // Empty object, no search
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: false }, // 使用 builtin abilities
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin has settings
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // 使用 builtin abilities
+ expect(merged?.abilities?.search).toEqual(false);
+ // 保留 builtin settings
+ expect(merged?.settings).toBeUndefined();
+ });
+
+ it('should retain builtin abilities and settings when user model has no abilities (empty) and builtin has settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: {}, // Empty object, no search
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: true }, // 使用 builtin abilities
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin has settings
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // 使用 builtin abilities
+ expect(merged?.abilities?.search).toEqual(true);
+ // 保留 builtin settings
+ expect(merged?.settings).toEqual({ searchImpl: 'params', searchProvider: 'google' });
+ });
+
+ // 测试场景:用户模型未启用搜索(abilities.search 为 undefined),而基础模型有搜索能力和设置
+ it('should retain builtin settings when user model has no abilities (empty) and builtin has settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { vision: true }, // 启用 vision 能力, no search
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: false }, // builtin abilities 会被 merge
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin has settings
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // abilities.search 会被 merge 为 false,此处和 getEnabledAiModel 不同
+ expect(merged?.abilities?.search).toEqual(false);
+ // 删去 builtin settings
+ expect(merged?.settings).toBeUndefined();
+ });
+
+ it('should retain builtin settings when user model has no abilities (empty) and builtin has settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { vision: true }, // 启用 vision 能力, no search
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: true }, // builtin abilities 会被 merge
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin has settings
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // abilities.search 会被 merge 为 true,此处和 getEnabledAiModel 不同
+ expect(merged?.abilities?.search).toEqual(true);
+ // 保留 builtin settings
+ expect(merged?.settings).toEqual({ searchImpl: 'params', searchProvider: 'google' });
+ });
+
+ // 测试:用户模型无 abilities.search(undefined),保留 builtin settings(mergeArrayById 优先用户,但用户无则 builtin)
+ it('should retain builtin settings when user model has no abilities.search (undefined) and builtin has settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: {}, // 无 search
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: {},
+ settings: { searchImpl: 'params', searchProvider: 'google' }, // builtin 有
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities?.search).toBeUndefined();
+ // 保留 builtin settings
+ expect(merged?.settings).toEqual({ searchImpl: 'params', searchProvider: 'google' });
+ });
+
+ it('should retain no settings when user model has no abilities.search (undefined) and builtin has no settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: {}, // 无 search
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ // 无 settings
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities?.search).toBeUndefined();
+ // 无 settings
+ expect(merged?.settings).toBeUndefined();
+ });
+
+ // 测试:用户模型有 abilities.search: true
+ it('should inject defaults when user has search: true, no existing settings (builtin none)', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: true }, // 用户启用
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ // 无 settings
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toEqual({ search: true });
+ // 注入 defaults
+ expect(merged?.settings).toEqual({ searchImpl: 'params' });
+ });
+
+ it('should retain existing settings when user has search: true and builtin has settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: true },
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ settings: { searchImpl: 'tool' },
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toEqual({ search: true });
+ // 使用 builtin settings
+ expect(merged?.settings).toEqual({ searchImpl: 'tool' });
+ });
+
+ // 测试:用户模型有 abilities.search: false
+ it('should remove settings when user has search: false and builtin has settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: false }, // 用户禁用
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ settings: { searchImpl: 'tool', extendParams: [] },
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toEqual({ search: false });
+ // 移除 search 相关,保留其他
+ expect(merged?.settings).toEqual({ extendParams: [] });
+ });
+
+ it('should keep no settings when user has search: false and no existing settings', async () => {
+ const providerId = 'openai';
+
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: false },
+ },
+ ];
+
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ // 无 settings
+ },
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toEqual({ search: false });
+ // 无 settings
+ expect(merged?.settings).toBeUndefined();
+ });
});
describe('getAiProviderRuntimeState', () => {