89 lines
4.3 KiB
TypeScript
89 lines
4.3 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
import { authenticate, mockChatSocket, mockHermesApi, TEST_ACCESS_KEY } from './fixtures'
|
|
|
|
const session = { id: 'restored-chat', profile: 'research', source: 'cli', title: 'Restored conversation', started_at: 1000, last_active: 1100, message_count: 2 }
|
|
|
|
for (const path of ['/hermes/chat', '/hermes/session/restored-chat?profile=research']) {
|
|
test(`recovers sessions and preserves the route after backend restart: ${path}`, async ({ page }) => {
|
|
await authenticate(page, TEST_ACCESS_KEY, 'research')
|
|
await mockHermesApi(page, { sessions: [session] })
|
|
await mockChatSocket(page)
|
|
let ready = false
|
|
let healthRequests = 0
|
|
await page.route(url => url.pathname === '/health', async route => {
|
|
healthRequests++
|
|
if (healthRequests === 1) await route.fulfill({ status: 503, json: { error: 'starting' } })
|
|
else {
|
|
ready = true
|
|
await route.fulfill({ json: { status: 'ok' } })
|
|
}
|
|
})
|
|
await page.route(url => url.pathname === '/api/hermes/sessions', async route => {
|
|
await route.fulfill(ready
|
|
? { json: { sessions: [session] } }
|
|
: { status: 503, json: { error: 'starting' } })
|
|
})
|
|
await page.goto(`/#${path}`)
|
|
await expect(page.locator('.session-item', { hasText: 'Restored conversation' })).toBeVisible({ timeout: 15000 })
|
|
expect(healthRequests).toBeGreaterThan(1)
|
|
if (path.includes('/session/')) await expect(page).toHaveURL(/session\/restored-chat/);
|
|
})
|
|
}
|
|
|
|
test('batch-delete text appears in its confirmation popup without leaking into the sidebar', async ({ page }) => {
|
|
await authenticate(page, TEST_ACCESS_KEY, 'research')
|
|
await mockHermesApi(page, { sessions: [session] })
|
|
await mockChatSocket(page)
|
|
await page.goto('/#/hermes/chat')
|
|
await page.getByTitle('Batch selection', { exact: true }).click()
|
|
await page.locator('.session-item-checkbox').first().click()
|
|
const confirmation = 'Delete 1 selected sessions?'
|
|
await expect(page.locator('.page-sidebar-top')).not.toContainText(confirmation)
|
|
await page.getByRole('button', { name: 'Delete', exact: true }).click()
|
|
const popup = page.locator('.arco-popconfirm')
|
|
await expect(popup).toBeVisible()
|
|
await expect(popup).toContainText(confirmation)
|
|
await expect(popup.getByRole('button', { name: /cancel/i })).toBeVisible()
|
|
})
|
|
|
|
for (const path of ['/hermes/chat', '/hermes/session/restored-chat?profile=research']) {
|
|
test(`shows conversation before slow profile, settings and model requests finish: ${path}`, async ({ page }) => {
|
|
await authenticate(page, TEST_ACCESS_KEY, 'research')
|
|
await mockHermesApi(page, { sessions: [session] })
|
|
await mockChatSocket(page)
|
|
await page.addInitScript(() => {
|
|
;(window as any).__PW_CHAT_SOCKET_RESUMES__ = {
|
|
'restored-chat': { session_id: 'restored-chat', messages: [{ id: 1, role: 'user', content: 'History without waiting for profiles', timestamp: 1000 }], isWorking: false, events: [] },
|
|
}
|
|
})
|
|
let release!: () => void
|
|
const gate = new Promise<void>(resolve => { release = resolve })
|
|
await page.route(url => ['/api/hermes/profiles', '/api/hermes/config', '/api/hermes/available-models'].includes(url.pathname), async route => {
|
|
await gate
|
|
await route.fallback()
|
|
})
|
|
try {
|
|
await page.goto(`/#${path}`)
|
|
await expect(page.getByText('History without waiting for profiles', { exact: true })).toBeVisible()
|
|
} finally { release() }
|
|
})
|
|
}
|
|
|
|
test('falls back to HTTP history and offers retry after a failed load', async ({ page }) => {
|
|
await authenticate(page, TEST_ACCESS_KEY, 'research')
|
|
await mockHermesApi(page, { sessions: [session] })
|
|
await mockChatSocket(page)
|
|
let fail = true
|
|
await page.route('**/sessions/conversations/restored-chat/messages/paginated?*', async route => {
|
|
await route.fulfill(fail
|
|
? { status: 503, json: { error: 'temporarily unavailable' } }
|
|
: { json: { session, messages: [{ id: 1, role: 'user', content: 'History recovered by retry', timestamp: 1000 }], total: 1, hasMore: false } })
|
|
})
|
|
await page.goto('/#/hermes/chat')
|
|
await expect(page.getByRole('alert')).toContainText('Could not load this conversation', { timeout: 12000 })
|
|
fail = false
|
|
await page.getByRole('alert').getByRole('button', { name: 'Retry' }).click()
|
|
await expect(page.getByText('History recovered by retry', { exact: true })).toBeVisible({ timeout: 12000 })
|
|
await expect(page.getByRole('alert')).toHaveCount(0)
|
|
})
|