🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🌐 chore: translate non-English comments to English in lambda-router-tests (#13838)
LobeHub Bot3bb4fd604679
diff --git a/src/server/routers/lambda/__tests__/aiAgent.test.ts b/src/server/routers/lambda/__tests__/aiAgent.test.tsindex 61033a42532..6e12bb4042e 100644--- a/src/server/routers/lambda/__tests__/aiAgent.test.ts+++ b/src/server/routers/lambda/__tests__/aiAgent.test.ts@@ -76,12 +76,12 @@ vi.mock('model-bank', async (importOriginal) => {});/**- * AI Agent Router 集成测试+ * AI Agent Router Integration Tests*- * 测试目标:- * 1. 验证 execAgent 的业务逻辑- * 2. 确保 topic 创建逻辑正确- * 3. 验证与数据库的交互+ * Test objectives:+ * 1. Verify the business logic of execAgent+ * 2. Ensure topic creation logic is correct+ * 3. Verify interactions with the database*/describe('AI Agent Router Integration Tests', () => {let serverDB: LobeChatDatabase;@@ -94,7 +94,7 @@ describe('AI Agent Router Integration Tests', () => {testDB = serverDB;userId = await createTestUser(serverDB);- // 创建测试 agent+ // Create test agentconst [agent] = await serverDB.insert(agents).values({@@ -107,11 +107,11 @@ describe('AI Agent Router Integration Tests', () => {.returning();testAgentId = agent.id;- // 创建测试 session+ // Create test sessionconst [session] = await serverDB.insert(sessions).values({ userId, type: 'agent' }).returning();testSessionId = session.id;- // 创建 agent 到 session 的映射关系+ // Create agent-to-session mappingawait serverDB.insert(agentsToSessions).values({agentId: testAgentId,sessionId: testSessionId,diff --git a/src/server/routers/lambda/__tests__/generationBatch.test.ts b/src/server/routers/lambda/__tests__/generationBatch.test.tsindex 1a00f3e0e6d..6a658f7a820 100644--- a/src/server/routers/lambda/__tests__/generationBatch.test.ts+++ b/src/server/routers/lambda/__tests__/generationBatch.test.ts@@ -76,7 +76,7 @@ describe('generationBatchRouter', () => {const mockDelete = vi.fn().mockResolvedValue({deletedBatch: mockDeletedBatch,- filesToDelete: [], // 没有缩略图+ filesToDelete: [], // no thumbnails});const mockDeleteFiles = vi.fn();@@ -99,7 +99,7 @@ describe('generationBatchRouter', () => {expect(result).toEqual(mockDeletedBatch);expect(mockDelete).toHaveBeenCalledWith(mockBatchId);- expect(mockDeleteFiles).not.toHaveBeenCalled(); // 没有文件要删除+ expect(mockDeleteFiles).not.toHaveBeenCalled(); // no files to delete});it('should delete generation batch with thumbnails', async () => {@@ -231,12 +231,12 @@ describe('generationBatchRouter', () => {expect(result).toBeUndefined();expect(mockDelete).toHaveBeenCalledWith(mockBatchId);- expect(mockDeleteFiles).not.toHaveBeenCalled(); // 没有文件要删除+ expect(mockDeleteFiles).not.toHaveBeenCalled(); // no files to delete});it('should handle large number of thumbnails deletion', async () => {const mockBatchId = 'batch-with-many-thumbnails';- // 模拟包含大量缩略图的批次+ // Simulate a batch with many thumbnailsconst mockThumbnailUrls = Array.from({ length: 50 }, (_, i) => `thumb${i + 1}.jpg`);const mockDeletedBatch: GenerationBatchItem = {id: mockBatchId,diff --git a/src/server/routers/lambda/__tests__/generationTopic.test.ts b/src/server/routers/lambda/__tests__/generationTopic.test.tsindex 21f9277d719..f7ea6fa555a 100644--- a/src/server/routers/lambda/__tests__/generationTopic.test.ts+++ b/src/server/routers/lambda/__tests__/generationTopic.test.ts@@ -174,10 +174,10 @@ describe('generationTopicRouter', () => {updatedAt: new Date(),};- // 修复 Mock 返回结构以匹配新的实现+ // Fix Mock return structure to match the new implementationconst mockDelete = vi.fn().mockResolvedValue({deletedTopic: mockDeletedTopic,- filesToDelete: [], // 没有封面时,文件列表为空+ filesToDelete: [], // No cover, so the file list is empty});const mockDeleteFiles = vi.fn();@@ -200,7 +200,7 @@ describe('generationTopicRouter', () => {expect(result).toEqual(mockDeletedTopic);expect(mockDelete).toHaveBeenCalledWith(mockTopicId);- expect(mockDeleteFiles).not.toHaveBeenCalled(); // 没有文件要删除+ expect(mockDeleteFiles).not.toHaveBeenCalled(); // no files to delete});it('should delete a topic with cover and remove the cover file', async () => {@@ -216,10 +216,10 @@ describe('generationTopicRouter', () => {updatedAt: new Date(),};- // 修复 Mock 返回结构以匹配新的实现+ // Fix Mock return structure to match the new implementationconst mockDelete = vi.fn().mockResolvedValue({deletedTopic: mockDeletedTopic,- filesToDelete: [mockCoverUrl], // 包含需要删除的封面文件+ filesToDelete: [mockCoverUrl], // includes the cover file to delete});const mockDeleteFiles = vi.fn().mockResolvedValue(true);@@ -242,7 +242,7 @@ describe('generationTopicRouter', () => {expect(result).toEqual(mockDeletedTopic);expect(mockDelete).toHaveBeenCalledWith(mockTopicId);- expect(mockDeleteFiles).toHaveBeenCalledWith([mockCoverUrl]); // 验证文件删除调用+ expect(mockDeleteFiles).toHaveBeenCalledWith([mockCoverUrl]); // verify file deletion was called});it('should still return deleted topic when file deletion fails', async () => {@@ -309,7 +309,7 @@ describe('generationTopicRouter', () => {const mockDelete = vi.fn().mockResolvedValue({deletedTopic: mockDeletedTopic,- filesToDelete: [mockCoverUrl, ...mockThumbnailUrls], // 包含封面和缩略图+ filesToDelete: [mockCoverUrl, ...mockThumbnailUrls], // includes cover and thumbnails});const mockDeleteFiles = vi.fn().mockResolvedValue(true);@@ -414,7 +414,7 @@ describe('generationTopicRouter', () => {expect(result).toBeUndefined();expect(mockDelete).toHaveBeenCalledWith(mockTopicId);- expect(mockDeleteFiles).not.toHaveBeenCalled(); // 没有文件要删除+ expect(mockDeleteFiles).not.toHaveBeenCalled(); // no files to delete});it('should handle edge cases for update with partial data', async () => {diff --git a/src/server/routers/lambda/__tests__/integration/agentEval.integration.test.ts b/src/server/routers/lambda/__tests__/integration/agentEval.integration.test.tsindex 829cb12ddff..1c0f845d75d 100644--- a/src/server/routers/lambda/__tests__/integration/agentEval.integration.test.ts+++ b/src/server/routers/lambda/__tests__/integration/agentEval.integration.test.ts@@ -32,13 +32,13 @@ vi.mock('@/database/core/db-adaptor', () => ({}));/**- * Agent Eval Router 集成测试+ * Agent Eval Router Integration Tests*- * 测试目标:- * 1. 验证完整的 tRPC 调用链路(Router → Model → Database)- * 2. 验证所有 CRUD 操作- * 3. 验证错误处理(重复标识符、外键约束等)- * 4. 验证权限和数据隔离(用户只能操作自己的数据)+ * Test objectives:+ * 1. Verify the complete tRPC call chain (Router → Model → Database)+ * 2. Verify all CRUD operations+ * 3. Verify error handling (duplicate identifiers, FK constraints, etc.)+ * 4. Verify permissions and data isolation (users can only operate on their own data)*/describe('Agent Eval Router Integration Tests', () => {let serverDB: LobeChatDatabase;diff --git a/src/server/routers/lambda/__tests__/integration/message.integration.test.ts b/src/server/routers/lambda/__tests__/integration/message.integration.test.tsindex f6e93b7e985..ad97757367e 100644--- a/src/server/routers/lambda/__tests__/integration/message.integration.test.ts+++ b/src/server/routers/lambda/__tests__/integration/message.integration.test.ts@@ -24,12 +24,12 @@ vi.mock('@/database/core/db-adaptor', () => ({}));/**- * Message Router 集成测试+ * Message Router Integration Tests*- * 测试目标:- * 1. 验证完整的 tRPC 调用链路(Router → Model → Database)- * 2. 确保 sessionId、topicId、groupId 等参数正确传递- * 3. 验证数据库约束和关联关系+ * Test objectives:+ * 1. Verify the complete tRPC call chain (Router → Model → Database)+ * 2. Ensure sessionId, topicId, groupId and other parameters are passed correctly+ * 3. Verify database constraints and associations*/describe('Message Router Integration Tests', () => {let serverDB: LobeChatDatabase;@@ -43,7 +43,7 @@ describe('Message Router Integration Tests', () => {testDB = serverDB; // Set the test DB for the mockuserId = await createTestUser(serverDB);- // 创建测试 agent+ // Create test agentconst { agents } = await import('@/database/schemas');const [agent] = await serverDB.insert(agents)@@ -54,7 +54,7 @@ describe('Message Router Integration Tests', () => {.returning();testAgentId = agent.id;- // 创建测试 session+ // Create test sessionconst [session] = await serverDB.insert(sessions).values({@@ -64,7 +64,7 @@ describe('Message Router Integration Tests', () => {.returning();testSessionId = session.id;- // 创建 agent 到 session 的映射关系+ // Create agent-to-session mappingconst { agentsToSessions } = await import('@/database/schemas');await serverDB.insert(agentsToSessions).values({agentId: testAgentId,@@ -72,7 +72,7 @@ describe('Message Router Integration Tests', () => {userId,});- // 创建测试 topic+ // Create test topicconst [topic] = await serverDB.insert(topics).values({@@ -99,7 +99,7 @@ describe('Message Router Integration Tests', () => {topicId: testTopicId,});- // 🔥 关键:从数据库验证关联关系+ // 🔥 Key: verify associations from databaseconst [createdMessage] = await serverDB.select().from(messages)@@ -108,7 +108,7 @@ describe('Message Router Integration Tests', () => {expect(createdMessage).toBeDefined();expect(createdMessage).toMatchObject({id: result.id,- agentId: testAgentId, // sessionId 会解析为 agentId 存储+ agentId: testAgentId, // sessionId resolves to agentId for storagetopicId: testTopicId,userId,content: 'Test message',@@ -119,7 +119,7 @@ describe('Message Router Integration Tests', () => {it('should create message with threadId', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 先创建 thread+ // First create a threadconst { threads } = await import('@/database/schemas');const [thread] = (await serverDB.insert(threads)@@ -139,7 +139,7 @@ describe('Message Router Integration Tests', () => {threadId: thread.id,});- // 验证 threadId 正确存储+ // Verify threadId is correctly storedconst [createdMessage] = await serverDB.select().from(messages)@@ -164,7 +164,7 @@ describe('Message Router Integration Tests', () => {content: 'Test message without topic',role: 'user',sessionId: testSessionId,- // 注意:没有 topicId+ // Note: no topicId});const [createdMessage] = await serverDB@@ -190,7 +190,7 @@ describe('Message Router Integration Tests', () => {it.skip('should fail when topicId does not belong to sessionId', async () => {// TODO: This validation is not currently enforced in the code- // 创建另一个 session 和 topic+ // Create another session and topicconst [anotherSession] = await serverDB.insert(sessions).values({@@ -210,23 +210,23 @@ describe('Message Router Integration Tests', () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 尝试在 testSessionId 下创建消息,但使用 anotherTopic 的 ID+ // Attempt to create a message under testSessionId but using anotherTopic's IDawait expect(caller.createMessage({content: 'Test message',role: 'user',sessionId: testSessionId,- topicId: anotherTopic.id, // 这个 topic 不属于 testSessionId+ topicId: anotherTopic.id, // This topic does not belong to testSessionId}),).rejects.toThrow();});});/**- * agentId 兼容性测试+ * agentId compatibility tests*- * 测试 agentId → sessionId 解析功能- * 确保可以使用 agentId 替代 sessionId 进行操作+ * Tests the agentId → sessionId resolution feature+ * Ensures agentId can be used in place of sessionId for operations*/describe('agentId compatibility', () => {describe('createMessage with agentId', () => {@@ -237,10 +237,10 @@ describe('Message Router Integration Tests', () => {content: 'Message created with agentId',role: 'user',agentId: testAgentId,- // 不提供 sessionId,只使用 agentId+ // Do not provide sessionId, use only agentId});- // 验证消息创建成功,且关联到正确的 sessionId+ // Verify message was created successfully and linked to the correct sessionIdconst [createdMessage] = await serverDB.select().from(messages)@@ -273,7 +273,7 @@ describe('Message Router Integration Tests', () => {it('should prefer agentId over sessionId when both provided', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建另一个 session(不关联到 agent)+ // Create another session (not linked to an agent)const [anotherSession] = await serverDB.insert(sessions).values({@@ -286,7 +286,7 @@ describe('Message Router Integration Tests', () => {content: 'Message with both agentId and sessionId',role: 'user',agentId: testAgentId,- sessionId: anotherSession.id, // 这个会被 agentId 覆盖+ sessionId: anotherSession.id, // This will be overridden by agentId});const [createdMessage] = await serverDB@@ -294,14 +294,14 @@ describe('Message Router Integration Tests', () => {.from(messages).where(eq(messages.id, result.id));- // 应该使用提供的 agentId+ // Should use the provided agentIdexpect(createdMessage.agentId).toBe(testAgentId);});it('should fail when agentId does not exist due to FK constraint', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 当 agentId 不存在时,应该因为外键约束而失败+ // When agentId doesn't exist, should fail due to FK constraintawait expect(caller.createMessage({content: 'Message with non-existent agentId',@@ -316,7 +316,7 @@ describe('Message Router Integration Tests', () => {it('should remove message using agentId and return updated list', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建两条消息+ // Create two messagesconst msg1 = await caller.createMessage({content: 'Message 1',role: 'user',@@ -329,7 +329,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 使用 agentId 删除消息+ // Delete message using agentIdconst result = await caller.removeMessage({id: msg1.id,agentId: testAgentId,@@ -417,7 +417,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 使用 agentId 删除 session 中的所有消息+ // Delete all messages in the session using agentIdawait caller.removeMessagesByAssistant({agentId: testAgentId,});@@ -433,7 +433,7 @@ describe('Message Router Integration Tests', () => {it('should remove messages in specific topic using agentId', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 在 topic 中创建消息+ // Create a message in the topicawait caller.createMessage({content: 'Message in topic',role: 'user',@@ -441,14 +441,14 @@ describe('Message Router Integration Tests', () => {topicId: testTopicId,});- // 在 session 中创建消息(不在 topic 中)+ // Create a message in the session (outside the topic)const msgOutside = await caller.createMessage({content: 'Message outside topic',role: 'user',sessionId: testSessionId,});- // 使用 agentId 和 topicId 删除+ // Delete using agentId and topicIdawait caller.removeMessagesByAssistant({agentId: testAgentId,topicId: testTopicId,@@ -474,7 +474,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 创建 plugin 记录+ // Create plugin recordconst { messagePlugins } = await import('@/database/schemas');await serverDB.insert(messagePlugins).values({id: msg.id,@@ -518,7 +518,7 @@ describe('Message Router Integration Tests', () => {it('should return messages filtered by sessionId', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建多个消息+ // Create multiple messagesconst msg1Result = await caller.createMessage({content: 'Message 1',role: 'user',@@ -531,7 +531,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 创建另一个 session 的消息+ // Create messages for another sessionconst [anotherSession] = await serverDB.insert(sessions).values({@@ -546,7 +546,7 @@ describe('Message Router Integration Tests', () => {sessionId: anotherSession.id,});- // 查询特定 session 的消息+ // Query messages for a specific sessionconst result = await caller.getMessages({sessionId: testSessionId,});@@ -559,7 +559,7 @@ describe('Message Router Integration Tests', () => {it('should return messages filtered by topicId', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 在 topic 中创建消息+ // Create a message in the topicconst msgInTopicResult = await caller.createMessage({content: 'Message in topic',role: 'user',@@ -567,14 +567,14 @@ describe('Message Router Integration Tests', () => {topicId: testTopicId,});- // 在 session 中创建消息(不在 topic 中)+ // Create a message in the session (outside the topic)await caller.createMessage({content: 'Message without topic',role: 'user',sessionId: testSessionId,});- // 查询特定 topic 的消息+ // Query messages for a specific topicconst result = await caller.getMessages({sessionId: testSessionId,topicId: testTopicId,@@ -588,7 +588,7 @@ describe('Message Router Integration Tests', () => {it('should support pagination', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建多个消息+ // Create multiple messagesfor (let i = 0; i < 5; i++) {await caller.createMessage({content: `Pagination test message ${i}`,@@ -597,13 +597,13 @@ describe('Message Router Integration Tests', () => {});}- // 获取所有消息确认创建成功+ // Retrieve all messages to confirm creation succeededconst allMessages = await caller.getMessages({sessionId: testSessionId,});expect(allMessages.length).toBeGreaterThanOrEqual(5);- // 第一页+ // First pageconst page1 = await caller.getMessages({sessionId: testSessionId,current: 1,@@ -612,7 +612,7 @@ describe('Message Router Integration Tests', () => {expect(page1.length).toBeLessThanOrEqual(2);- // 第二页+ // Second pageconst page2 = await caller.getMessages({sessionId: testSessionId,current: 2,@@ -621,7 +621,7 @@ describe('Message Router Integration Tests', () => {expect(page2.length).toBeLessThanOrEqual(2);- // 确保不同页的消息不重复(如果两页都有数据)+ // Ensure messages from different pages do not overlap (if both pages have data)if (page1.length > 0 && page2.length > 0) {const page1Ids = page1.map((m) => m.id);const page2Ids = page2.map((m) => m.id);@@ -632,7 +632,7 @@ describe('Message Router Integration Tests', () => {it('should return messages filtered by groupId', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 首先创建一个 chat_group+ // First create a chat groupconst { chatGroups } = await import('@/database/schemas');const [chatGroup] = await serverDB.insert(chatGroups)@@ -642,7 +642,7 @@ describe('Message Router Integration Tests', () => {}).returning();- // 创建消息并设置 groupId+ // Create a message and set groupIdconst msg1 = await caller.createMessage({content: 'Message 1 in group',role: 'assistant',@@ -654,14 +654,14 @@ describe('Message Router Integration Tests', () => {.set({ groupId: chatGroup.id }).where(eq(messages.id, msg1.id));- // 创建不在 group 中的消息+ // Create a message not in the groupawait caller.createMessage({content: 'Message without group',role: 'user',sessionId: testSessionId,});- // 查询 group 中的消息+ // Query messages in the groupconst result = await caller.getMessages({sessionId: testSessionId,groupId: chatGroup.id,@@ -676,7 +676,7 @@ describe('Message Router Integration Tests', () => {it('should remove multiple messages', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建消息+ // Create messagesconst msg1Result = await caller.createMessage({content: 'Message 1',role: 'user',@@ -689,10 +689,10 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 删除消息+ // Delete messagesawait caller.removeMessages({ ids: [msg1Result.id, msg2Result.id] });- // 验证消息已删除+ // Verify messages were deletedconst remainingMessages = await serverDB.select().from(messages)@@ -704,7 +704,7 @@ describe('Message Router Integration Tests', () => {it('should return message list when sessionId is provided', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建消息+ // Create messagesconst msg1Result = await caller.createMessage({content: 'Message 1',role: 'user',@@ -723,7 +723,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 删除消息并返回列表+ // Delete messages and return the listconst result = await caller.removeMessages({ids: [msg1Result.id],sessionId: testSessionId,@@ -749,7 +749,7 @@ describe('Message Router Integration Tests', () => {await caller.removeMessage({ id: msgResult.id });- // 验证消息已删除+ // Verify messages were deletedconst deletedMessage = await serverDB.select().from(messages)@@ -789,7 +789,7 @@ describe('Message Router Integration Tests', () => {it('should remove all messages for the user', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建多个 session 和消息+ // Create multiple sessions and messagesawait caller.createMessage({content: 'Message 1',role: 'user',@@ -810,10 +810,10 @@ describe('Message Router Integration Tests', () => {sessionId: anotherSession.id,});- // 删除所有消息+ // Delete all messagesawait caller.removeAllMessages();- // 验证所有消息已删除+ // Verify all messages were deletedconst remainingMessages = await serverDB.select().from(messages)@@ -833,7 +833,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 创建一个 message query 记录,使用 UUID+ // Create a message query record using UUIDconst { messageQueries } = await import('@/database/schemas');const [queryRecord] = await serverDB.insert(messageQueries)@@ -846,7 +846,7 @@ describe('Message Router Integration Tests', () => {await caller.removeMessageQuery({ id: queryRecord.id });- // 验证消息查询已删除+ // Verify message query was deletedconst deletedQuery = await serverDB.select().from(messageQueries)@@ -860,7 +860,7 @@ describe('Message Router Integration Tests', () => {it('should remove all messages in a session', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建多个消息+ // Create multiple messagesawait caller.createMessage({content: 'Message 1',role: 'user',@@ -873,12 +873,12 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 删除 session 中的所有消息+ // Delete all messages in the sessionawait caller.removeMessagesByAssistant({sessionId: testSessionId,});- // 验证消息已删除+ // Verify messages were deletedconst remainingMessages = await serverDB.select().from(messages)@@ -890,7 +890,7 @@ describe('Message Router Integration Tests', () => {it('should remove messages in a specific topic', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 在 topic 中创建消息+ // Create a message in the topicawait caller.createMessage({content: 'Message in topic',role: 'user',@@ -898,20 +898,20 @@ describe('Message Router Integration Tests', () => {topicId: testTopicId,});- // 在 session 中创建消息(不在 topic 中)+ // Create a message in the session (outside the topic)const msgOutsideTopicResult = await caller.createMessage({content: 'Message outside topic',role: 'user',sessionId: testSessionId,});- // 删除 topic 中的消息+ // Delete messages in the topicawait caller.removeMessagesByAssistant({sessionId: testSessionId,topicId: testTopicId,});- // 验证 topic 中的消息已删除,但其他消息仍存在+ // Verify messages in the topic were deleted but other messages still existconst remainingMessages = await serverDB.select().from(messages)@@ -926,7 +926,7 @@ describe('Message Router Integration Tests', () => {it('should call removeMessagesByGroup endpoint', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 首先创建一个 chat_group+ // First create a chat groupconst { chatGroups } = await import('@/database/schemas');const [chatGroup] = await serverDB.insert(chatGroups)@@ -936,7 +936,7 @@ describe('Message Router Integration Tests', () => {}).returning();- // 创建消息并设置 groupId+ // Create a message and set groupIdconst msg1 = await caller.createMessage({content: 'Message 1 in group',role: 'assistant',@@ -949,7 +949,7 @@ describe('Message Router Integration Tests', () => {.set({ groupId: chatGroup.id }).where(eq(messages.id, msg1.id));- // 调用删除接口(不会抛出错误即为成功)+ // Call the delete endpoint (success means no error thrown)await expect(caller.removeMessagesByGroup({groupId: chatGroup.id,@@ -1051,7 +1051,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 先创建一个 plugin 记录+ // First create a plugin recordconst { messagePlugins } = await import('@/database/schemas');await serverDB.insert(messagePlugins).values({id: msg.id,@@ -1087,10 +1087,10 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 创建必要的依赖: chunks -> messageQueries -> messageQueryChunks+ // Create required dependencies: chunks -> messageQueries -> messageQueryChunksconst { chunks, messageQueries, messageQueryChunks } = await import('@/database/schemas');- // 1. 创建 chunk+ // 1. Create chunkconst [chunk] = await serverDB.insert(chunks).values({@@ -1099,7 +1099,7 @@ describe('Message Router Integration Tests', () => {}).returning();- // 2. 创建 message query+ // 2. Create message queryconst [query] = await serverDB.insert(messageQueries).values({@@ -1109,7 +1109,7 @@ describe('Message Router Integration Tests', () => {}).returning();- // 3. 调用 updateMessageRAG+ // 3. Call updateMessageRAGawait caller.updateMessageRAG({id: msg.id,value: {@@ -1118,7 +1118,7 @@ describe('Message Router Integration Tests', () => {},});- // 验证 messageQueryChunks 记录已创建+ // Verify messageQueryChunks record was createdconst [queryChunk] = await serverDB.select().from(messageQueryChunks)@@ -1143,7 +1143,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 创建必要的依赖: chunks -> messageQueries+ // Create required dependencies: chunks -> messageQueriesconst { chunks, messageQueries } = await import('@/database/schemas');const [chunk] = await serverDB.insert(chunks)@@ -1153,7 +1153,7 @@ describe('Message Router Integration Tests', () => {}).returning();- // 创建 query (需要 queryId)+ // Create query (queryId required)const [query] = await serverDB.insert(messageQueries).values({@@ -1214,7 +1214,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 先创建一个 plugin 记录+ // First create a plugin recordconst { messagePlugins } = await import('@/database/schemas');await serverDB.insert(messagePlugins).values({id: msg.id,@@ -1246,7 +1246,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 先创建一个 plugin 记录+ // First create a plugin recordconst { messagePlugins } = await import('@/database/schemas');await serverDB.insert(messagePlugins).values({id: msg1.id,@@ -1283,7 +1283,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 先创建一个 plugin 记录+ // First create a plugin recordconst { messagePlugins } = await import('@/database/schemas');await serverDB.insert(messagePlugins).values({id: msg.id,@@ -1312,7 +1312,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 创建 file 记录+ // Create file recordconst { files } = await import('@/database/schemas');const [file] = await serverDB.insert(files)@@ -1351,7 +1351,7 @@ describe('Message Router Integration Tests', () => {sessionId: testSessionId,});- // 创建 file 记录+ // Create file recordconst { files } = await import('@/database/schemas');const [file] = await serverDB.insert(files)@@ -1452,7 +1452,7 @@ describe('Message Router Integration Tests', () => {it('should get message heatmaps', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建一些消息+ // Create some messagesawait caller.createMessage({content: 'Message 1',role: 'user',@@ -1476,14 +1476,14 @@ describe('Message Router Integration Tests', () => {it('should get model usage ranking', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建带有模型信息的消息+ // Create message with model informationconst msg = await caller.createMessage({content: 'Message from AI',role: 'assistant',sessionId: testSessionId,});- // 添加模型信息+ // Add model informationawait serverDB.update(messages).set({ model: 'gpt-4' }).where(eq(messages.id, msg.id));const ranking = await caller.rankModels();@@ -1497,7 +1497,7 @@ describe('Message Router Integration Tests', () => {it('should count messages', async () => {const caller = messageRouter.createCaller(createTestContext(userId));- // 创建消息+ // Create messageawait caller.createMessage({content: 'Message 1',role: 'user',diff --git a/src/server/routers/lambda/__tests__/integration/topic.integration.test.ts b/src/server/routers/lambda/__tests__/integration/topic.integration.test.tsindex e537eca17bf..7bc6b6b38e2 100644--- a/src/server/routers/lambda/__tests__/integration/topic.integration.test.ts+++ b/src/server/routers/lambda/__tests__/integration/topic.integration.test.ts@@ -20,12 +20,12 @@ vi.mock('next/server', () => ({}));/**- * Topic Router 集成测试+ * Topic Router Integration Tests*- * 测试目标:- * 1. 验证完整的 tRPC 调用链路(Router → Model → Database)- * 2. 确保 agentId → sessionId 解析正常工作- * 3. 验证数据库约束和关联关系+ * Test objectives:+ * 1. Verify the complete tRPC call chain (Router → Model → Database)+ * 2. Ensure agentId → sessionId resolution works correctly+ * 3. Verify database constraints and associations*/describe('Topic Router Integration Tests', () => {let serverDB: LobeChatDatabase;@@ -38,7 +38,7 @@ describe('Topic Router Integration Tests', () => {testDB = serverDB;userId = await createTestUser(serverDB);- // 创建测试 agent+ // Create test agentconst { agents } = await import('@/database/schemas');const [agent] = await serverDB.insert(agents)@@ -46,11 +46,11 @@ describe('Topic Router Integration Tests', () => {.returning();testAgentId = agent.id;- // 创建测试 session+ // Create test sessionconst [session] = await serverDB.insert(sessions).values({ userId, type: 'agent' }).returning();testSessionId = session.id;- // 创建 agent 到 session 的映射关系+ // Create agent-to-session mappingconst { agentsToSessions } = await import('@/database/schemas');await serverDB.insert(agentsToSessions).values({agentId: testAgentId,@@ -91,14 +91,14 @@ describe('Topic Router Integration Tests', () => {expect(createdTopic).toBeDefined();expect(createdTopic.title).toBe('Topic with agentId');- // 验证 agentId 被正确解析为 sessionId+ // Verify agentId is correctly resolved to sessionIdexpect(createdTopic.sessionId).toBe(testSessionId);});it('should prefer agentId over sessionId when both provided', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建另一个 session+ // Create another sessionconst [anotherSession] = await serverDB.insert(sessions).values({@@ -110,12 +110,12 @@ describe('Topic Router Integration Tests', () => {const topicId = await caller.createTopic({title: 'Topic with both ids',agentId: testAgentId,- sessionId: anotherSession.id, // 这个会被 agentId 覆盖+ sessionId: anotherSession.id, // This will be overridden by agentId});const [createdTopic] = await serverDB.select().from(topics).where(eq(topics.id, topicId));- // 应该使用 agentId 解析出的 sessionId+ // Should use the sessionId resolved from agentIdexpect(createdTopic.sessionId).toBe(testSessionId);});@@ -159,7 +159,7 @@ describe('Topic Router Integration Tests', () => {it('should batch create topics with mixed agentId and sessionId', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建另一个 session+ // Create another sessionconst [anotherSession] = await serverDB.insert(sessions).values({@@ -176,7 +176,7 @@ describe('Topic Router Integration Tests', () => {expect(result.success).toBe(true);expect(result.added).toBe(2);- // 验证每个 topic 关联到正确的 session+ // Verify each topic is linked to the correct sessionconst allTopics = await serverDB.select().from(topics).where(eq(topics.userId, userId));const topicWithAgent = allTopics.find((t) => t.title === 'Topic with agentId');@@ -191,7 +191,7 @@ describe('Topic Router Integration Tests', () => {it('should get topics by agentId', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建测试 topic+ // Create test topicawait caller.createTopic({title: 'Topic 1',sessionId: testSessionId,@@ -202,12 +202,12 @@ describe('Topic Router Integration Tests', () => {sessionId: testSessionId,});- // 使用 agentId 查询+ // Query using agentIdconst result = await caller.getTopics({agentId: testAgentId,});- // result 包含 items 和 total+ // result contains items and totalexpect(result.items).toHaveLength(2);expect(result.items.map((t) => t.title)).toContain('Topic 1');expect(result.items.map((t) => t.title)).toContain('Topic 2');@@ -217,13 +217,13 @@ describe('Topic Router Integration Tests', () => {it('should resolve sessionId to agentId when only sessionId provided', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建测试 topic+ // Create test topicawait caller.createTopic({title: 'Topic for reverse lookup',sessionId: testSessionId,});- // 使用 sessionId 查询(需要反向查找 agentId)+ // Query using sessionId (requires reverse lookup of agentId)const result = await caller.getTopics({sessionId: testSessionId,});@@ -238,7 +238,7 @@ describe('Topic Router Integration Tests', () => {it('should batch delete topics using agentId', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建测试 topics+ // Create test topicsawait caller.createTopic({title: 'Topic to delete 1',sessionId: testSessionId,@@ -249,7 +249,7 @@ describe('Topic Router Integration Tests', () => {sessionId: testSessionId,});- // 使用 agentId 批量删除+ // Batch delete using agentIdawait caller.batchDeleteBySessionId({agentId: testAgentId,});@@ -265,13 +265,13 @@ describe('Topic Router Integration Tests', () => {it('should batch delete topics using sessionId', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建测试 topics+ // Create test topicsawait caller.createTopic({title: 'Topic to delete',sessionId: testSessionId,});- // 使用 sessionId 批量删除+ // Batch delete using sessionIdawait caller.batchDeleteBySessionId({id: testSessionId,});@@ -364,7 +364,7 @@ describe('Topic Router Integration Tests', () => {it('should search topics using agentId', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建测试 topics+ // Create test topicsawait caller.createTopic({title: 'TypeScript Discussion',sessionId: testSessionId,@@ -375,7 +375,7 @@ describe('Topic Router Integration Tests', () => {sessionId: testSessionId,});- // 使用 agentId 搜索+ // Search using agentIdconst result = await caller.searchTopics({keywords: 'TypeScript',agentId: testAgentId,@@ -390,13 +390,13 @@ describe('Topic Router Integration Tests', () => {it('should update topic with agentId in value', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建测试 topic+ // Create test topicconst topicId = await caller.createTopic({title: 'Original Title',sessionId: testSessionId,});- // 创建另一个 agent 和 session+ // Create another agent and sessionconst { agents, agentsToSessions } = await import('@/database/schemas');const [newAgent] = await serverDB.insert(agents)@@ -420,7 +420,7 @@ describe('Topic Router Integration Tests', () => {userId,});- // 更新 topic,使用 agentId 指定新的关联+ // Update topic, specifying new association using agentIdawait caller.updateTopic({id: topicId,value: {@@ -732,13 +732,13 @@ describe('Topic Router Integration Tests', () => {it('should clone topic', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 创建原始 topic+ // Create original topicconst originalId = await caller.createTopic({title: 'Original Topic',sessionId: testSessionId,});- // 克隆 topic+ // Clone topicconst clonedId = await caller.cloneTopic({id: originalId,newTitle: 'Cloned Topic',@@ -769,7 +769,7 @@ describe('Topic Router Integration Tests', () => {sessionId: testSessionId,});- // 删除前两个+ // Delete the first twoawait caller.batchDelete({ ids: [id1, id2] });const remainingTopics = await serverDB@@ -835,11 +835,11 @@ describe('Topic Router Integration Tests', () => {it('should check if user has topics', async () => {const caller = topicRouter.createCaller(createTestContext(userId));- // 初始应该没有 topics+ // Initially there should be no topicsconst hasNoTopics = await caller.hasTopics();- expect(hasNoTopics).toBe(true); // 注意:hasTopics 返回 count === 0+ expect(hasNoTopics).toBe(true); // Note: hasTopics returns count === 0- // 创建 topic 后+ // After creating a topicawait caller.createTopic({title: 'First Topic',sessionId: testSessionId,