diff --git a/packages/cli/src/browser/gpuPolicy.test.ts b/packages/cli/src/browser/gpuPolicy.test.ts new file mode 100644 index 0000000000..7ea3766721 --- /dev/null +++ b/packages/cli/src/browser/gpuPolicy.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from "vitest"; +import { + assertWebGpuRequirement, + compositionRequiresWebGpu, + resolveLocalBrowserGpuMode, +} from "./gpuPolicy.js"; + +describe("local browser GPU policy", () => { + it("defaults to auto and preserves explicit CLI/env overrides", () => { + expect(resolveLocalBrowserGpuMode(undefined, undefined)).toBe("auto"); + expect(resolveLocalBrowserGpuMode(undefined, "hardware")).toBe("hardware"); + expect(resolveLocalBrowserGpuMode(undefined, "software")).toBe("software"); + expect(resolveLocalBrowserGpuMode(true, "software")).toBe("hardware"); + expect(resolveLocalBrowserGpuMode(false, "hardware")).toBe("software"); + }); + + it("detects the explicit WebGPU capability marker on the composition root", () => { + expect( + compositionRequiresWebGpu( + '
', + ), + ).toBe(true); + expect(compositionRequiresWebGpu('')).toBe(false); + }); + + it("rejects an auto software fallback for required WebGPU compositions", () => { + const html = ''; + expect(() => assertWebGpuRequirement(html, "auto", "software")).toThrow( + "PRODUCER_BROWSER_GPU_MODE=hardware", + ); + expect(() => assertWebGpuRequirement(html, "hardware", "hardware")).not.toThrow(); + expect(() => assertWebGpuRequirement(html, "software", "software")).not.toThrow(); + }); +}); diff --git a/packages/cli/src/browser/gpuPolicy.ts b/packages/cli/src/browser/gpuPolicy.ts new file mode 100644 index 0000000000..0c809e3715 --- /dev/null +++ b/packages/cli/src/browser/gpuPolicy.ts @@ -0,0 +1,43 @@ +export type BrowserGpuMode = "auto" | "hardware" | "software"; +export type ResolvedBrowserGpuMode = Exclude