fix: isolate teacher references from unrelated selections

This commit is contained in:
鲨鱼辣椒
2026-09-30 11:19:37 +08:00
parent c55e9c7182
commit 36202e0642
6 changed files with 235 additions and 11 deletions

View File

@@ -1855,6 +1855,52 @@ test('PI feature UI isolates Conversations and exposes queue, interaction, model
});
test('teacher navigation isolates selected text and consumes operation quotes once', async ({ launchElectronApp }) => {
const electronApp = await launchElectronApp({ skipSetup: true });
let page = await getStableWindow(electronApp);
const connection = await page.evaluate(async () => ({ token: await window.electron.ipcRenderer.invoke('hostapi:token') as string, baseUrl: await window.electron.ipcRenderer.invoke('hostapi:base-url') as string }));
await installCodingFirstChatHost(electronApp, connection, true);
await settleSnapshot(electronApp);
await disableCodingEventSource(page);
try {
await page.reload(); page = await getStableWindow(electronApp);
await page.getByTestId('ai-module-option-programming').click();
await page.evaluate(() => { window.location.hash = '/chat'; });
await page.getByRole('button', { name: '与朋友聊天', exact: true }).click();
const panel = page.getByTestId('teacher-chat-panel');
const input = panel.getByRole('textbox', { name: '向智能体提问' });
await input.fill('只有测试老师的提问');
await panel.getByRole('button', { name: '提问', exact: true }).click();
await expect(panel.getByText('先理解状态如何随点击变化,再修改代码。')).toBeVisible();
await panel.getByText('只有测试老师的提问', { exact: true }).evaluate(element => {
const range = document.createRange(); range.selectNodeContents(element);
window.getSelection()!.removeAllRanges(); window.getSelection()!.addRange(range);
});
await page.getByRole('button', { name: '与代码智能体聊天', exact: true }).click();
await expect(panel.getByRole('button', { name: '移除引用' })).toHaveCount(0);
await input.fill('正式老师的独立提问');
await panel.getByRole('button', { name: '提问', exact: true }).click();
await expect(panel.getByText('先理解状态如何随点击变化,再修改代码。')).toBeVisible();
const sent = (await readState(electronApp)).captured.filter(item => item.path.endsWith('/messages') && item.method === 'POST');
expect(sent).toHaveLength(2);
expect(sent[1]).toMatchObject({ path: expect.stringContaining('/teacher-code/messages'), body: { text: '正式老师的独立提问', references: [] } });
await page.getByRole('tab', { name: '操作对话', exact: true }).click();
const operationMessage = page.getByTestId('coding-conversation-timeline').locator('[data-node-kind="message"]').first();
await expect(operationMessage).toBeVisible();
await operationMessage.evaluate(element => {
const range = document.createRange(); range.selectNodeContents(element);
window.getSelection()!.removeAllRanges(); window.getSelection()!.addRange(range);
});
await page.getByRole('button', { name: '与朋友聊天', exact: true }).click();
await panel.getByRole('button', { name: '移除引用' }).click();
await page.getByRole('button', { name: '收起老师对话栏' }).click();
await page.getByRole('button', { name: '展开老师对话栏' }).click();
await expect(input).toBeEnabled();
await expect(panel.getByRole('button', { name: '移除引用' })).toHaveCount(0);
expect((await readState(electronApp)).captured.filter(item => item.path.endsWith('/messages') && item.method === 'POST')).toHaveLength(2);
} finally { await releaseSnapshot(electronApp); }
});
test('project consultations preserve student drafts and switch between work and chat without submitting advice', async ({launchElectronApp}) => {
const electronApp=await launchElectronApp({skipSetup:true});let page=await getStableWindow(electronApp);
const connection=await page.evaluate(async()=>({token:await window.electron.ipcRenderer.invoke('hostapi:token') as string,baseUrl:await window.electron.ipcRenderer.invoke('hostapi:base-url') as string}));