fix(assistant): reject restored ordinary sessions (#4356)

main
hahahahahayesyeseys 2026-10-15 23:47:51 +08:00 committed by GitHub
parent 4d4acec418
commit aeeb72a61a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View File

@ -98,7 +98,7 @@ async function fixture(
'./AssistantAccessPicker.vue': emptyComponent,
'@/api/chat': {
createSessions: createSession,
getSession: api.getSession || (async () => ({ success: true, data: {} })),
getSession: api.getSession || (async () => ({ success: true, data: { kind: 'assistant' } })),
getSessionsList: async (...args: any[]) => {
listCalls.push(args)
return api.getSessionsList ? api.getSessionsList(...args) : { success: true, data: [], total: 0 }
@ -328,6 +328,19 @@ for (const status of [403, 404, 500]) {
})
}
test('stored ordinary session is rejected instead of mounting it as assistant history', async () => {
const f = await fixture(undefined, undefined, {
getSession: async () => ({ success: true, data: { id: 'workspace-b-session', kind: '' } }),
})
try {
f.auth.effectiveTenantId = 2
await flush()
assert.equal(f.assistant.sessionId, '')
assert.equal(f.sessionStorage.getItem('weknora:assistant-session:user-a:2'), null)
assert.equal(f.mounted.length, 0)
} finally { f.close() }
})
test('history distinguishes empty and failed loads and retries the same page', async () => {
let failed = true
const f = await fixture(undefined, undefined, {

View File

@ -344,8 +344,13 @@ async function validateSession(id: string) {
return
}
try {
await getSession(id)
if (owner === conversationOwner.value && id === assistant.sessionId) readySessionId.value = id
const res: any = await getSession(id)
if (owner !== conversationOwner.value || id !== assistant.sessionId) return
if (res?.data?.kind !== 'assistant') {
startNewConversation()
return
}
readySessionId.value = id
} catch (error: any) {
if (owner !== conversationOwner.value || id !== assistant.sessionId) return
const status = error?.$httpStatus ?? error?.response?.status ?? error?.status