import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import test from 'node:test'; const read = (path) => readFile(new URL(path, import.meta.url), 'utf8'); test('问师傅为文字、媒体和数据工具请求携带同一短期会话版本', async () => { const service = await read('../src/services/knowledge.ts'); assert.match(service, /conversationId:\s*conversation\?\.conversationId/); assert.match(service, /contextVersion:\s*conversation\?\.contextVersion/); assert.match(service, /conversationId:\s*conversation\.conversationId/); assert.match(service, /resources:\s*response\.resources \|\| \[\]/); }); test('问师傅支持显式新对话、版本回写和受控原文件或视频卡', async () => { const [page, header] = await Promise.all([ read('../src/pages/user/sop/index.vue'), read('../src/components/chat/AskSourceHeader.vue') ]); assert.match(page, /@new-conversation="startNewConversation"/); assert.match(header, /@click="emit\('newConversation'\)"/); assert.match(header, /class="new-chat-text">新对话/); assert.match(page, /const contextVersion = ref\(0\)/); assert.match(page, /applyConversationState\(nextResult\)/); assert.match(page, /authenticatedFileUrl\(resource\.contentUrl\)/); assert.match(page, /releaseAuthenticatedFileUrl\(resource\.localUrl\)/); assert.match(page, /resource\.type === 'VIDEO' && resource\.localUrl/); assert.match(page, /msg\.result\.rewrittenQuery !== msg\.result\.queryText/); assert.match(page, /已结合本次对话理解/); }); test('工作助手按项目名称选择并为文字、媒体和工具请求携带项目上下文', async () => { const [page, service, auth] = await Promise.all([ read('../src/pages/user/sop/index.vue'), read('../src/services/knowledge.ts'), read('../src/services/auth.ts') ]); assert.match(page, /class="compact-project-strip"/); assert.match(page, /projectContextLabel/); assert.match(page, /选择当前项目/); assert.match(page, /搜索项目名称/); assert.match(page, /saveCurrentProject\(project\)/); assert.match(page, /resetConversation\(false\)/); assert.match(page, /currentProject\.value\?\.projectCode/); assert.match(service, /projectCode/); assert.match(auth, /aihr_mobile_current_project:\$\{tenantId/); assert.match(auth, /reconcileCurrentProject/); }); test('项目选择面板避开底栏,普通消息滚底且确认卡从识别结论处展示', async () => { const page = await read('../src/pages/user/sop/index.vue'); assert.match(page, /inset:\s*0 0 var\(--window-bottom, 0px\)/); assert.match(page, /let scrollSeq = 0/); assert.match(page, /threadScrollTop\.value = 100000 \+ \(\+\+scrollSeq \* 200\)/); assert.match(page, /:scroll-into-view="threadScrollIntoView"/); assert.match(page, /:id="`chat-message-\$\{msg\.id\}`"/); assert.match(page, /next\?\.role === 'master' && next\.result\.memoryCandidate/); assert.match(page, /scrollToMessageStart\(id\)/); }); test('问师傅在真正开始会话后收起首次使用引导,保留对话主体', async () => { const page = await read('../src/pages/user/sop/index.vue'); assert.match(page, /const conversationStarted = computed\(\(\) => messages\.value\.some/); assert.match(page, /v-if="loggedIn && !conversationStarted" class="compact-project-strip"/); assert.match(page, /v-if="!conversationStarted" class="bubble-row left"/); assert.match(page, /:quick-questions="conversationStarted \? \[\] : quickQuestions"/); }); test('消息咨询只以消息 ID 作为受控上下文,并让每轮文字或语音请求携带它', async () => { const [page, service, types] = await Promise.all([ read('../src/pages/user/sop/index.vue'), read('../src/services/knowledge.ts'), read('../src/types/api.ts') ]); assert.match(page, /getBroadcastMessage\(pending\.messageId\)/); assert.match(page, /messageId: message\.id,\s*title: message\.title,\s*publishedAt: message\.publishedAt/); assert.match(page, /broadcastMessageId \? undefined : currentProject\.value\?\.projectCode/); assert.match(page, /options\.voice \? 'mobile_uni_voice' : 'mobile_uni_sop',\s*broadcastMessageId/); assert.match(service, /broadcastMessageId\?: number/); assert.match(service, /\? \{ broadcastMessageId \}/); assert.match(service, /broadcastContext: response\.broadcastContext \|\| legacy\.broadcastContext \|\| null/); assert.match(types, /export interface BroadcastKnowledgeContext/); assert.match(types, /broadcastContext\?: BroadcastKnowledgeContext \| null/); }); test('消息咨询会新开会话,隐藏媒体和数据工具,并在撤回时清空对话', async () => { const page = await read('../src/pages/user/sop/index.vue'); assert.match(page, /if \(!conversationStarted\.value\) \{\s*\/\/ Do not start project selection[\s\S]*await activateBroadcastConsultation\(pending, accountKey, pageGeneration\);/); assert.match(page, /!broadcastContext\.value && !broadcastContextLoading\.value && !broadcastContextPrompting\.value/); assert.match(page, /const cancelPendingBroadcastConsultation = \(\) => \{\s*broadcastContextGeneration \+= 1;\s*broadcastContextLoading\.value = false;\s*broadcastContextPrompting\.value = false;/); assert.match(page, /onHide\(\(\) => \{\s*showGeneration \+= 1;\s*candidateRefreshGeneration \+= 1;\s*cancelPendingBroadcastConsultation\(\);/); assert.match(page, /onUnload\(\(\) => \{\s*showGeneration \+= 1;\s*cancelPendingBroadcastConsultation\(\);/); assert.match(page, /error\.statusCode === 404 \|\| error\.bizCode === 404/); assert.match(page, /const pending = readBroadcastQuestionContext\(accountKey\);\s*if \(!pending\) \{\s*if \(broadcastContext\.value\) \{\s*clearBroadcastConsultation\(\);\s*resetConversation\(false\);/); assert.match(page, /const startNewConversation = \(\) => \{\s*clearBroadcastConsultation\(\);\s*resetConversation\(true\);/); assert.match(page, /clearBroadcastConsultation\(\);\s*resetConversation\(false\);\s*pushSystem\('这条消息已撤回,无法继续咨询。'\)/); assert.match(page, /const composerPanelItems = computed\(\(\) => broadcastContext\.value\s*\? \[\{ key: 'pick-audio'/); assert.match(page, /if \(broadcastContext\.value\) \{\s*uni\.showToast\(\{ title: '消息咨询不支持数据查询/); assert.match(page, /if \(broadcastContext\.value\) \{\s*uni\.showToast\(\{ title: '消息咨询暂不支持图片或视频/); assert.match(page, /@click="viewBroadcastMessage">查看原消息/); assert.match(page, /@click="endBroadcastConsultation">结束咨询/); });