d229648511
Brand-new drafts are empty on purpose. A routed session the list already knows has messages must not drop the loader just because a runtime id is bound — that is the blank frame during an unproven warm hold and a cold switch.
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { ChatMessage } from '@/lib/chat-messages'
|
|
|
|
import { lastVisibleMessageIsUser, routedSessionIsLoading, threadLoadingState } from './thread-loading'
|
|
|
|
function message(id: string, role: ChatMessage['role'], hidden = false): ChatMessage {
|
|
return {
|
|
id,
|
|
role,
|
|
parts: [{ type: 'text', text: `${role}:${id}` }],
|
|
hidden
|
|
}
|
|
}
|
|
|
|
describe('thread loading state', () => {
|
|
it('returns session when routed session is still hydrating', () => {
|
|
expect(threadLoadingState(true, true, true, false)).toBe('session')
|
|
})
|
|
|
|
it('returns response while awaiting an assistant reply to the last visible user message', () => {
|
|
const messages = [message('u1', 'user'), message('a1', 'assistant', true)]
|
|
|
|
expect(lastVisibleMessageIsUser(messages)).toBe(true)
|
|
expect(threadLoadingState(false, true, true, lastVisibleMessageIsUser(messages))).toBe('response')
|
|
})
|
|
|
|
it('does not show response loading when the last visible message is not user-authored', () => {
|
|
const messages = [message('u1', 'user'), message('a1', 'assistant')]
|
|
|
|
expect(lastVisibleMessageIsUser(messages)).toBe(false)
|
|
expect(threadLoadingState(false, true, true, lastVisibleMessageIsUser(messages))).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('routedSessionIsLoading', () => {
|
|
const base = {
|
|
activeSessionId: 'runtime-1' as string | null,
|
|
knownHistory: false,
|
|
messagesEmpty: false,
|
|
resumeExhausted: false,
|
|
routeSessionMismatch: false,
|
|
routedSessionView: true
|
|
}
|
|
|
|
it('keeps the session loader up when known history is held off the view', () => {
|
|
expect(
|
|
routedSessionIsLoading({
|
|
...base,
|
|
knownHistory: true,
|
|
messagesEmpty: true
|
|
})
|
|
).toBe(true)
|
|
})
|
|
|
|
it('does not treat a brand-new empty routed draft as still loading', () => {
|
|
expect(
|
|
routedSessionIsLoading({
|
|
...base,
|
|
messagesEmpty: true
|
|
})
|
|
).toBe(false)
|
|
})
|
|
})
|