Merge pull request #8906 from deepseek-harness/fix/fold-blank-frame-sampling

test(web): sample fold gaps after animation frame writes
This commit is contained in:
imccyu authored and GitHub committed 2026-11-20 16:03:43 +08:00
commit f64b63fd9c
4 files changed
+65 -10

No files matched your search

@@ -21,8 +21,8 @@
en: ca6a5c372bb3cad1
zh: 1cd5028269b58c65
/agent-note-one-fold-motion-for-collapsing-on-the-next-message/testing:
en: 0423a607ee0589b5
zh: 61df892a01c5aa43
en: 6928ea8cc28112e5
zh: e9d69605558ea102
/agent-note-one-fold-motion-for-collapsing-on-the-next-message/alternatives-considered:
en: d8e1ea66e293cd93
zh: 0aaa9e693f441673
@@ -73,7 +73,7 @@ Let `start` be the scrollTop when the batch begins, `above` the height of closin
## Testing
[fold-blank-matrix.e2e.ts](../../../../apps/web/tests/fold-blank-matrix.e2e.ts) covers 19 main-Session cases and 8 right-Sidebar child cases across reader position (bottom, middle of the body, top of the body, inside the steps, previous Turn), input source (composer, Turn failing before its message is recorded, another tab, queued delivery, steer, parent message, several Turns folding at once), body length, and Standard and "On completion" controls. The layout gap is the tallest band between the scrollport top and the composer that no visible row's box covers: at most 120 px once settled, and over that for at most one animation frame. It counts boxes, so a closing row that has faded but not finished shrinking still covers its space. Tail cases assert the floor landing; reader-content-still cases assert that the reader's anchor row moves at most 2 px on screen. Short-body cases assert only that no room remains after the reply arrives.
[fold-blank-matrix.e2e.ts](../../../../apps/web/tests/fold-blank-matrix.e2e.ts) covers 19 main-Session cases and 8 right-Sidebar child cases across reader position (bottom, middle of the body, top of the body, inside the steps, previous Turn), input source (composer, Turn failing before its message is recorded, another tab, queued delivery, steer, parent message, several Turns folding at once), body length, and Standard and "On completion" controls. The layout gap is the tallest band between the scrollport top and the composer that no visible row's box covers: at most 120 px once settled, and over that for at most one animation frame. The probe reads the layout after the animation callbacks for each rendering opportunity, before paint. Identical gaps on consecutive frames count separately. It counts boxes, so a closing row that has faded but not finished shrinking still covers its space. Tail cases assert the floor landing; reader-content-still cases assert that the reader's anchor row moves at most 2 px on screen. Short-body cases assert only that no room remains after the reply arrives.
## Alternatives considered
@@ -73,7 +73,7 @@ Status: implemented
## Testing
[fold-blank-matrix.e2e.ts](../../../../apps/web/tests/fold-blank-matrix.e2e.ts) 覆盖主会话 19 例与右侧栏子会话 8 例,维度包括读者位置(底部、正文中段、正文开头、步骤中间、上一轮)、输入来源(输入框、回合在写入消息前失败、另一个标签页、排队投递、steer、父消息、一次折叠多轮)、正文长短,以及 Standard 与「完成时收起」对照。布局空洞指视口顶部到输入框之间没有任何可见行的盒子覆盖的最大连续高度:落定后不超过 120 px,动画中至多 1 帧超过。它按盒子计算,已经淡出但尚未收完的收起行仍算作覆盖。「到底部」的用例断言落到底部;「内容不动」的用例断言读者锚定行的屏幕位置变化不超过 2 px。正文很短的用例只断言回复到达后不再留空。
[fold-blank-matrix.e2e.ts](../../../../apps/web/tests/fold-blank-matrix.e2e.ts) 覆盖主会话 19 例与右侧栏子会话 8 例,维度包括读者位置(底部、正文中段、正文开头、步骤中间、上一轮)、输入来源(输入框、回合在写入消息前失败、另一个标签页、排队投递、steer、父消息、一次折叠多轮)、正文长短,以及 Standard 与「完成时收起」对照。布局空洞指视口顶部到输入框之间没有任何可见行的盒子覆盖的最大连续高度:落定后不超过 120 px,动画中至多 1 帧超过。探针在每次渲染机会的动画回调全部结束、绘制之前读取布局;相邻两帧的空洞即使相同,也分别计数。它按盒子计算,已经淡出但尚未收完的收起行仍算作覆盖。「到底部」的用例断言落到底部;「内容不动」的用例断言读者锚定行的屏幕位置变化不超过 2 px。正文很短的用例只断言回复到达后不再留空。
## Alternatives considered
+61 -6
View File
@@ -349,12 +349,22 @@ async function startTrace(page: Page, root: string): Promise<void> {
if (read === undefined) throw new Error('fold measurement is not installed')
const samples: Geometry[] = []
let frame = 0
let pending = false
const observer = new ResizeObserver(() => {
if (!pending) return
pending = false
// A scrollport or its composer can remount between rendering opportunities.
if (document.querySelector(selector)?.querySelector('[data-composer-seat]')) samples.push(read(selector))
})
const tick = (): void => {
// A scrollport can remount between frames; that frame contributes no sample.
try { samples.push(read(selector)) } catch (_remounting) { /* skip this frame */ }
// A fresh observation is delivered after *all* rAF writers, before paint, even when the root box is unchanged.
// Reading here instead can count a gap that the fold's later callback closes in the very same frame.
pending = true
observer.unobserve(document.documentElement)
observer.observe(document.documentElement)
frame = requestAnimationFrame(tick)
}
window.foldProbe = { samples, stop: () => { cancelAnimationFrame(frame) } }
window.foldProbe = { samples, stop: () => { cancelAnimationFrame(frame); observer.disconnect() } }
frame = requestAnimationFrame(tick)
}, root)
}
@@ -848,12 +858,13 @@ describe.skipIf(MODE === 'record')('web e2e: blank area after next-message foldi
try {
world = await openWorld(browser, scenario, replayDir)
const { afterFold, afterTurn, samples, anchors } = await run(world, scenario)
const transient = samples.filter(sample => sample.maxGap > BLANK_LIMIT)
const transient = samples.flatMap((sample, frame) => sample.maxGap > BLANK_LIMIT
? [{ frame, gap: Math.round(sample.maxGap), at: Math.round(sample.gapAt), collapsing: sample.collapsing }] : [])
const summary = {
id: scenario.id, landing: scenario.landing, before: samples[0] === undefined ? null : rounded(samples[0]),
afterFold: rounded(afterFold), afterTurn: rounded(afterTurn), anchors,
peakGap: Math.round(Math.max(0, ...samples.map(sample => sample.maxGap))),
framesOverLimit: transient.length, frames: samples.length,
framesOverLimit: transient.length, firstOverLimit: transient.slice(0, TRANSIENT_FRAMES + 1), frames: samples.length,
peakSpacer: Math.round(Math.max(0, ...samples.map(sample => sample.spacer))),
}
const evidence = async (): Promise<void> => {
@@ -864,7 +875,10 @@ describe.skipIf(MODE === 'record')('web e2e: blank area after next-message foldi
// Per-frame evidence is written for failures, or for every case with FOLDMX_EVIDENCE=1.
if (process.env.FOLDMX_EVIDENCE === '1') await evidence()
else onTestFailed(evidence)
if (scenario.origin === 'parent-message' || scenario.origin === 'steer') {
expect(samples.length, 'post-layout frame samples').toBeGreaterThan(0)
if (scenario.anchorFolds) {
expect.soft(samples.some(sample => sample.collapsing), 'sampled a closing row during the reader fold').toBe(true)
} else if (scenario.origin === 'parent-message' || scenario.origin === 'steer') {
expect.soft(samples.some(sample => sample.collapsing), 'a control case folds nothing').toBe(false)
}
if (scenario.roomUntilReply !== true) {
@@ -898,6 +912,47 @@ describe.skipIf(MODE === 'record')('web e2e: blank area after next-message foldi
export {}
describe('web e2e: fold blank measurement', () => {
it('counts gaps left by the frame writers, including consecutive frames with the same gap', async () => {
const browser = await chromium.launch()
try {
const page = await browser.newPage()
await page.setContent(`<div id="viewport" style="display:flex;flex-direction:column">
<div data-chat-flow-key="a" style="height:20px"></div>
<div data-chat-flow-key="b" style="height:20px"></div>
<div data-composer-seat style="height:20px"></div>
</div>`)
await page.evaluate(installMeasure)
// Register an early writer before the probe and a late writer after it, all on the browser's frame clock.
const drive = await page.evaluateHandle(() => {
const row = document.querySelector<HTMLElement>('[data-chat-flow-key="b"]')!
let active = false
let earlyFrame = 0
const early = (): void => {
if (active) row.style.marginTop = '240px'
earlyFrame = requestAnimationFrame(early)
}
earlyFrame = requestAnimationFrame(early)
return () => new Promise<void>((done) => {
active = true
const gaps = [0, 180, 180, 0]
let index = 0
const late = (): void => {
row.style.marginTop = `${gaps[index++]}px`
if (index < gaps.length) requestAnimationFrame(late)
else { cancelAnimationFrame(earlyFrame); requestAnimationFrame(() => { done() }) }
}
requestAnimationFrame(late)
})
})
await startTrace(page, '#viewport')
await drive.evaluate(start => start())
const samples = await stopTrace(page)
expect(samples.filter(sample => sample.maxGap > BLANK_LIMIT).map(sample => sample.maxGap)).toEqual([180, 180])
} finally {
await browser.close()
}
})
it('skips a band between fully transparent rows and counts a band beside a visible row', async () => {
const browser = await chromium.launch()
try {