Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/utils/__tests__/images.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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",
Expand Down
Loading