diff --git a/frontend/src/components/assistant/AssistantPanel.test.ts b/frontend/src/components/assistant/AssistantPanel.test.ts index 7aa86ad5..d368c3e0 100644 --- a/frontend/src/components/assistant/AssistantPanel.test.ts +++ b/frontend/src/components/assistant/AssistantPanel.test.ts @@ -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, { diff --git a/frontend/src/components/assistant/AssistantPanel.vue b/frontend/src/components/assistant/AssistantPanel.vue index 52c832ce..63f42839 100644 --- a/frontend/src/components/assistant/AssistantPanel.vue +++ b/frontend/src/components/assistant/AssistantPanel.vue @@ -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