mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-12-04 20:01:34 -05:00
* perf(client-ui-stats): add a PTC fold and publication diagnostic One root run_code call dispatching 1,000 to 10,000 settled subcalls reports the Statistics fold, the first and repeated Code-Mode publication, and the live assembler window. Threshold-free, outside every CI lane. * perf(client-ui-stats): fold tool calls into Context-private indexes Every event copied the growing call and dispatch-start records, so one Code-Mode root call with n nested dispatches cost O(n^2). The four fold collections are Maps the Context mutates in place now, and update() returns the same State. The call list stops sorting the whole index: a Context receives its matches in ascending seq, so insertion order is the order the table lists. * perf(client-ui-stats): publish only the bounded Code-Mode prefix The Code-Mode node rebuilt every step metric, including a sort of every dispatch, for each settle, though it publishes at most 12 rows. It now materializes that prefix from the index, republishes the node it already published while the prefix is unchanged, and coalesces publications to one per frame. Targeted snapshot updates skip the rebuild when every upserted node is the published one. * docs(client-ui-stats): record the linear Statistics fold Agent Note for the in-place call index, the bounded Code-Mode prefix, the retention bound, and the publication cadence, with the measured before and after table. * fix(client-ui-stats): reuse the node the Assembler already holds The Code-Mode Definition kept its own module-level WeakMap of published nodes, keyed by State. The Assembler already stores each Context's last published node in `context.current`, which is where the Chat Definition reads it, so the extra cache hid state ownership for nothing. It also missed in two reachable cases: a failed dispatch returns a fresh State, and `callList` rebuilds every row past the step text budget as a truncated copy, so an unchanged prefix arrived as fresh objects and the reference comparison failed. The snapshot rebuild the cache was meant to skip then ran anyway. Read `context.current` instead and compare rows field by field. Edited the publication comment to state the real cadence: the Assembler materializes an `animation-frame` publication after three frames. * docs(notes): correct the Statistics fold note against the code Three statements did not match what shipped. The scalar counters the retention bound leaves alone are `toolPairs`, `toolMs`, `toolOpen`, and `toolMissing`, not `pairs`/`ms`/`open`/`missing`, and they are written by the native `tool/call` and `tool/result` branches rather than by the dispatch branch; only `tools` and `toolErrors` count every dispatch. The retained records are the first `CALL_LIMIT` displayable dispatches, not the first `CALL_LIMIT` dispatches, so a nested runner no longer takes a slot. The publication cadence is three animation frames, not one. * test(scripts): expect the Statistics diagnostic in the perf inventory The manual `test:web:perf` inventory is pinned item by item, and the new `client-ui-stats` entry left the expectation behind, so the required coverage partition failed on it. --------- Co-authored-by: imccyu <[email protected]>
86 lines
3.6 KiB
TypeScript
86 lines
3.6 KiB
TypeScript
import { existsSync } from 'node:fs'
|
|
import { resolve } from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
WEB_SNAPSHOT_SERIAL_FILES,
|
|
WEB_SNAPSHOT_SLICE_COUNTS,
|
|
ownsWebSnapshotSerialFiles,
|
|
parseWebSnapshotShard,
|
|
sliceOfTest,
|
|
sliceProjectName,
|
|
webSnapshotProjects,
|
|
} from './web-snapshot-projects.ts'
|
|
|
|
describe('web snapshot test slices', () => {
|
|
it('assigns tests to slices round-robin by depth-first index', () => {
|
|
expect(Array.from({ length: 7 }, (_, index) => sliceOfTest(index, 3))).toEqual([1, 2, 3, 1, 2, 3, 1])
|
|
})
|
|
|
|
it('names one project per slice by file stem', () => {
|
|
expect(sliceProjectName('apps/web/tests/document-preview.e2e.ts', 2)).toBe('web-slice:document-preview:2')
|
|
})
|
|
|
|
// The slice setup file checks at runtime that each slice receives a test.
|
|
it('plans only existing, non-serial files, each with at least two slices', () => {
|
|
const plans = Object.entries(WEB_SNAPSHOT_SLICE_COUNTS)
|
|
|
|
expect(plans.length).toBeGreaterThan(0)
|
|
for (const [file, count] of plans) {
|
|
expect(existsSync(file), file).toBe(true)
|
|
expect(WEB_SNAPSHOT_SERIAL_FILES, file).not.toContain(file)
|
|
expect(Number.isSafeInteger(count) && count >= 2, file).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('runs each sliced file only in its slice projects', () => {
|
|
const projects = webSnapshotProjects(['apps/web/tests/**/*.e2e.ts'], ['**/node_modules/**'])
|
|
const main = projects.find(project => project.test.name === 'web')
|
|
|
|
for (const [file, count] of Object.entries(WEB_SNAPSHOT_SLICE_COUNTS)) {
|
|
expect(main?.test.exclude, file).toContain(file)
|
|
const slices = projects.filter(project => project.test.include.includes(file)).map(project => project.test.name)
|
|
expect(slices, file).toEqual(Array.from({ length: count }, (_, index) => sliceProjectName(file, index + 1)))
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('web snapshot shards', () => {
|
|
it('parses an in-range shard', () => {
|
|
expect(parseWebSnapshotShard('1/2')).toEqual({ index: 1, count: 2 })
|
|
expect(parseWebSnapshotShard('2/2')).toEqual({ index: 2, count: 2 })
|
|
})
|
|
|
|
it.each(['3/2', '0/2', 'a/b'])('rejects shard %s', (raw) => {
|
|
expect(() => parseWebSnapshotShard(raw)).toThrow(
|
|
`DSH_WEB_SNAPSHOT_SHARD must be <index>/<count> with 1 <= index <= count, got ${JSON.stringify(raw)}.`,
|
|
)
|
|
})
|
|
|
|
it('runs the whole pool and the serial files when unset', () => {
|
|
expect(parseWebSnapshotShard(undefined)).toBeUndefined()
|
|
expect(parseWebSnapshotShard('')).toBeUndefined()
|
|
expect(ownsWebSnapshotSerialFiles(undefined)).toBe(true)
|
|
})
|
|
|
|
it('runs the serial files only in the last shard', () => {
|
|
expect(ownsWebSnapshotSerialFiles({ index: 1, count: 2 })).toBe(false)
|
|
expect(ownsWebSnapshotSerialFiles({ index: 2, count: 2 })).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('web perf inventory', () => {
|
|
it('collects only the perf files, without the browser lane projects or sequencer', async () => {
|
|
// A runtime URL keeps the root Vitest configs outside the scripts type program.
|
|
const perfConfigUrl = pathToFileURL(resolve(import.meta.dirname, '../vitest.web.perf.config.ts')).href
|
|
const { default: webPerfConfig } = await import(perfConfigUrl) as { default: { test?: Record<string, unknown> } }
|
|
expect(webPerfConfig.test).not.toHaveProperty('projects')
|
|
expect(webPerfConfig.test).not.toHaveProperty('sequence')
|
|
expect(webPerfConfig.test?.include).toEqual([
|
|
'apps/web/tests/**/*.perf.ts',
|
|
'packages/client/ui-conversation/tests/**/*.perf.client.ts',
|
|
'packages/experimental/client-ui-stats/tests/**/*.perf.client.ts',
|
|
])
|
|
})
|
|
})
|