test(engine): the GPU probe tests do not start a Chrome from the host cache (#6187)

This commit is contained in:
Miguel Ángel
2026-10-24 04:33:57 +00:00
committed by GitHub
parent 09d7f1c646
commit 3ef28e26c6
@@ -1,7 +1,7 @@
// fallow-ignore-file code-duplication
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { execFileSync } from "node:child_process";
import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { chmodSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -448,14 +448,43 @@ describe("resolveBrowserGpuMode", () => {
beforeEach(() => {
_resetAutoBrowserGpuModeCacheForTests();
// A named shell skips discovery, which starts any older Chrome in the user's cache to test it.
vi.stubEnv("PRODUCER_HEADLESS_SHELL_PATH", process.execPath);
});
afterEach(() => {
vi.unstubAllEnvs();
vi.restoreAllMocks();
_setPuppeteerForTests(undefined);
_resetAutoBrowserGpuModeCacheForTests();
});
it.runIf(process.platform === "linux" && process.arch === "x64")(
"does not launch a Chrome found in the user's cache while probing",
async () => {
const home = mkdtempSync(join(tmpdir(), "hf-gpu-probe-home-"));
const marker = join(home, "launched");
const shellDir = join(
home,
".cache/puppeteer/chrome-headless-shell",
"linux-100.0.0.0",
"chrome-headless-shell-linux64",
);
mkdirSync(shellDir, { recursive: true });
writeFileSync(join(shellDir, "chrome-headless-shell"), `#!/bin/sh\ntouch "${marker}"\n`);
chmodSync(join(shellDir, "chrome-headless-shell"), 0o755);
vi.stubEnv("HOME", home);
vi.stubEnv("HYPERFRAMES_BROWSER_PATH", "");
setMockWebGlProbe({ hasWebGL: true, vendor: "NVIDIA", renderer: "NVIDIA" });
try {
await resolveBrowserGpuMode("auto");
expect(existsSync(marker)).toBe(false);
} finally {
rmSync(home, { recursive: true, force: true });
}
},
);
it("lets a host own GPU probe launch and cleanup", async () => {
const { launch } = setMockWebGlProbe({ hasWebGL: true, vendor: "NVIDIA", renderer: "NVIDIA" });
const close = vi.fn(async (browser: Browser) => {