feat: 在顶栏并排展示下发智能体并直接切换

This commit is contained in:
2026-09-24 15:38:50 +08:00
parent 39b03a1628
commit a10cf00015
15 changed files with 291 additions and 59 deletions

View File

@@ -642,6 +642,22 @@ it('comparison focuses and directly sends the selected difference while preservi
describe('merged cloud teacher classroom', () => {
it('keeps an old unassigned project draft readable without copying it to the selected agent', async () => {
const published = { ...definition, config_id: 'one' };
const original = JSON.stringify({ text: '旧项目草稿', references: [{ kind: 'code', text: '旧引用' }] });
const key = 'makelore-consultation-draft:signed-out:p:teacher';
localStorage.setItem(key, original);
api.list.mockResolvedValue({ items: [], lastSelectedTopicId: null });
render(<TeacherChatPanel projectId="p" sourceId="c" selectedAgent={{ teacher_id: 'one', version: 1, definition: published, is_default: true }} />);
await waitFor(() => expect(screen.getByLabelText('向智能体提问')).toBeEnabled());
expect(screen.getByLabelText('向智能体提问')).toHaveValue('');
fireEvent.click(screen.getByText('查看之前的项目草稿'));
expect(screen.getByText('旧项目草稿')).toBeVisible();
fireEvent.change(screen.getByLabelText('向智能体提问'), { target: { value: '新的独立草稿' } });
expect(localStorage.getItem(key)).toBe(original);
expect(api.send).not.toHaveBeenCalled();
});
it('selects a cloud teacher for the first project discussion without sending the operation draft', async () => {
const cloudDefinition = { ...definition, runtime: 'yuxi' as const, config_id: 'algorithm', name: '算法智能体', yuxi: { agent_slug: 'algorithm', agent_version: 2 } };
api.list.mockResolvedValue({ items: [], lastSelectedTopicId: null });
@@ -652,10 +668,10 @@ describe('merged cloud teacher classroom', () => {
const selected = { ...topic('selected'), sourceConversationId: 'project', role: 'teacher' as const, definition: cloudDefinition, version: 9 };
api.create.mockResolvedValue(selected);
api.send.mockImplementation(async (_base, _id, input: TeacherSend) => ({ ...selected, revision: 2, requests: [request({ id: input.requestId, text: input.text, response: '先看看玩家会做什么。' })] }));
render(<TeacherChatPanel projectId="p" sourceId="c" />);
await waitFor(() => expect(screen.getByLabelText('新话题使用的智能体')).toBeEnabled());
render(<TeacherChatPanel projectId="p" sourceId="c" selectedAgent={{ teacher_id: 'algorithm', version: 9, definition: cloudDefinition, is_default: false }} />);
await waitFor(() => expect(screen.getByLabelText('向智能体提问')).toBeEnabled());
expect(screen.queryByLabelText('新话题使用的智能体')).not.toBeInTheDocument();
expect(api.create).not.toHaveBeenCalled();
fireEvent.change(screen.getByLabelText('新话题使用的智能体'), { target: { value: '9' } });
fireEvent.change(screen.getByLabelText('向智能体提问'), { target: { value: '我想做一个小游戏' } });
fireEvent.click(screen.getByRole('button', { name: '提问', exact: true }));
await screen.findByText('先看看玩家会做什么。');