feat(web): 工作台 AI 模式与差旅/风险建议交互优化
- 新增 PersonalWorkbenchAiMode 组件、AI 侧边栏与 orb 机器人视觉资源 - 新增 aiApplicationDraftModel / aiExpenseDraftModel / aiWorkbenchConversationStore 及业务准入 aiSidebarBusinessAccess,支撑 AI 模式下的申请与报销草稿 - 顶栏、侧边栏、工作台样式重构,适配 AI 模式切换与响应式布局 - 同步 steward plan/off_topic、差旅报销引导流、风险建议卡片等测试
This commit is contained in:
69
web/tests/ai-workbench-conversation-store.test.mjs
Normal file
69
web/tests/ai-workbench-conversation-store.test.mjs
Normal file
@@ -0,0 +1,69 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
deleteAiWorkbenchConversation,
|
||||
loadAiWorkbenchConversationHistory,
|
||||
saveAiWorkbenchConversation
|
||||
} from '../src/utils/aiWorkbenchConversationStore.js'
|
||||
|
||||
function installLocalStorageMock() {
|
||||
const store = new Map()
|
||||
globalThis.window = {
|
||||
localStorage: {
|
||||
getItem(key) {
|
||||
return store.has(key) ? store.get(key) : null
|
||||
},
|
||||
setItem(key, value) {
|
||||
store.set(key, String(value))
|
||||
},
|
||||
removeItem(key) {
|
||||
store.delete(key)
|
||||
},
|
||||
clear() {
|
||||
store.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
return store
|
||||
}
|
||||
|
||||
test('AI workbench conversation store persists scoped history for sidebar sessions', () => {
|
||||
installLocalStorageMock()
|
||||
const user = { username: 'caoxiaozhu', email: 'caoxiaozhu@xf.com', name: '曹笑竹' }
|
||||
const anotherUser = { username: 'budget-user' }
|
||||
|
||||
saveAiWorkbenchConversation(user, {
|
||||
id: 'conv-first',
|
||||
title: '',
|
||||
updatedAt: Date.now() - 3000,
|
||||
messages: [
|
||||
{ id: 'u1', role: 'user', content: '帮我核对差旅报销口径' },
|
||||
{ id: 'a1', role: 'assistant', content: '我会根据制度和票据要求继续核对。' }
|
||||
]
|
||||
})
|
||||
saveAiWorkbenchConversation(user, {
|
||||
id: 'conv-second',
|
||||
title: '预算占用分析',
|
||||
updatedAt: Date.now(),
|
||||
stewardState: { intent: 'budget_check' },
|
||||
messages: [
|
||||
{ id: 'u2', role: 'user', content: '分析本月预算占用' },
|
||||
{ id: 'a2', role: 'assistant', content: '本月预算占用需要结合部门额度和已提交单据。' }
|
||||
]
|
||||
})
|
||||
|
||||
const history = loadAiWorkbenchConversationHistory(user)
|
||||
assert.equal(history.length, 2)
|
||||
assert.equal(history[0].id, 'conv-second')
|
||||
assert.equal(history[0].title, '预算占用分析')
|
||||
assert.equal(history[0].stewardState.intent, 'budget_check')
|
||||
assert.equal(history[1].title, '帮我核对差旅报销口径')
|
||||
assert.equal(history[1].prompt, '帮我核对差旅报销口径')
|
||||
assert.ok(history[0].time)
|
||||
assert.deepEqual(loadAiWorkbenchConversationHistory(anotherUser), [])
|
||||
|
||||
const nextHistory = deleteAiWorkbenchConversation(user, 'conv-second')
|
||||
assert.equal(nextHistory.length, 1)
|
||||
assert.equal(nextHistory[0].id, 'conv-first')
|
||||
})
|
||||
Reference in New Issue
Block a user