test(e2e): measure the folder-archive flow in the perf audit

This commit is contained in:
Menghuan1918 committed 2026-10-30 02:14:40 +08:00
1 parent 0e643852c3
commit bd6cfa55b4
2 files changed
+33 -1

No files matched your search

+4 -1
View File
@@ -55,8 +55,10 @@
| `GET /sidebar/file`(1.5 MB) | 5–7 ms | 1.55 MB |
| `GET /sidebar/file`(md) | 2 ms | 1.7 KB |
| `GET /sidebar/html`(带 css/js) | 2–3 ms | 147 B(资源由同路由按需再取) |
| `POST /sidebar/upload` 1 MB | 30–31 ms | — |
| `POST /sidebar/upload` 1 MB | 28–31 ms | — |
| `POST /sidebar/write` 200 KB | 3–5 ms | — |
| `archive.build` → `archive.status` → `GET /sidebar/archive`(40 文件) | 59 ms | 4.3 KB |
| 同上(5,000 文件) | 163 ms | 544 KB |
## 四、成本与判断
@@ -79,6 +81,7 @@
- 真机移动端。
- 任务页 / 侧边对话在**有真实 job / 模型回复**时的渲染:keyless lane 里只有空状态(接口耗时已单独记录)。
- 设置页 UI(宿主设置对话框 + 插件的侧边卡片分组):只测了 `settings.get`;插件在该页只挂一个导航图标与一组卡片。
- 写操作与推送通道没有单独计时:`git.stage/unstage/commit/push`、`teams.*`、`sidechat.prompt/dequeue/cancel`、three `/sidebar/ws/*` 通道(它们的读取侧与页面流已覆盖;写操作都是既有 git/文件系统调用的薄包装)。
- 长时间运行的内存曲线:`performance.memory` 在 Chromium 中被量化(多轮恒为 45 MB),不能作为泄漏证据,需要 CDP heap snapshot,本轮未做。
- 多用户/远程(`dsh-remote`)场景的网络延迟。
+29
View File
@@ -455,5 +455,34 @@ test('audit: heavy routes', async ({ page }) => {
sessionId, path: abs('written-audit.txt'), cwd: WORKSPACE,
}).toString(), { kind: 'text', text: 'z'.repeat(200 * 1024) })
/** The tree's "download" flow: build (async) → poll → stream the bytes. */
const archiveDir = async (label: string, dir: string): Promise<void> => {
const timing = await page.evaluate(async (target) => {
const post = async (method: string, payload: unknown): Promise<Response> => fetch('/sidebar/api/' + method, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(payload),
})
const started = performance.now()
const build = await post('archive.build', { sessionId: target.sessionId, paths: [target.dir], name: 'audit' })
const built = await build.json() as { value?: { id?: string } }
const id = built.value?.id
if (id === undefined) return { ms: Math.round(performance.now() - started), status: build.status, bytes: 0, error: 'no id' }
let state = 'building'
while (state === 'building' && performance.now() - started < 120_000) {
await new Promise(resolve => setTimeout(resolve, 50))
const status = await post('archive.status', { sessionId: target.sessionId, id })
const body = await status.json() as { value?: { state?: string } }
state = body.value?.state ?? 'error'
}
const download = await fetch('/sidebar/archive?' + new URLSearchParams({ sessionId: target.sessionId, id }))
const bytes = (await download.arrayBuffer()).byteLength
return { ms: Math.round(performance.now() - started), status: download.status, bytes, state }
}, { dir, sessionId })
results.push({ label, ...timing })
}
await archiveDir('archive d00 (40 files)', WORKSPACE + '/d00')
await archiveDir('archive many (5,000 files)', WORKSPACE + '/many')
console.log(`AUDIT_JSON ${JSON.stringify({ metric: 'heavy-routes', results })}`)
})