Compare commits

...
Author SHA1 Message Date
l0ng-ai 89345b1a35 test(bench): skip browser tests where Playwright's Chromium isn't installed
The harness tests that launch Chromium ran under pnpm test, but CI's Frontend
job installs no browsers, so they failed on every pull request. They now skip
when the build they launch (the headless shell, or the full browser for the
chromium channel) is missing. The legacy artifact date uses whole seconds,
which every file system keeps.
2026-11-20 00:02:54 +08:00
6 changed files with 190 additions and 163 deletions

No files matched your search

+2 -1
View File
@@ -1,6 +1,7 @@
// @vitest-environment node
import { chromium, type Browser, type Page } from "@playwright/test";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { chromiumInstalled } from "../../perf/lib/lifecycle.ts";
import { track } from "./measure.ts";
let browser: Browser;
@@ -29,7 +30,7 @@ afterAll(async () => {
const existingResult = () => document.querySelector("#result") !== null;
describe("tracking the current action", () => {
describe.skipIf(!chromiumInstalled(true))("tracking the current action", () => {
it("rejects an action that declines to run even with an old result visible", async () => {
await expect(
track(page, { action: "unavailable", arg: null, first: existingResult, done: existingResult, timeoutMs: 1000 }),
+26 -22
View File
@@ -1,26 +1,30 @@
// @vitest-environment node
import { expect, test } from "vitest";
import { launchBrowser } from "../../perf/lib/lifecycle.ts";
import { chromiumInstalled, launchBrowser } from "../../perf/lib/lifecycle.ts";
import { track } from "./measure.ts";
test("track times out on Node's clock when animation frames stop", { timeout: 20_000 }, async () => {
const runtime = await launchBrowser({ headless: true });
try {
const page = await runtime.browser.newPage();
await page.evaluate(() => {
// Install the otherwise undeclared probe consumed by the serialized measurement.
const w = window as unknown as { __openideaPerf: unknown };
w.__openideaPerf = {
editorState: () => null,
runAction: async () => true,
};
window.requestAnimationFrame = () => 0;
});
// The platform-clock boundary is the regression; a fake Node clock cannot drive Chromium.
await expect(
track(page, { action: "fixture.action", arg: null, first: () => false, done: () => false, timeoutMs: 20 }),
).rejects.toThrow("page measurement timed out");
} finally {
await runtime.close();
}
});
test.skipIf(!chromiumInstalled(true))(
"track times out on Node's clock when animation frames stop",
{ timeout: 20_000 },
async () => {
const runtime = await launchBrowser({ headless: true });
try {
const page = await runtime.browser.newPage();
await page.evaluate(() => {
// Install the otherwise undeclared probe consumed by the serialized measurement.
const w = window as unknown as { __openideaPerf: unknown };
w.__openideaPerf = {
editorState: () => null,
runAction: async () => true,
};
window.requestAnimationFrame = () => 0;
});
// The platform-clock boundary is the regression; a fake Node clock cannot drive Chromium.
await expect(
track(page, { action: "fixture.action", arg: null, first: () => false, done: () => false, timeoutMs: 20 }),
).rejects.toThrow("page measurement timed out");
} finally {
await runtime.close();
}
},
);
+145 -137
View File
@@ -4,6 +4,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from
import { chromium, type Browser, type BrowserContext, type Page } from "@playwright/test";
import { createServer, type ViteDevServer } from "vite";
import { Harness } from "./harness.ts";
import { chromiumInstalled } from "./lifecycle.ts";
import { installInPage } from "./inpage.ts";
let server: ViteDevServer;
@@ -66,150 +67,157 @@ async function fixtureFile(text = "start\nend") {
await h.setCursor(0);
}
describe("current-operation UI measurements", () => {
it("observes startup without input, but rejects pre-existing DOM even after a no-op key", async () => {
expect(await h.inPage((p) => p.waitShown("#result", "ready", 500))).toBeGreaterThanOrEqual(0);
await expect(h.measure(async () => {}, "#result", "ready", 80)).rejects.toThrow("timed out");
await expect(
h.measure(
() =>
page.evaluate(() => {
document.querySelector("#result")!.textContent = "ready before input";
}),
"#result",
"ready",
80,
),
).rejects.toThrow("timed out");
await expect(
h.measure(
// Another channel (OPENIDEA_PERF_CHANNEL=chrome) is the installed browser itself.
describe.skipIf(!chromiumInstalled(false) && !process.env.OPENIDEA_PERF_CHANNEL)(
"current-operation UI measurements",
() => {
it("observes startup without input, but rejects pre-existing DOM even after a no-op key", async () => {
expect(await h.inPage((p) => p.waitShown("#result", "ready", 500))).toBeGreaterThanOrEqual(0);
await expect(h.measure(async () => {}, "#result", "ready", 80)).rejects.toThrow("timed out");
await expect(
h.measure(
() =>
page.evaluate(() => {
document.querySelector("#result")!.textContent = "ready before input";
}),
"#result",
"ready",
80,
),
).rejects.toThrow("timed out");
await expect(
h.measure(
async () => {
await page.evaluate(() => {
document.querySelector("#result")!.textContent = "ready changed before input";
});
await page.keyboard.press("Shift");
},
"#result",
"ready",
80,
),
).rejects.toThrow("timed out");
await expect(h.measure(() => page.keyboard.press("Shift"), "#result", "ready", 80)).rejects.toThrow("timed out");
});
it("waits for input and the resulting target change, not an earlier frame", async () => {
let changedAt = 0;
const result = h.measure(
async () => {
await page.evaluate(() => {
document.querySelector("#result")!.textContent = "ready changed before input";
await h.inPage((p) => p.afterNextPaint());
await page.keyboard.press("a");
await h.inPage((p) => p.afterNextPaint());
changedAt = await page.evaluate(() => {
document.querySelector("#result")!.textContent = "ready now";
return performance.now();
});
await page.keyboard.press("Shift");
},
"#result",
"ready",
80,
),
).rejects.toThrow("timed out");
await expect(h.measure(() => page.keyboard.press("Shift"), "#result", "ready", 80)).rejects.toThrow("timed out");
});
it("waits for input and the resulting target change, not an earlier frame", async () => {
let changedAt = 0;
const result = h.measure(
async () => {
await h.inPage((p) => p.afterNextPaint());
await page.keyboard.press("a");
await h.inPage((p) => p.afterNextPaint());
changedAt = await page.evaluate(() => {
document.querySelector("#result")!.textContent = "ready now";
return performance.now();
});
},
"#result",
"ready",
1_000,
);
const latency = await result;
expect((await h.inPage((p) => p.lastInput)) + latency).toBeGreaterThanOrEqual(changedAt);
});
it("propagates trigger failure and cancels its waiter without browser rejection", async () => {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
await expect(
h.measure(
async () => {
throw new Error("trigger failed");
},
"#missing",
null,
80,
),
).rejects.toThrow("trigger failed");
await expect(h.measure(async () => false, "#missing", null, 80)).rejects.toThrow("returned false");
await h.inPage(async (p) => {
await p.afterNextPaint();
await p.afterNextPaint();
1_000,
);
const latency = await result;
expect((await h.inPage((p) => p.lastInput)) + latency).toBeGreaterThanOrEqual(changedAt);
});
expect(errors).toEqual([]);
expect(await h.inPage((p) => p.waitShown("#result", "ready", 80))).toBeGreaterThanOrEqual(0);
});
it.each(["ignoreOpen", "wrongContents"])("requires the requested path and seeded contents with %s", async (fault) => {
await fixtureFile();
await mode(fault);
await expect(h.openFile("/two/Same.ts", "different", 100)).rejects.toThrow("requested editor");
});
it("does not finish before the open action succeeds, even with matching existing contents", async () => {
await fixtureFile();
await mode("delayOpen");
let completed = false;
const opening = h.openFile("/one/Same.ts", "start\nend").finally(() => {
completed = true;
});
await page.waitForFunction(() => "__releaseOpen" in window);
try {
await h.inPage((p) => p.afterNextPaint());
expect(completed).toBe(false);
} finally {
await page.evaluate(() => {
if (!("__releaseOpen" in window) || typeof window.__releaseOpen !== "function")
throw new Error("open action was not held");
window.__releaseOpen();
it("propagates trigger failure and cancels its waiter without browser rejection", async () => {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
await expect(
h.measure(
async () => {
throw new Error("trigger failed");
},
"#missing",
null,
80,
),
).rejects.toThrow("trigger failed");
await expect(h.measure(async () => false, "#missing", null, 80)).rejects.toThrow("returned false");
await h.inPage(async (p) => {
await p.afterNextPaint();
await p.afterNextPaint();
});
await opening;
}
});
it("awaits the open action and rejects failed actions even with a matching editor", async () => {
await fixtureFile();
await mode("rejectOpen");
await expect(h.openFile("/one/Same.ts")).rejects.toThrow("open failed");
});
it("measures real typing, including automatic brackets, indentation and backspace", async () => {
await fixtureFile("function f() {\n}\n");
await h.setCursor(14);
expect(await h.typeMeasured("const n = (1 + 2);\n\b", 0)).toHaveLength(20);
});
it.each(["swallowTyping", "wrongCaret", "missingSample", "wrongFocus"])("rejects typing with %s", async (fault) => {
await fixtureFile();
if (fault === "wrongFocus") await page.locator("#other").click();
else await mode(fault);
await expect(h.typeMeasured("x", 0)).rejects.toThrow(/typing|caret|sample|focus/);
});
it("checks the whole document after bounded per-key observations", async () => {
await fixtureFile("start\n" + "unchanged\n".repeat(200) + "end");
expect(await h.typeMeasured("ok", 0)).toHaveLength(2);
await mode("mutateDistant");
await expect(h.typeMeasured("x", 0)).rejects.toThrow("outside the intended insertion");
});
it("requires both cursor destination and viewport displacement for the jump", async () => {
await fixtureFile(Array.from({ length: 1_000 }, (_, i) => `export class Repository${i} {}`).join("\n"));
await mode("disableJump");
await expect(h.jumpToEnd(100)).rejects.toThrow("timed out");
await page.evaluate(() => {
const w = window as unknown as { __fixture: Record<string, boolean> };
w.__fixture.disableJump = false;
expect(errors).toEqual([]);
expect(await h.inPage((p) => p.waitShown("#result", "ready", 80))).toBeGreaterThanOrEqual(0);
});
expect(await h.jumpToEnd(1_000)).toBeGreaterThanOrEqual(0);
expect((await h.editorState())!.head).toBe((await h.editorState())!.length);
});
it("requires each completion arrow to advance exactly one selected item", async () => {
await fixtureFile("");
await h.measure(() => page.keyboard.press("g"), ".cm-tooltip-autocomplete li", "getOrder", 2_000);
await page.waitForSelector('.cm-tooltip-autocomplete li[aria-selected="true"]');
expect(await h.completionArrowsMeasured(3, 0)).toHaveLength(3);
await mode("disableArrows");
await expect(h.completionArrowsMeasured(1, 0)).rejects.toThrow("completion selection");
});
});
it.each(["ignoreOpen", "wrongContents"])(
"requires the requested path and seeded contents with %s",
async (fault) => {
await fixtureFile();
await mode(fault);
await expect(h.openFile("/two/Same.ts", "different", 100)).rejects.toThrow("requested editor");
},
);
it("does not finish before the open action succeeds, even with matching existing contents", async () => {
await fixtureFile();
await mode("delayOpen");
let completed = false;
const opening = h.openFile("/one/Same.ts", "start\nend").finally(() => {
completed = true;
});
await page.waitForFunction(() => "__releaseOpen" in window);
try {
await h.inPage((p) => p.afterNextPaint());
expect(completed).toBe(false);
} finally {
await page.evaluate(() => {
if (!("__releaseOpen" in window) || typeof window.__releaseOpen !== "function")
throw new Error("open action was not held");
window.__releaseOpen();
});
await opening;
}
});
it("awaits the open action and rejects failed actions even with a matching editor", async () => {
await fixtureFile();
await mode("rejectOpen");
await expect(h.openFile("/one/Same.ts")).rejects.toThrow("open failed");
});
it("measures real typing, including automatic brackets, indentation and backspace", async () => {
await fixtureFile("function f() {\n}\n");
await h.setCursor(14);
expect(await h.typeMeasured("const n = (1 + 2);\n\b", 0)).toHaveLength(20);
});
it.each(["swallowTyping", "wrongCaret", "missingSample", "wrongFocus"])("rejects typing with %s", async (fault) => {
await fixtureFile();
if (fault === "wrongFocus") await page.locator("#other").click();
else await mode(fault);
await expect(h.typeMeasured("x", 0)).rejects.toThrow(/typing|caret|sample|focus/);
});
it("checks the whole document after bounded per-key observations", async () => {
await fixtureFile("start\n" + "unchanged\n".repeat(200) + "end");
expect(await h.typeMeasured("ok", 0)).toHaveLength(2);
await mode("mutateDistant");
await expect(h.typeMeasured("x", 0)).rejects.toThrow("outside the intended insertion");
});
it("requires both cursor destination and viewport displacement for the jump", async () => {
await fixtureFile(Array.from({ length: 1_000 }, (_, i) => `export class Repository${i} {}`).join("\n"));
await mode("disableJump");
await expect(h.jumpToEnd(100)).rejects.toThrow("timed out");
await page.evaluate(() => {
const w = window as unknown as { __fixture: Record<string, boolean> };
w.__fixture.disableJump = false;
});
expect(await h.jumpToEnd(1_000)).toBeGreaterThanOrEqual(0);
expect((await h.editorState())!.head).toBe((await h.editorState())!.length);
});
it("requires each completion arrow to advance exactly one selected item", async () => {
await fixtureFile("");
await h.measure(() => page.keyboard.press("g"), ".cm-tooltip-autocomplete li", "getOrder", 2_000);
await page.waitForSelector('.cm-tooltip-autocomplete li[aria-selected="true"]');
expect(await h.completionArrowsMeasured(3, 0)).toHaveLength(3);
await mode("disableArrows");
await expect(h.completionArrowsMeasured(1, 0)).rejects.toThrow("completion selection");
});
},
);
+2 -2
View File
@@ -1,6 +1,6 @@
// @vitest-environment node
import { expect, test, vi } from "vitest";
import { launchBrowser, withDeadline } from "./lifecycle.ts";
import { chromiumInstalled, launchBrowser, withDeadline } from "./lifecycle.ts";
test("a deadline rejects an unanswered operation and releases its timer", async () => {
vi.useFakeTimers();
@@ -15,7 +15,7 @@ test("a deadline rejects an unanswered operation and releases its timer", async
}
});
test.each(["blocked renderer", "missing animation frames"])(
test.skipIf(!chromiumInstalled(true)).each(["blocked renderer", "missing animation frames"])(
"Node deadline survives %s and browser cleanup terminates it",
{ timeout: 20_000 },
async (mode) => {
+13
View File
@@ -1,6 +1,19 @@
import { chromium, type Browser, type LaunchOptions } from "@playwright/test";
import { existsSync } from "node:fs";
import type { Server } from "node:http";
/**
* Whether Playwright's Chromium is installed (`pnpm exec playwright install chromium`):
* `headless` launches use its headless shell, the `chromium` channel the full browser.
* Unit tests that drive a real browser skip without it, as in CI's Frontend job.
*/
export function chromiumInstalled(headless: boolean): boolean {
const full = chromium.executablePath();
if (!headless) return existsSync(full);
const build = /^(.*[\\/])chromium-(\d+)[\\/]/.exec(full);
return !!build && existsSync(`${build[1]}chromium_headless_shell-${build[2]}`);
}
export class DeadlineError extends Error {
constructor(label: string, timeoutMs: number) {
super(`${label} timed out after ${timeoutMs} ms (wall clock)`);
+2 -1
View File
@@ -193,7 +193,8 @@ describe("Rust trial lifecycle", () => {
it("keeps legacy inspection useful and reports artifact dates", async () => {
const root = fixture();
const date = new Date(Date.now() - 120_000);
// Whole seconds: file times don't keep every millisecond on all file systems.
const date = new Date(Math.floor((Date.now() - 120_000) / 1000) * 1000);
artifacts(join(root, "target/criterion"), ["ide-text"], date);
expect(await runRust({ root, packages: ["ide-text"], noRun: true })).toBe(0);
const current = report(root);