Skip to content

Commit 299670e

Browse files
fix: stop two merge-queue flakes in the history prune and timeline tests (#4786)
* test(studio-server): history prune tests allow a file time a moment past Date.now() * ci: temporary probe for the history prune test flake * fix(studio): timeline scroll-end timer no longer fires after unmount * ci: remove the temporary history prune probe * test(studio): check the virtualizer teardown with a spy and a 200 ms wait
1 parent 7b0ec69 commit 299670e

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

‎bun.lock‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/studio-server/src/history/pruneHistories.test.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ function tempDir(prefix: string): string {
3131
}
3232

3333
const DAY_MS = 24 * 60 * 60 * 1000;
34+
// Date.now() rounds down to the millisecond; a file written in that millisecond can carry a later mtime.
35+
const pastKeepWindow = () => Date.now() + 1 + KEEP_GONE_PROJECT_HISTORY_MS;
3436

3537
async function projectWithHistory(
3638
historyRoot: string,
@@ -105,7 +107,7 @@ describe("pruneGoneProjectHistories", () => {
105107
expect(await prunedIds(historyRoot, { ...elsewhere, now: Date.now() + 13 * DAY_MS })).toEqual(
106108
[],
107109
);
108-
expect(await prunedIds(historyRoot, { ...elsewhere, now: Date.now() + 14 * DAY_MS })).toEqual([
110+
expect(await prunedIds(historyRoot, { ...elsewhere, now: pastKeepWindow() })).toEqual([
109111
gone.id,
110112
]);
111113
});
@@ -178,7 +180,7 @@ describe("pruneGoneProjectHistories", () => {
178180

179181
chmodSync(locked, 0o000);
180182
try {
181-
const later = Date.now() + KEEP_GONE_PROJECT_HISTORY_MS;
183+
const later = pastKeepWindow();
182184
const onError = (error: unknown) => errors.push(error);
183185
expect(await prunedIds(historyRoot, { now: later, onError })).toEqual([gone.id]);
184186
} finally {
@@ -206,7 +208,7 @@ describe("pruneGoneProjectHistories", () => {
206208
rmSync(join(mountPoint.projectDir, ".hyperframes"), { recursive: true, force: true });
207209
rmSync(dirname(deleted.projectDir), { recursive: true, force: true });
208210

209-
const later = Date.now() + KEEP_GONE_PROJECT_HISTORY_MS;
211+
const later = pastKeepWindow();
210212
expect(await prunedIds(historyRoot, { tempDir: historyRoot, now: later })).toEqual([
211213
deleted.id,
212214
]);
@@ -227,7 +229,7 @@ describe("pruneGoneProjectHistories", () => {
227229
rmSync(folderGone.projectDir, { recursive: true, force: true });
228230
rmSync(dirname(parentGone.projectDir), { recursive: true, force: true });
229231

230-
const later = Date.now() + KEEP_GONE_PROJECT_HISTORY_MS;
232+
const later = pastKeepWindow();
231233
expect(await prunedIds(historyRoot, { tempDir: historyRoot, now: later })).toEqual([
232234
emptied.id,
233235
]);

‎packages/studio/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"@hyperframes/studio-server": "workspace:*",
104104
"@mcp-b/global": "^5.0.1",
105105
"@phosphor-icons/react": "^2.1.10",
106-
"@tanstack/react-virtual": "^3.14.6",
106+
"@tanstack/react-virtual": "^3.14.13",
107107
"bpm-detective": "^2.0.5",
108108
"cn": "0.2.4",
109109
"dockview-react": "8.3.1",

‎packages/studio/src/player/components/useTimelineVirtualRows.test.tsx‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
import React, { act } from "react";
44
import { createRoot } from "react-dom/client";
5-
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
5+
import {
6+
elementScroll,
7+
observeElementOffset,
8+
observeElementRect,
9+
Virtualizer,
10+
} from "@tanstack/react-virtual";
11+
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
612
import { createTimelineRowGeometry, RULER_H, TRACKS_TOP_PAD } from "./timelineLayout";
713
import { extractTimelineVirtualRowRange, useTimelineVirtualRows } from "./useTimelineVirtualRows";
814
import type { TimelineScrollViewportSnapshot } from "./useTimelineScrollViewport";
@@ -203,4 +209,27 @@ describe("useTimelineVirtualRows", () => {
203209
expect(rows.some((row) => row.index === 500)).toBe(false);
204210
act(() => root.unmount());
205211
});
212+
213+
// A scroll-end timer left running fires into the torn-down test window ("window is not defined").
214+
it("gets no virtualizer change after unmount from a scroll just before it", async () => {
215+
const scroll = createScrollElement(0);
216+
const onChange = vi.fn();
217+
const virtualizer = new Virtualizer<HTMLDivElement, Element>({
218+
count: 100,
219+
getScrollElement: () => scroll,
220+
estimateSize: () => 48,
221+
scrollToFn: elementScroll,
222+
observeElementRect,
223+
observeElementOffset,
224+
onChange,
225+
});
226+
const unmount = virtualizer._didMount();
227+
virtualizer._willUpdate();
228+
scroll.dispatchEvent(new Event("scroll"));
229+
unmount();
230+
onChange.mockClear();
231+
232+
await new Promise((settle) => setTimeout(settle, 200));
233+
expect(onChange).not.toHaveBeenCalled();
234+
});
206235
});

0 commit comments

Comments
 (0)