Files
James d2ca45ef75 feat(cli): add remove-background command for transparent video
Adds `hyperframes remove-background` — a local-AI subcommand that mattes a
video or image with the u2net_human_seg ONNX model and emits a transparent
WebM (VP9-alpha), ProRes 4444 .mov, or RGBA PNG. Drops directly into any
composition's <video> tag — no green screen, no API keys, no upload.

Auto-picks the fastest available execution provider via onnxruntime-node:
CoreML on Apple Silicon, CUDA when HYPERFRAMES_CUDA=1, CPU otherwise.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 04:17:51 +00:00

82 lines
2.6 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("background-removal/manager — selectProviders", () => {
beforeEach(() => {
vi.resetModules();
delete process.env["HYPERFRAMES_CUDA"];
});
afterEach(() => {
vi.restoreAllMocks();
});
it("returns CPU explicitly when --device cpu", async () => {
vi.doMock("node:os", () => ({
platform: () => "darwin",
arch: () => "arm64",
homedir: () => "/tmp",
}));
const { selectProviders } = await import("./manager.js");
const choice = selectProviders("cpu");
expect(choice.providers).toEqual(["cpu"]);
expect(choice.label).toBe("CPU");
});
it("auto picks CoreML on darwin-arm64", async () => {
vi.doMock("node:os", () => ({
platform: () => "darwin",
arch: () => "arm64",
homedir: () => "/tmp",
}));
const { selectProviders } = await import("./manager.js");
const choice = selectProviders("auto");
expect(choice.providers).toEqual(["coreml", "cpu"]);
expect(choice.label).toBe("CoreML");
});
it("auto falls back to CPU on linux without HYPERFRAMES_CUDA", async () => {
vi.doMock("node:os", () => ({
platform: () => "linux",
arch: () => "x64",
homedir: () => "/tmp",
}));
const { selectProviders } = await import("./manager.js");
const choice = selectProviders("auto");
expect(choice.providers).toEqual(["cpu"]);
expect(choice.label).toBe("CPU");
});
it("auto picks CUDA on linux when HYPERFRAMES_CUDA=1", async () => {
process.env["HYPERFRAMES_CUDA"] = "1";
vi.doMock("node:os", () => ({
platform: () => "linux",
arch: () => "x64",
homedir: () => "/tmp",
}));
const { selectProviders } = await import("./manager.js");
const choice = selectProviders("auto");
expect(choice.providers).toEqual(["cuda", "cpu"]);
expect(choice.label).toBe("CUDA");
});
it("--device coreml on linux throws", async () => {
vi.doMock("node:os", () => ({
platform: () => "linux",
arch: () => "x64",
homedir: () => "/tmp",
}));
const { selectProviders } = await import("./manager.js");
expect(() => selectProviders("coreml")).toThrow(/CoreML execution provider not available/);
});
it("--device cuda without env var throws", async () => {
vi.doMock("node:os", () => ({
platform: () => "linux",
arch: () => "x64",
homedir: () => "/tmp",
}));
const { selectProviders } = await import("./manager.js");
expect(() => selectProviders("cuda")).toThrow(/CUDA execution provider not available/);
});
});