From 8e983c841932c1a4d8d374e09155dd9c564ffe64 Mon Sep 17 00:00:00 2001 From: Shane Neubauer Date: Fri, 28 Aug 2026 21:10:43 +1000 Subject: [PATCH] Fix launch telemetry test failing under CI `isCI` from std-env is evaluated once at import time, so the "sends launch telemetry by default" test failed on any CI runner where CI=true. Mock std-env in the test to pin `isCI`, and add a case asserting telemetry is skipped when `isCI` is true. --- ui/studio/context.test.tsx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ui/studio/context.test.tsx b/ui/studio/context.test.tsx index 8f4ec91c..5b1746db 100644 --- a/ui/studio/context.test.tsx +++ b/ui/studio/context.test.tsx @@ -26,6 +26,21 @@ vi.mock("../../checkpoint", () => ({ check: vi.fn(() => Promise.resolve()), })); +// std-env evaluates `isCI` once at import time from the environment, so telemetry +// tests can't control it through process.env. Pin it here (off by default) so the +// suite behaves the same on a developer machine and on CI. +const stdEnvState = vi.hoisted(() => ({ isCI: false })); + +vi.mock("std-env", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + get isCI() { + return stdEnvState.isCI; + }, + }; +}); + vi.mock("./NuqsHashAdapter", () => ({ NuqsHashAdapter: ({ children }: { children: ReactNode }) => <>{children}, })); @@ -192,6 +207,7 @@ afterEach(() => { vi.unstubAllGlobals(); document.body.innerHTML = ""; delete process.env.CHECKPOINT_DISABLE; + stdEnvState.isCI = false; delete (globalThis as { VERSION_INJECTED_AT_BUILD_TIME?: string }) .VERSION_INJECTED_AT_BUILD_TIME; }); @@ -443,6 +459,24 @@ describe("StudioContextProvider telemetry opt-out", () => { harness.cleanup(); }); + it("skips launch telemetry on CI", () => { + stdEnvState.isCI = true; + const harness = renderHarness(); + + act(() => { + harness.getLatestStudio()?.onEvent({ + name: "studio_launched", + payload: { + tableCount: 3, + }, + }); + }); + + expect(check).not.toHaveBeenCalled(); + + harness.cleanup(); + }); + it("skips launch telemetry when CHECKPOINT_DISABLE=1", () => { process.env.CHECKPOINT_DISABLE = "1";