Files
shumai/apps/web/e2e/tests/team/agent-session-logs.spec.ts
Yiling-J 35a0e82284 refactor(agent)!: migrate to Pi Durable and embed the agent queue (#525)
* refactor(agent)!: migrate sessions to Pi Durable

Replace patched AgentHarness storage with per-session SQLite and PostgreSQL commit mirroring. Migrate legacy history automatically and run agent queues with the main server.

BREAKING CHANGE: Remove standalone agent workers and return native Pi entry records from chat history APIs.

* fix(agent): constrain session log dialog scrolling

Keep the header visible and wrap long output while log entries and expanded records scroll within the dialog. Cover desktop and narrow viewports through the dashboard Sessions flow.

* fix(agent): hide entry IDs from session log card headers

Retain internal entry IDs in expanded raw records for debugging. Verify that card headers omit the IDs while raw JSON preserves them.

* test(e2e): handle browser wheel limits in session log checks

Verify that a normal wheel event moves the viewport before explicitly scrolling to the final record. Keep the dialog bounds, fixed header, wrapping, and expanded-record assertions.

* fix(agent): select model providers without inheriting unrelated auth

* fix(webui): prevent resize feedback when toggling agent panel

* test(agent): reproduce concurrent comment session races

* fix(agent): serialize comment sessions and deduplicate history

* docs(changelog): consolidate Pi Durable changes into one entry
2026-11-11 16:05:18 +08:00

126 lines
4.1 KiB
TypeScript

import { expect, test } from '../../fixtures'
test('session logs stay within the dialog and scroll through long messages and expanded records', async ({
owner,
prisma,
}) => {
const { page, teamId, email } = owner
const user = await prisma.user.findUniqueOrThrow({ where: { email } })
const agentUser = await prisma.user.create({
data: { name: 'Session Logs Agent', email: 'session-logs@shumai.test', type: 'agent' },
})
const agent = await prisma.agent.create({
data: {
id: agentUser.id,
teamId,
type: 'chat',
enabled: false,
config: { provider: 'test', model: 'test' },
},
})
const session = await prisma.agentSession.create({
data: {
agentId: agent.id,
userId: user.id,
type: 'chat',
name: 'Scrollable Session Logs',
cwd: '/test',
},
})
await prisma.agentSessionCommit.create({
data: {
sessionId: session.id,
seq: 1n,
data: {
version: 1,
writes: [
{ type: 'conversation', value: { id: 1 } },
...Array.from({ length: 30 }, (_, index) => ({
type: 'entry',
value: {
id: index + 2,
conversationId: 1,
kind: 'pi.user',
model: [
{
role: 'user',
content: `Log message ${index + 1}\n\n\`\`\`text\n${'unbroken_output_'.repeat(100)}\n\`\`\``,
timestamp: Date.now(),
},
],
data: { output: 'raw_output_'.repeat(100) },
},
})),
],
},
},
})
await page.goto(`/teams/${teamId}/dashboard`)
await page.getByRole('button', { name: /^(Sessions|会话)$/ }).click()
await page.getByRole('row').filter({ hasText: session.name! }).click()
const dialog = page.getByRole('dialog')
await expect(dialog.getByText('Log message 1', { exact: true })).toBeVisible()
await expect(dialog.getByText(/^(Entry ID|条目 ID):/)).toHaveCount(0)
const viewport = dialog.locator('[data-slot="scroll-area-viewport"]')
const heading = dialog.getByRole('heading')
for (const size of [
{ width: 1280, height: 800 },
{ width: 390, height: 640 },
]) {
await page.setViewportSize(size)
await dialog.evaluate(async (element) => {
await Promise.all(element.getAnimations().map((animation) => animation.finished))
})
await expect
.poll(async () => {
return dialog.evaluate((element) => {
const bounds = element.getBoundingClientRect()
return (
bounds.top >= 0 &&
bounds.bottom <= window.innerHeight &&
bounds.left >= 0 &&
bounds.right <= window.innerWidth
)
})
})
.toBe(true)
await expect
.poll(() =>
viewport.evaluate(
(element) =>
element.clientHeight > 0 &&
element.scrollHeight > element.clientHeight &&
element.scrollWidth <= element.clientWidth,
),
)
.toBe(true)
const headerTop = (await heading.boundingBox())!.y
await viewport.evaluate((element) => {
element.scrollTop = 0
})
await viewport.hover()
// Wheel events may be capped; verify movement before jumping to the final record.
await page.mouse.wheel(0, 400)
await expect.poll(() => viewport.evaluate((element) => element.scrollTop)).toBeGreaterThan(0)
const record = dialog.locator('details').last()
await viewport.evaluate((element) => {
element.scrollTop = element.scrollHeight
})
await expect(record.locator('summary')).toBeInViewport()
expect((await heading.boundingBox())!.y).toBeCloseTo(headerTop, 0)
await record.locator('summary').click()
await viewport.evaluate((element) => {
element.scrollTop = element.scrollHeight
})
await expect(record.locator('pre')).toBeInViewport()
await expect(record.locator('pre')).toContainText('"id": 31')
expect(await viewport.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(
true,
)
await record.locator('summary').click()
}
})