From f7ccc18cdd3696a29483e31bfea2f7afbbd7e857 Mon Sep 17 00:00:00 2001 From: Sawyer Cutler Date: Fri, 21 Aug 2026 00:15:01 -0700 Subject: [PATCH] Fix Linux CI platform-detection flake in activatable-row tests isMacPlatform() reads navigator.platform, which happy-dom's GlobalRegistrator reports as whatever the host OS is - Darwin-flavored on a Mac, something else on Linux CI. The "ctrl-click on Mac" tests inherited that host value instead of controlling it, so they passed locally on macOS but failed identically on ubuntu-latest. Each test now stubs navigator.platform to the value it means to exercise (matching the existing navigator.clipboard stub pattern in library-page-selection.test.tsx), so both the Mac and non-Mac branches of isAdditiveSelectClick are asserted deterministically on any OS. No production code changes - isMacPlatform's behavior was already correct. --- apps/web/src/activatable-row.test.ts | 29 +++++++++++++++++-- apps/web/test/library-page-selection.test.tsx | 8 +++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/apps/web/src/activatable-row.test.ts b/apps/web/src/activatable-row.test.ts index 47aabf4e7..95bd78af1 100644 --- a/apps/web/src/activatable-row.test.ts +++ b/apps/web/src/activatable-row.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, test } from "bun:test"; +import { afterEach, describe, expect, test } from "bun:test"; import { isAdditiveSelectClick, @@ -6,18 +6,43 @@ import { rowActivationProps, } from "./activatable-row"; +// `isAdditiveSelectClick`'s Mac/non-Mac branch reads `navigator.platform`, +// which happy-dom's `GlobalRegistrator` reports as whatever the *host* OS +// is — Darwin-flavored on a Mac, something else on Linux CI. Each test +// below pins the platform it means to exercise instead of inheriting the +// host's, so both branches are deterministic on any OS. +const originalPlatform = Object.getOwnPropertyDescriptor(navigator, "platform"); + +function stubPlatform(platform: string): void { + Object.defineProperty(navigator, "platform", { + configurable: true, + value: platform, + }); +} + +afterEach(() => { + if (originalPlatform !== undefined) { + Object.defineProperty(navigator, "platform", originalPlatform); + } +}); + describe("isAdditiveSelectClick", () => { - // The test DOM reports a Darwin platform, so these exercise the Mac rules. test("cmd-click is additive", () => { expect(isAdditiveSelectClick({ metaKey: true, ctrlKey: false })).toBe(true); }); test("ctrl-click is not additive on Mac (it's the context-menu gesture)", () => { + stubPlatform("MacIntel"); expect(isAdditiveSelectClick({ metaKey: false, ctrlKey: true })).toBe( false, ); }); + test("ctrl-click is additive on non-Mac", () => { + stubPlatform("Linux x86_64"); + expect(isAdditiveSelectClick({ metaKey: false, ctrlKey: true })).toBe(true); + }); + test("a plain click is not additive", () => { expect(isAdditiveSelectClick({ metaKey: false, ctrlKey: false })).toBe( false, diff --git a/apps/web/test/library-page-selection.test.tsx b/apps/web/test/library-page-selection.test.tsx index e7b36f0fe..242c713e2 100644 --- a/apps/web/test/library-page-selection.test.tsx +++ b/apps/web/test/library-page-selection.test.tsx @@ -52,6 +52,14 @@ beforeEach(() => { configurable: true, value: { writeText: mock(() => Promise.resolve()) }, }); + // isAdditiveSelectClick's Mac/non-Mac branch reads navigator.platform, + // which happy-dom reports as whatever the host OS is — Darwin-flavored + // locally, something else on Linux CI. Pinned here so the ctrl-click + // test below exercises the Mac branch deterministically on any OS. + Object.defineProperty(navigator, "platform", { + configurable: true, + value: "MacIntel", + }); toastMock.mockClear(); });