fix: isolate delivered agent chats by project

This commit is contained in:
2026-09-28 16:21:14 +08:00
parent a21a1f077c
commit 4b41c23a3a
15 changed files with 518 additions and 165 deletions

View File

@@ -20,6 +20,7 @@ const api = vi.hoisted(() => ({
}));
vi.mock('@/lib/coding-teacher', () => ({
teacherApi: api,
teacherConversationsPath: (project: string) => '/api/coding/projects/' + project + '/agent-conversations',
teacherTopicsPath: (p: string) => p === 'preview' ? 'preview/sample' : p + '/agent-topics',
legacyTopicBase: (base: string, legacy: boolean) => legacy ? base.replace('agent-topics', 'friend-topics') : base,
}));
@@ -696,7 +697,7 @@ describe('merged cloud teacher classroom', () => {
const selected = { ...topic('selected'), sourceConversationId: 'project', role: 'teacher' as const, definition: cloudDefinition, version: 9 };
api.conversation.mockResolvedValue({ topic: null, before: null });
api.create.mockResolvedValue(selected);
api.sendConversation.mockImplementation(async (_agent, input: TeacherSend) => ({ ...selected, revision: 2,
api.sendConversation.mockImplementation(async (_project, _agent, input: TeacherSend) => ({ ...selected, revision: 2,
conversation: {agentId: 'algorithm', segmentTurns: 1, discussions: {}, seenThrough: input.requestId},
requests: [request({ id: input.requestId, text: input.text, response: '先看看玩家会做什么。' })] }));
render(<TeacherChatPanel projectId="p" sourceId="c" selectedAgent={{ teacher_id: 'algorithm', version: 9, definition: cloudDefinition, is_default: false }} />);
@@ -709,7 +710,7 @@ describe('merged cloud teacher classroom', () => {
fireEvent.click(screen.getByRole('button', { name: '提问', exact: true }));
await screen.findByText('先看看玩家会做什么。');
expect(api.create).not.toHaveBeenCalled();
expect(api.sendConversation).toHaveBeenCalledWith('algorithm', expect.objectContaining({ projectId: 'p', sourceConversationId: 'c', presentation: 'discussion-v1' }));
expect(api.sendConversation).toHaveBeenCalledWith('p', 'algorithm', expect.objectContaining({ projectId: 'p', sourceConversationId: 'c', presentation: 'discussion-v1' }));
expect(screen.getByRole('complementary', { name: '算法智能体咨询' })).toBeVisible();
});