fix(ai): 修复追问与删除确认并支持删除对话

This commit is contained in:
LoveChengke committed 2026-11-08 11:13:43 +08:00
1 parent 0b57e926bd
commit 195ee3b90a
24 files changed
+627 -113

No files matched your search

+118
View File
@@ -108,6 +108,124 @@ module.exports = async function runAssistantChecks({ win, target, record, waitFo
);
assert.equal((await request('/homeworks?keyword=' + encodeURIComponent(title))).length, 1);
record('AI 界面确认后通过原业务端点执行并显示结果', true);
const sendChat = async (content) => {
await win.webContents.executeJavaScript(
`(() => {const input=document.querySelector('.assistant-composer textarea');Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,'value').set.call(input,${JSON.stringify(content)});input.dispatchEvent(new Event('input',{bubbles:true}));})()`,
);
assert(
await waitFor(
win,
`Array.from(document.querySelectorAll('.assistant-composer button')).some(b=>b.textContent.trim()==='发送'&&!b.disabled)`,
),
);
await win.webContents.executeJavaScript(
`Array.from(document.querySelectorAll('.assistant-composer button')).find(b=>b.textContent.trim()==='发送').click()`,
);
};
await sendChat(
JSON.stringify({
message: '请确认要处理哪张课表?',
questions: [{ question: '请选择下一步', options: ['查看本班今天的作业'] }],
}),
);
const questionVisible = `Array.from(document.querySelectorAll('.assistant-questions-dialog')).some(d=>d.getBoundingClientRect().height>0 && d.textContent.includes('请选择下一步'))`;
assert(await waitFor(win, questionVisible));
await screenshot('assistant-question-dialog');
await win.loadURL(origin + '/assistant');
assert(await waitFor(win, questionVisible));
const roundsBefore = await win.webContents.executeJavaScript(
`document.querySelectorAll('.assistant-message.user').length`,
);
await win.webContents.executeJavaScript(
`document.querySelector('.assistant-questions-dialog .question-options button').click()`,
);
assert(
await waitFor(
win,
`Array.from(document.querySelectorAll('.assistant-questions-dialog .el-dialog__footer button')).some(b=>b.textContent.trim()==='发送回答'&&!b.disabled)`,
),
);
await win.webContents.executeJavaScript(
`Array.from(document.querySelectorAll('.assistant-questions-dialog .el-dialog__footer button')).find(b=>b.textContent.trim()==='发送回答').click()`,
);
assert(
await waitFor(
win,
`document.querySelectorAll('.assistant-message.user').length===${roundsBefore + 1} && Array.from(document.querySelectorAll('.assistant-composer button')).some(b=>b.textContent.trim()==='发送'&&!b.disabled)===false && !(${questionVisible})`,
),
);
// 输入为空时发送按钮禁用,等待后台结束由停止生成按钮消失判断。
assert(
await waitFor(
win,
`!Array.from(document.querySelectorAll('.assistant-composer button')).some(b=>b.textContent.trim()==='停止生成')`,
),
);
record('模型提问弹出交互窗口,刷新可恢复,回答作为同一对话的新一轮继续', true);
const layout = await request('/time-layouts', 'POST', {
classId: cls.id,
name: title + '删除作息',
points: [],
});
const day = await request('/class-plans', 'POST', {
classId: cls.id,
name: title + '待删除课表',
timeLayoutId: layout.id,
weekday: 1,
});
await sendChat(JSON.stringify({ operations: [{ action: 'plans.delete', target: { id: day.id } }] }));
assert(
await waitFor(
win,
`document.querySelector('.assistant-step')?.textContent.includes(${JSON.stringify(day.name)}) && document.querySelector('.assistant-step .el-tag')?.textContent.includes('待确认')`,
),
);
assert(
(await request('/class-plans?classId=' + encodeURIComponent(cls.id))).some((p) => p.id === day.id),
);
await win.webContents.executeJavaScript(
`Array.from(document.querySelectorAll('.assistant-plan-actions button')).find(b=>b.textContent.trim()==='确认执行').click()`,
);
assert(
await waitFor(
win,
`(() => {const box=document.querySelector('.el-message-box');if(!box?.textContent.includes(${JSON.stringify(day.name)})||!box.getBoundingClientRect().height)return false;for(let node=box;node;node=node.parentElement){const style=getComputedStyle(node);if(style.display==='none'||style.visibility==='hidden'||Number(style.opacity)<0.99)return false;}return true;})()`,
),
);
await win.webContents.capturePage();
await new Promise((resolve) => setTimeout(resolve, 150));
await screenshot('assistant-delete-confirm');
await win.webContents.executeJavaScript(
`Array.from(document.querySelectorAll('.el-message-box__btns button')).find(b=>b.textContent.trim()==='取消').click()`,
);
assert(
(await request('/class-plans?classId=' + encodeURIComponent(cls.id))).some((p) => p.id === day.id),
);
record('删除课表先显示预览及危险操作确认窗口,取消不会删除', true);
// 对话删除不回滚已完成的作业,也不执行其余待确认删除计划。
const current = (await request('/ai/conversations'))[0];
await win.webContents.executeJavaScript(
`Array.from(document.querySelectorAll('.agent-header-actions button')).find(b=>b.textContent.trim()==='删除对话').click()`,
);
assert(await waitFor(win, `document.querySelector('.el-message-box')?.textContent.includes('删除对话')`));
await win.webContents.executeJavaScript(
`Array.from(document.querySelectorAll('.el-message-box__btns button')).find(b=>b.textContent.trim()==='删除对话').click()`,
);
assert(
await waitFor(
win,
`!document.querySelector('.assistant-step') && !document.querySelector('.assistant-message')`,
),
);
assert(!(await request('/ai/conversations')).some((c) => c.id === current.id));
assert.equal((await request('/homeworks?keyword=' + encodeURIComponent(title))).length, 1);
assert(
(await request('/class-plans?classId=' + encodeURIComponent(cls.id))).some((p) => p.id === day.id),
);
await request('/class-plans/' + day.id, 'DELETE');
await request('/time-layouts/' + layout.id, 'DELETE');
record('界面可以确认删除当前对话,轮次消失,已执行作业保留且待确认课表未删除', true);
const cachedBefore = await request('/update/client/releases');
const cacheVersion = `0.0.0-ai-${Date.now()}`;
const cacheTask = JSON.stringify({
+2 -2
View File
@@ -104,9 +104,9 @@ const child = spawn(executable, [entry], {
}),
});
const timeout = setTimeout(() => {
console.error('[ui-smoke] 后台验收超过 120 秒,终止验证进程');
console.error('[ui-smoke] 后台验收超过 180 秒,终止验证进程');
child.kill();
}, 120_000);
}, 180_000);
child.on('exit', async (code) => {
clearTimeout(timeout);
+55
View File
@@ -0,0 +1,55 @@
/** 真实模型回复解析器的快速回归;不加载业务库,不访问模型服务。 */
const fs = require('node:fs');
const vm = require('node:vm');
const path = require('node:path');
const assert = require('node:assert/strict');
const ts = require('typescript');
const { createRequire } = require('node:module');
const requireServer = createRequire(path.resolve(__dirname, '../packages/server/package.json'));
const output = {};
const source = fs.readFileSync(
path.resolve(__dirname, '../packages/server/src/modules/ai/model-reply.ts'),
'utf8',
);
vm.runInNewContext(
ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
}).outputText,
{ exports: output, require: requireServer },
);
const parse = output.parseModelReply;
for (const sample of [
'请确认是否删除“周一课表”?确认后我会继续。',
JSON.stringify({ message: '请确认是否删除“周一课表”?', queries: [], operations: [] }),
JSON.stringify({ questions: [{ question: '要删除哪张课表?', options: ['周一', '周五'] }] }),
JSON.stringify({ question: '请选择要删除的课表。' }),
JSON.stringify({ questions: ['请选择要删除的课表。'] }),
JSON.stringify({
questions: [{ text: '请选择课表', options: [{ label: '周一', description: '每周一' }] }],
}),
JSON.stringify('Would you like to continue?'),
]) {
const reply = parse(sample);
assert(reply.questions.length > 0);
assert.equal(reply.operations.length, 0);
assert.equal(reply.queries.length, 0);
}
assert(parse('请确认是否删除课表?').questions[0].options.includes('继续生成操作预览'));
const deletion = {
message: '请确认删除',
operations: [{ action: 'plans.delete', target: { id: 'existing-plan' } }],
};
const plan = parse(JSON.stringify(deletion));
assert.equal(plan.operations[0].target.id, 'existing-plan');
assert(!plan.questions?.length);
const mixed = parse(JSON.stringify({ ...deletion, questions: [{ text: '请选择课表' }] }));
assert.equal(mixed.operations.length, 0);
for (const sample of [
'空白',
'已删除课表。',
'{"message":"确认删除吗?"',
'{"operations":[{"action":"plans.delete","target":{"id":10}}]}',
'{"operations":{}}',
])
assert.throws(() => parse(sample));
console.log('PASS:追问兼容、删除预览保留、问题优先及损坏协议拒绝');