Give durable user context its producer-owned source kind instead of a generic plugin wrapper. The V3-to-V4 conversion preserves the frozen rename and collision rules, all own JSON metadata, event coordinates, and historical request-only kinds. Native catalog and JSONL admission retain source validation so unknown attribution can survive without its producer while malformed owned sources are refused. Use an explicit user-only RequestUserInput for auxiliary LLM prompts that do not own durable message identity. Auto Review and compaction remove their request-only source registrations while retaining prompt content and freezing; provider serializers and projections keep the same wire data, assistant replay isolation, image ordering, and tool correlation. Session writes, Agent delivery, and recorded title requests continue to require identified durable messages. Bind the saved compatibility policy only to user sources and qualify tmux location attribution without weakening fixed system, model, or tool semantics. Rebuild the current inventory and unpublished V4 acknowledgement on the actual tool-role parent, preserving its rationale and all accepted historical records. The catalog format version records tooling metadata; Session remains V4. Developer-role policy and activation belong to their own feature. The latest-master Messages adapter, serialization, request-input typing, EpochHeader reservation, and attribution checks pass 103 tests across five files. The retained V3 Messages input-history snapshot passes through the source profile; Host/Client typechecks and all 41 documentation gates pass. The generated comparison records four changed roots and 447 unchanged type fingerprints. Latest-master ARIA changes are retained, with producer source labels applied independently; new Messages fixtures retain their producer names as declared source kinds and use the fixed system-message helper; recorded Session generations are unchanged by this regrouping. Co-authored-by: Tianyi Cui <[email protected]>
152 lines
6.6 KiB
TypeScript
152 lines
6.6 KiB
TypeScript
// Web e2e scenario: full-session stats over paged history. A deterministic
|
|
// 28-turn log (56 chat messages — more than one 50-message history page)
|
|
// seeded cold through the REAL persistence API must render whole-log turn/step
|
|
// counts from the sessionStats projection on first open, and loading the
|
|
// older page must NOT change them. This pins the bug the projection fixed:
|
|
// the pre-projection window fold recounted per loaded page, so 加载更早 grew
|
|
// the counter. Zero model calls; the seed is generated, not recorded, because
|
|
// no line of it is model output.
|
|
import { fileURLToPath } from 'node:url'
|
|
import type { Browser, Page } from 'playwright'
|
|
import { chromium } from 'playwright'
|
|
import { createSystemMessage } from '@deepseek-ai/dsh-llm'
|
|
import { SESSION_FORMAT_VERSION } from '@deepseek-ai/dsh-session'
|
|
import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
|
|
import {
|
|
assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
|
|
launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
|
|
} from './scaffold.ts'
|
|
import { newEnglishPage, saveFailureShot } from './support.ts'
|
|
|
|
const SNAPSHOT_DIR = fileURLToPath(new URL('./expected/stats-paged-history', import.meta.url))
|
|
const UI_EXPECTED = fileURLToPath(new URL('./expected/stats-paged-history/ui.expected.md', import.meta.url))
|
|
const MODE = webSnapshotMode()
|
|
const SEED_ID = 'stats-paged-history-web-e2e'
|
|
|
|
/** Turn count: 2 chat messages per turn, so 28 turns overflow one 50-message page. */
|
|
const TURNS = 28
|
|
const FULL_COUNTS = `${TURNS} turns ${TURNS} steps`
|
|
|
|
/**
|
|
* Generate the seed: TURNS closed single-step turns of one short user prompt
|
|
* and one short assistant reply each. Fixed times pin displayed dates;
|
|
* the empty system head precedes every user message in the current format.
|
|
* @param turns - closed turns to generate.
|
|
* @returns session.jsonl text for {@link seedSession}.
|
|
*/
|
|
function buildSeed(turns: number): string {
|
|
const lines = [JSON.stringify({
|
|
type: 'session', version: SESSION_FORMAT_VERSION, id: '{{sessionId}}',
|
|
createdAt: 1784974100000, cwd: '{{cwd}}/workspace', isSeeded: false, delegationDepth: 0,
|
|
})]
|
|
let seq = 0
|
|
let time = 1784974100000
|
|
const at = (event: Record<string, unknown>): void => {
|
|
lines.push(JSON.stringify({ ...event, seq: seq++, time: time++ }))
|
|
}
|
|
for (let turn = 1; turn <= turns; turn++) {
|
|
at({ type: 'turn/start', data: { turn } })
|
|
at({ type: 'step/start', data: { turn, step: 1 } })
|
|
if (turn === 1) {
|
|
at({
|
|
type: 'system/message',
|
|
data: { turn, step: 1, message: createSystemMessage('') },
|
|
surfaceOp: 'append',
|
|
})
|
|
}
|
|
at({
|
|
type: 'user/message',
|
|
data: {
|
|
id: `00000000-0000-4000-9000-${String(turn).padStart(12, '0')}`,
|
|
role: 'user',
|
|
content: [{ type: 'text', text: `m${turn}` }],
|
|
source: { kind: 'user' },
|
|
},
|
|
surfaceOp: 'append',
|
|
})
|
|
at({
|
|
type: 'assistant/message',
|
|
data: {
|
|
stream: [],
|
|
turn,
|
|
step: 1,
|
|
message: {
|
|
id: `00000000-0000-4000-8000-${String(turn).padStart(12, '0')}`,
|
|
role: 'assistant',
|
|
content: [{ type: 'text', text: `r${turn}` }],
|
|
source: { kind: 'model', provider: 'snapshot', model: 'snapshot-replier' },
|
|
},
|
|
},
|
|
surfaceOp: 'append',
|
|
})
|
|
at({ type: 'step/end', data: { turn, step: 1 } })
|
|
at({ type: 'turn/end', data: { turn, reason: { kind: 'completed' } } })
|
|
}
|
|
return `${lines.join('\n')}\n`
|
|
}
|
|
|
|
describe('web e2e: whole-session stats survive history paging', () => {
|
|
let scaffold: WebScaffold
|
|
let browser: Browser
|
|
let page: Page
|
|
let tripwire: ReturnType<typeof watchConsole>
|
|
|
|
beforeAll(async () => {
|
|
if (MODE === 'record') throw new Error('stats-paged-history is a keyless assembled snapshot')
|
|
scaffold = await launchWebScaffold({})
|
|
await seedSession(scaffold, buildSeed(TURNS), SEED_ID)
|
|
browser = await chromium.launch()
|
|
page = await newEnglishPage(browser)
|
|
tripwire = watchConsole(page)
|
|
await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
|
|
await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
|
|
}, 120_000)
|
|
|
|
afterAll(async () => {
|
|
await browser?.close()
|
|
await scaffold?.close()
|
|
})
|
|
|
|
it('renders full-session counts on the partial tail page and keeps them across load-older', async () => {
|
|
onTestFailed(() => saveFailureShot(page, 'web-e2e-stats-paged'))
|
|
const groupRow = page.locator('[role="treeitem"]').first()
|
|
await groupRow.waitFor({ timeout: 15_000 })
|
|
await groupRow.click()
|
|
const sessionRow = page.locator('[role="treeitem"]').nth(1)
|
|
await sessionRow.waitFor({ timeout: 10_000 })
|
|
await sessionRow.click()
|
|
// Settled barrier: the newest recorded reply renders from the tail page.
|
|
await expect.poll(() => page.getByText(`r${TURNS}`, { exact: true }).count(), { timeout: 15_000 }).toBe(1)
|
|
// The tail page is partial (56 messages > one 50-message page): the first
|
|
// turns are NOT loaded, yet the strip already reports the whole log —
|
|
// the sessionStats projection, not the window fold.
|
|
expect(await page.getByText('m1', { exact: true }).count()).toBe(0)
|
|
await expect.poll(() => page.getByText(FULL_COUNTS, { exact: false }).count(), { timeout: 10_000 }).toBe(1)
|
|
const strip = page.getByText(FULL_COUNTS, { exact: false }).locator('..')
|
|
const stripBeforePaging = await strip.textContent()
|
|
|
|
// 加载更早: prepending the older page must not move ANY strip figure —
|
|
// counts, wall times, or token groups.
|
|
await page.getByRole('button', { name: 'Load earlier' }).click()
|
|
await expect.poll(() => page.getByText('m1', { exact: true }).count(), { timeout: 10_000 }).toBe(1)
|
|
expect(await strip.textContent()).toBe(stripBeforePaging)
|
|
// With the whole log loaded, the window mounts one turn-tail footer per
|
|
// settled turn — the loaded-window probe the scroll/perf lanes count now
|
|
// that the strip is whole-log-scoped.
|
|
expect(await page.locator('[data-chat-flow-key^="9:turn-tail"]').count()).toBe(TURNS)
|
|
}, 60_000)
|
|
|
|
it('matches the paged-stats aria golden', async () => {
|
|
onTestFailed(() => saveFailureShot(page, 'web-e2e-stats-paged-aria'))
|
|
const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
|
|
.split(SEED_ID).join('{{seededId}}')
|
|
await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
|
|
})
|
|
|
|
it('issued zero model calls and stayed clean', async () => {
|
|
expect(tripwire.pageErrors).toEqual([])
|
|
expect(tripwire.warnings).toEqual([])
|
|
await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
|
|
})
|
|
})
|