ui / scripts / virtual-log-scroll.test.tsmain at d68d7e1
// Browser scroll-stability threshold test for VirtualLog (scripts/check-virtual-log-scroll.ts).
// Runs in real headless Chromium with wheel events across the four failure modes:
// boundary-merging prepends at scrollTop 0, late reflows during backward scroll, idle prepend at
// top, all-4px pages, and mixed 4px/2,000px pages.
import { resolve } from "node:path";
import { expect, test } from "vitest";
import {
findChromium,
runScrollStabilityCheck,
type ScenarioSpec,
} from "./check-virtual-log-scroll.ts";
const REPO_ROOT = resolve(import.meta.dirname, "..");
const THRESHOLD_SCENARIOS: ScenarioSpec[] = [
{
name: "small-pages-boundary-merge",
query:
"totalRows=200&initialRows=22&pageSizes=4,7,3,12,17,5,9&pageDelayMs=400&mergeBoundary=1&lateReflow=0",
scrollMs: 3_500,
speedPxPerSec: 2_000,
},
{
name: "mid-list-mixed-and-reflow",
query:
"totalRows=240&initialRows=240&pageSizes=10&pageDelayMs=400&mergeBoundary=0&lateReflow=1",
scrollMs: 2_800,
speedPxPerSec: 2_500,
},
{
name: "idle-at-top-page-lands",
query:
"totalRows=120&initialRows=22&pageSizes=5,3,15,40&pageDelayMs=300&mergeBoundary=1&lateReflow=0",
scrollMs: 900,
speedPxPerSec: 3_000,
idleAtTopMs: 1_400,
},
{
name: "tiny-4px-and-2000px-pages",
query:
"totalRows=200&initialRows=22&pageSizes=3,1,30,8&pageDelayMs=300&mergeBoundary=1&lateReflow=1",
scrollMs: 3_000,
speedPxPerSec: 2_000,
},
{
name: "context-day-lines-raf",
query:
"totalRows=1200&initialRows=85&pageSizes=70,116,47,50,170&pageDelayMs=400&dayLines=1&parseBusyMs=50",
scrollMs: 3_000,
speedPxPerSec: 2_000,
driver: "scrollTop",
},
{
name: "context-day-lines-at-top",
query: "totalRows=600&initialRows=35&pageSizes=57,70,47&pageDelayMs=700&dayLines=1",
scrollMs: 900,
speedPxPerSec: 3_000,
idleAtTopMs: 1_200,
},
];
const hasChromium = findChromium() !== null;
test.runIf(hasChromium)(
"VirtualLog keeps visible rows still (0 jumps > 2 px) while scrolling up and prepending older pages",
{ timeout: 60_000 },
async () => {
const results = await runScrollStabilityCheck(REPO_ROOT, THRESHOLD_SCENARIOS);
for (const r of results) {
// A JUMP IS A ROW THAT MOVED ON THE SCREEN. The check also lists a wheel tick that the list
// swallowed (the row stood still, `dTop` 0): that depends on the frame a tick lands in, and
// came in one run of three on a busy host, so it is in the check's output and not a failure
// here. Frame times and long tasks are the host's load as much as the list's: the check
// prints them, this test does not hold them.
const moved = r.visualJumpSamples.filter((sample) => Math.abs(sample.dTop) > 2);
const detail = `${r.name}: ${JSON.stringify(moved)}`;
expect(r.frames, `${r.name}: rendered frames`).toBeGreaterThan(30);
expect(moved.length, detail).toBe(0);
expect(r.anchorLost, `${r.name}: anchor lost`).toBe(0);
expect(r.cls, `${r.name}: layout shift`).toBe(0);
}
},
);