fix(web): verify SQLite histories in browser fixtures

This commit is contained in:
liukx0205 committed 2026-11-15 01:41:29 +08:00
1 parent 34db539551
commit a1823eff02
5 files changed
+16 -32

No files matched your search

@@ -1,11 +1,5 @@
# NavScenario: first run bash to
Session file:
```text
{{sessionFile}}
```
> NavScenario: first run bash to print exactly NAVIGATION_OK, then read nav-a.md and nav-b.md using two read calls in ONE assistant message, then reply with the single word FIRST_DONE and stop.
<details><summary>3 previous messages</summary>
+3 -4
View File
@@ -17,6 +17,7 @@ import {
} from './scaffold.ts'
import { openSettings, newEnglishPage, pinBrowserClock, pinHostClock, saveFailureShot, WEB_FIXTURE_TIME } from './support.ts'
import { brandString } from '@deepseek-ai/dsh-brand'
import { sessionDir } from '../../../packages/session/session-persistence-jsonl/src/format.ts'
const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/message-actions', import.meta.url))
// Borrowed read-only: this scenario needs any settled user+assistant pair, not
@@ -464,9 +465,7 @@ describe('web e2e: message IconActions and clocks on settled history', () => {
const [header, ...events] = realizeSeedFixture(scaffold, await readFile(SEED, 'utf8'), id).trimEnd().split('\n')
.map((line): Record<string, unknown> => JSON.parse(line) as Record<string, unknown>)
expect(header?.version).toBe(3)
const projects = (await readdir(scaffold.persistenceRoot, { withFileTypes: true })).filter(entry => entry.isDirectory())
expect(projects).toHaveLength(1)
const directory = join(scaffold.persistenceRoot, projects[0]!.name, id)
const directory = sessionDir(scaffold.persistenceRoot, scaffold.workspaceCwd, id)
const predecessor = join(directory, 'session.v3.jsonl.zstd')
const createdAt = WEB_FIXTURE_TIME - 90_000
const rows = [{ ...header, id, cwd: scaffold.workspaceCwd, createdAt },
@@ -506,7 +505,7 @@ describe('web e2e: message IconActions and clocks on settled history', () => {
await expect.poll(() => row.getAttribute('aria-selected')).toBe('true')
await expect.poll(() => scaffold.ctx.agents.get(id)).toBeDefined()
await expect(scaffold.ctx.sessionPersistence.stat(id)).resolves.toMatchObject({ formatStatus: 'current' })
expect(await readdir(directory)).toContain(`session.v${SESSION_FORMAT_VERSION}.jsonl.zstd`)
expect(await readdir(directory)).not.toContain(`session.v${SESSION_FORMAT_VERSION}.jsonl.zstd`)
expect(await readFile(predecessor)).toEqual(source)
expect(forkRequests).toEqual(['/api/session/fork'])
expect(scaffold.ctx.agents.list().filter(agent => !existing.has(agent.id) && agent.id !== id)).toEqual([])
+6 -10
View File
@@ -6,7 +6,7 @@
// under the standard discipline: turn 1 produces a bash call plus two
// parallel reads in one assistant message (tool-call density for the
// trajectory ledger/timing lanes), turn 2 a markdown-rich reply.
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises'
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
import type { Browser, Page, Response } from 'playwright'
@@ -501,18 +501,14 @@ describe('web e2e: navigation & panes over a rich seeded session', () => {
await page.getByText('Session copied as Markdown.', { exact: true }).waitFor({ timeout: 30_000 })
expect(await page.evaluate(() => Number(Reflect.get(globalThis, '__dshClipboardWrites')))).toBe(1)
const sourcePath = (await scaffold.ctx.sessionPersistence.stat(brandString<SessionId>(SEED_ID)))?.location?.path
if (sourcePath === undefined) throw new Error('seeded Session has no materialized artifact location')
expect((await stat(sourcePath)).isFile()).toBe(true)
expect(sourcePath.startsWith(`${scaffold.persistenceRoot}/`)).toBe(true)
const snapshot = await scaffold.ctx.sessionPersistence.stat(brandString<SessionId>(SEED_ID))
expect(snapshot?.header.id).toBe(SEED_ID)
expect(snapshot?.location).toBeUndefined()
const markdown = await page.evaluate(() => navigator.clipboard.readText())
expect(markdown).toContain(`Session file:\n\n\`\`\`text\n${sourcePath}\n\`\`\``)
const normalized = markdown
.split(sourcePath).join('{{sessionFile}}')
.split(scaffold.workspaceCwd).join('{{cwd}}')
const normalized = markdown.split(scaffold.workspaceCwd).join('{{cwd}}')
// compareOrRefreshGolden appends its own newline; the clipboard text already ends with exactly one.
await compareOrRefreshGolden(COPY_MARKDOWN_EXPECTED, normalized.replace(/\n$/u, ''), MODE)
expect(normalized).toContain('Session file:\n\n```text\n{{sessionFile}}\n```')
expect(normalized).not.toContain('Session file:')
expect(normalized).toContain('# NavScenario: first run bash to')
expect(normalized).toContain('> NavScenario: first run bash to print exactly NAVIGATION_OK')
expect(normalized).toContain('<details><summary>3 previous messages</summary>')
+2 -5
View File
@@ -22,6 +22,7 @@ import {
} from './scaffold.ts'
import { connectFreshWorkspace, newEnglishPage, pinBrowserClock, pinHostClock, saveFailureShot, writeComposerDraft } from './support.ts'
import { brandString } from '@deepseek-ai/dsh-brand'
import { sessionDir } from '../../../packages/session/session-persistence-jsonl/src/format.ts'
const BASE_FIXTURE = fileURLToPath(new URL('../../../snapshots/web/live-interactions/session.v3.jsonl', import.meta.url))
const AVAILABLE_CHILD_EXPECTED = fileURLToPath(new URL('../../../snapshots/web/subagent-conversation/ui.expected.md', import.meta.url))
@@ -1011,10 +1012,6 @@ describe('web e2e: migration-required subagent catalog', () => {
} finally {
await parentHandle.close()
}
const projects = (await readdir(scaffold.persistenceRoot, { withFileTypes: true })).filter(entry => entry.isDirectory())
expect(projects).toHaveLength(1)
const project = projects[0]
if (project === undefined) throw new Error('parent seed has no project directory')
// Keep historical bytes on disk; seeding through the writer would migrate them before the browser opens.
for (const [id, parentSession, label, depth] of [
[childId, parentId, childLabel, 1],
@@ -1035,7 +1032,7 @@ describe('web e2e: migration-required subagent catalog', () => {
{ ...header, id, createdAt: createdAt + depth, cwd: scaffold.workspaceCwd, parentSession, origin: 'subagent', delegationDepth: depth },
...body.map((event, seq) => ({ ...event, seq, time: createdAt + depth + seq + 1 })),
]
const directory = join(scaffold.persistenceRoot, project.name, id)
const directory = sessionDir(scaffold.persistenceRoot, scaffold.workspaceCwd, id)
const path = join(directory, 'session.v3.jsonl.zstd')
const source = Buffer.concat(rows.map(row => zstdCompressSync(Buffer.from(`${JSON.stringify(row)}\n`))))
await mkdir(directory, { recursive: true })
+5 -7
View File
@@ -11,14 +11,13 @@
// are host RPCs with no model involvement, and the one session row the
// flat/hover/menu/archive scenarios need comes from a seeded fixture (the
// seeded-history seed reused verbatim — no new recording).
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises'
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { join, sep } from 'node:path'
import type { Browser, Locator, Page } from 'playwright'
import { chromium } from 'playwright'
import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
import type { SessionId } from '@deepseek-ai/dsh-session'
import { logPath } from '../../../packages/session/session-persistence-jsonl/src/format.ts'
import {
acknowledgeReloadConnectionLoss, assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
launchWebScaffold, readPersistedEvents, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
@@ -255,9 +254,8 @@ describe('web e2e: workspace management (create / rename / grouping / hover affo
.map(snapshot => snapshot.header)
.find(candidate => candidate.id === SEED_ID)
if (header === undefined) throw new Error('seeded Session log disappeared before deletion')
const seededLogPath = logPath(scaffold.persistenceRoot, header.cwd, header.id, 'zstd')
expect(await readFile(join(scaffold.workspaceCwd, 'workspace', 'a.txt'), 'utf8')).toBe('alpha\n')
await stat(seededLogPath)
await expect(scaffold.ctx.sessionPersistence.stat(header.id)).resolves.toBeDefined()
// The attachment stream can lag the Host commit while New Session is
// already visible. A row count or position cannot identify the seed.
@@ -303,7 +301,7 @@ describe('web e2e: workspace management (create / rename / grouping / hover affo
{ timeout: 10_000 },
).toBe(1)
expect(await readFile(join(scaffold.workspaceCwd, 'workspace', 'a.txt'), 'utf8')).toBe('alpha\n')
await stat(seededLogPath)
await expect(scaffold.ctx.sessionPersistence.stat(header.id)).resolves.toBeDefined()
expect((await readPersistedEvents(scaffold, brandString<SessionId>(SEED_ID))).length).toBeGreaterThan(0)
// Re-registering the exact deleted path immediately, without a reload, is
@@ -327,7 +325,7 @@ describe('web e2e: workspace management (create / rename / grouping / hover affo
await expect.poll(() => page.getByText('Ungrouped', { exact: true }).count(), { timeout: 10_000 })
.toBeGreaterThanOrEqual(1)
expect(await readFile(join(scaffold.workspaceCwd, 'workspace', 'a.txt'), 'utf8')).toBe('alpha\n')
await stat(seededLogPath)
await expect(scaffold.ctx.sessionPersistence.stat(header.id)).resolves.toBeDefined()
// Restore the deleted-registry state so reload still verifies deletion
// persistence independently of the successful re-registration above.
@@ -350,7 +348,7 @@ describe('web e2e: workspace management (create / rename / grouping / hover affo
).toBe(1)
expect(scaffold.ctx.workspaceRegistry.get(workspace.id)).toBeUndefined()
expect(await readFile(join(scaffold.workspaceCwd, 'workspace', 'a.txt'), 'utf8')).toBe('alpha\n')
await stat(seededLogPath)
await expect(scaffold.ctx.sessionPersistence.stat(header.id)).resolves.toBeDefined()
expect((await readPersistedEvents(scaffold, brandString<SessionId>(SEED_ID))).length).toBeGreaterThan(0)
expect(transientSlotErrors).toEqual([])