From b0e9796acbbb67693f322f433dbae9b688de0b30 Mon Sep 17 00:00:00 2001 From: wangdl Date: Thu, 18 Jun 2026 11:47:59 +0800 Subject: [PATCH] fix: use ConfigService for DeepSeek base URL in testCredential - Replace hardcoded 'https://api.deepseek.com/v1/models' with config lookup - Single source of truth via ai.deepseek.baseUrl (DEEPSEEK_BASE_URL env) - Add ConfigService dep to UserAiService constructor + test mock Co-Authored-By: Claude Opus 4.7 --- src/modules/ai-runtime/user-ai.service.spec.ts | 2 ++ src/modules/ai-runtime/user-ai.service.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/ai-runtime/user-ai.service.spec.ts b/src/modules/ai-runtime/user-ai.service.spec.ts index 25db00a..c3c85a6 100644 --- a/src/modules/ai-runtime/user-ai.service.spec.ts +++ b/src/modules/ai-runtime/user-ai.service.spec.ts @@ -1,4 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; +import { ConfigService } from '@nestjs/config'; import { BadRequestException, NotFoundException } from '@nestjs/common'; import { UserAiService } from './user-ai.service'; import { PrismaService } from '../../infrastructure/database/prisma.service'; @@ -42,6 +43,7 @@ describe('UserAiService.createAnalysisJob', () => { { provide: PriorityRulesService, useValue: priorityRules }, { provide: UserAiQuotaService, useValue: quota }, { provide: PlatformBudgetService, useValue: budget }, + { provide: ConfigService, useValue: { get: jest.fn().mockReturnValue('https://api.deepseek.com') } }, ], }).compile(); diff --git a/src/modules/ai-runtime/user-ai.service.ts b/src/modules/ai-runtime/user-ai.service.ts index afc8f61..f2f8590 100644 --- a/src/modules/ai-runtime/user-ai.service.ts +++ b/src/modules/ai-runtime/user-ai.service.ts @@ -1,4 +1,5 @@ import { Injectable, NotFoundException, BadRequestException } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { PrismaService } from '../../infrastructure/database/prisma.service'; import { CredentialEncryptionService } from './credential-encryption.service'; import { SnapshotBuilderService } from './snapshot-builder.service'; @@ -24,6 +25,7 @@ export class UserAiService { private readonly priorityRules: PriorityRulesService, private readonly quota: UserAiQuotaService, private readonly budget: PlatformBudgetService, + private readonly config: ConfigService, ) {} // ══ LearningProfile ══ @@ -143,7 +145,8 @@ export class UserAiService { } try { - const res = await fetch('https://api.deepseek.com/v1/models', { + const baseUrl = this.config.get('ai.deepseek.baseUrl', 'https://api.deepseek.com'); + const res = await fetch(`${baseUrl}/v1/models`, { headers: { Authorization: `Bearer ${decryptedKey}` }, signal: AbortSignal.timeout(10000), });