test(e2e): poll for visible Monaco diff line before clicking

clickVisibleDiffLine read Monaco's virtualized .view-line set in a single
evaluate right after a tab switch, but Monaco re-lays-out its diff lines
asynchronously. On a contended CI shard the visible set is briefly empty, so
the evaluate threw 'visible combined diff line not found' before Monaco
painted. Poll until a line is in the viewport instead of failing on first miss.

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Neil
2026-07-05 21:09:08 -07:00
co-authored by Orca
parent 546a416d54
commit 3c3c064f50
+43 -27
View File
@@ -329,34 +329,50 @@ function getLargestBackwardScrollJump(samples: readonly ScrollProbeSample[]): nu
}
async function clickVisibleDiffLine(page: Page): Promise<void> {
const linePoint = await page.evaluate(() => {
const container = document.querySelector<HTMLElement>('.combined-diff-scroll-container')
if (!container) {
throw new Error('combined diff scroll container not found')
}
const containerRect = container.getBoundingClientRect()
const visibleLine = Array.from(
container.querySelectorAll<HTMLElement>('.monaco-diff-editor .view-line')
).find((line) => {
const rect = line.getBoundingClientRect()
return (
rect.height > 0 &&
rect.bottom > containerRect.top &&
rect.top < containerRect.bottom &&
rect.right > containerRect.left &&
rect.left < containerRect.right
)
})
if (!visibleLine) {
throw new Error('visible combined diff line not found')
}
const rect = visibleLine.getBoundingClientRect()
return {
x: rect.left + Math.min(12, Math.max(1, rect.width / 2)),
y: rect.top + rect.height / 2
}
})
// Why: after a tab switch Monaco re-lays-out its virtualized diff lines
// asynchronously, so the visible .view-line set is briefly empty on a loaded
// CI runner. Poll until a line is painted in the viewport instead of reading
// it once and throwing on the first miss.
let linePoint: { x: number; y: number } | null = null
await expect
.poll(
async () => {
linePoint = await page.evaluate(() => {
const container = document.querySelector<HTMLElement>('.combined-diff-scroll-container')
if (!container) {
return null
}
const containerRect = container.getBoundingClientRect()
const visibleLine = Array.from(
container.querySelectorAll<HTMLElement>('.monaco-diff-editor .view-line')
).find((line) => {
const rect = line.getBoundingClientRect()
return (
rect.height > 0 &&
rect.bottom > containerRect.top &&
rect.top < containerRect.bottom &&
rect.right > containerRect.left &&
rect.left < containerRect.right
)
})
if (!visibleLine) {
return null
}
const rect = visibleLine.getBoundingClientRect()
return {
x: rect.left + Math.min(12, Math.max(1, rect.width / 2)),
y: rect.top + rect.height / 2
}
})
return linePoint !== null
},
{ timeout: 10_000, message: 'visible combined diff line not found' }
)
.toBe(true)
if (!linePoint) {
throw new Error('visible combined diff line not found')
}
await page.mouse.click(linePoint.x, linePoint.y)
}