From 7bbeeefa4e2064c38958599b50f7febfdea8c69a Mon Sep 17 00:00:00 2001 From: Cryptopoly <31970407+cryptopoly@users.noreply.github.com> Date: Fri, 1 May 2026 13:23:28 +0100 Subject: [PATCH] Pin imageDiscoverMemoryEstimate tests to Mac host The imageDiscoverMemoryEstimate describe block called the function with no explicit device, which falls through to inferDeviceFromHostPlatform in src/utils/videos.ts: - macOS host -> 'mps' device path - Linux/Win -> 'cuda' device path The expected values in the three failing tests were calibrated against the MPS path (FLUX text encoders, MPS runtime overhead, MPS-specific runtimeFootprint overrides). On a Mac developer box they pass; on the ubuntu-latest CI runner the host-inference returns 'cuda' and the function picks the CUDA branch, producing different numbers: modelFootprintGb 7.5 -> 4.5 (loses MPS multiplier) modelFootprintGb 41.3 -> 18.3 (no MPS GGUF overhead) modelFootprintGb 20 -> 16 (skips runtimeFootprintMpsGb override) This has been broken on CI since PR #20 (video-gen merge) introduced the host-platform fallback. Every push to main since 2026-04-29 has failed Build Desktop App > test on these three lines. Fix - Stub navigator + navigator.userAgentData.platform to 'macOS' inside the imageDiscoverMemoryEstimate describe block via beforeEach + vi.stubGlobal. - Restore globals after each test via afterEach + vi.unstubAllGlobals. The assessImageGenerationSafety describe block above is untouched because it always passes an explicit device, so host-inference never fires there. Verified locally: all 207 tests pass on macOS. --- src/utils/__tests__/images.test.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/utils/__tests__/images.test.ts b/src/utils/__tests__/images.test.ts index c948ec3..618fa92 100644 --- a/src/utils/__tests__/images.test.ts +++ b/src/utils/__tests__/images.test.ts @@ -1,9 +1,26 @@ -import { describe, expect, it } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { ImageModelVariant } from "../../types"; import { assessImageGenerationSafety, imageDiscoverMemoryEstimate } from "../images"; import { compareDiscoverVariants } from "../discoverSort"; +// imageDiscoverMemoryEstimate calls assessImageGenerationSafety with +// device=null, which falls through to inferDeviceFromHostPlatform(). +// That helper reads navigator.userAgentData.platform and returns +// "mps" on macOS, "cuda" elsewhere. The expected values in the +// imageDiscoverMemoryEstimate describe block below were calibrated for +// the MPS path (FLUX text encoders, MPS runtime overhead, MPS-specific +// runtimeFootprint overrides), so we pin the host to macOS for the +// duration of those tests. CI runs on Linux runners where the +// inference would otherwise return "cuda" and produce different numbers. +function pinHostPlatformToMac(): void { + vi.stubGlobal("navigator", { + userAgentData: { platform: "macOS" }, + platform: "MacIntel", + userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)", + }); +} + describe("assessImageGenerationSafety()", () => { it("does not block standard FLUX 1024px generation on a 64 GB MPS Mac", () => { const result = assessImageGenerationSafety({ @@ -127,6 +144,13 @@ describe("assessImageGenerationSafety()", () => { }); describe("imageDiscoverMemoryEstimate()", () => { + beforeEach(() => { + pinHostPlatformToMac(); + }); + afterEach(() => { + vi.unstubAllGlobals(); + }); + const baseVariant: ImageModelVariant = { id: "black-forest-labs/FLUX.1-schnell", familyId: "flux-fast",