Add the Media Studio adapters behind the frozen provider contracts: a deterministic offline inference emulator driven by file-name markers that renders real redactions with ffmpeg, a synthetic emulator library, the bearer-auth HTTP client for the local media sidecar with validated responses, typed errors, busy retries and timeouts, a lazily paginated folder source that never follows symlinks, and the configuration factory. A shared conformance suite runs against the emulator and, in the Docker integration job, against the sidecar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0138YqDj3ttfayRwuMKKrqVj
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { homedir } from "node:os";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
createMediaInferenceProvider,
|
|
createMediaSourceProvider,
|
|
mediaConfigFromEnv,
|
|
resolveMediaInferenceKind,
|
|
} from "./media-factory.js";
|
|
|
|
const worker = {
|
|
MEDIA_WORKER_URL: "http://127.0.0.1:8790",
|
|
MEDIA_WORKER_TOKEN: "placeholder-token-placeholder-token-00",
|
|
};
|
|
|
|
describe("media factory", () => {
|
|
it("reads one generic worker connection and derives paths", () => {
|
|
expect(mediaConfigFromEnv({ DATA_DIR: "/srv/evoo", ...worker })).toEqual({
|
|
enabled: true,
|
|
workerUrl: worker.MEDIA_WORKER_URL,
|
|
workerToken: worker.MEDIA_WORKER_TOKEN,
|
|
profilesDir: path.join(homedir(), ".evoo/media-profiles"),
|
|
mediaRoot: "/srv/evoo/media",
|
|
});
|
|
expect(
|
|
mediaConfigFromEnv({ DATA_DIR: "/srv/evoo", MEDIA_PROFILES_DIR: "/etc/evoo/profiles" }),
|
|
).toMatchObject({ enabled: false, workerUrl: null, profilesDir: "/etc/evoo/profiles" });
|
|
});
|
|
|
|
it("selects the sidecar only with URL and token", () => {
|
|
expect(resolveMediaInferenceKind(worker)).toBe("sidecar");
|
|
expect(createMediaInferenceProvider(worker)?.id).toBe("sidecar");
|
|
expect(resolveMediaInferenceKind({ MEDIA_WORKER_URL: worker.MEDIA_WORKER_URL })).toBeNull();
|
|
expect(createMediaInferenceProvider({})).toBeNull();
|
|
});
|
|
|
|
it("pins the emulator under the scripted runtime", () => {
|
|
expect(resolveMediaInferenceKind({ ...worker, AGENT_RUNTIME: "scripted" })).toBe("emulator");
|
|
expect(createMediaInferenceProvider({ AGENT_RUNTIME: "scripted" })?.id).toBe("emulator");
|
|
expect(mediaConfigFromEnv({ AGENT_RUNTIME: "scripted" }).enabled).toBe(true);
|
|
// pin-test-env sets AGENT_RUNTIME=scripted for every unit test.
|
|
expect(createMediaInferenceProvider()?.id).toBe("emulator");
|
|
});
|
|
|
|
it("creates server-side sources only", () => {
|
|
expect(createMediaSourceProvider("folder", {}).kind).toBe("folder");
|
|
expect(createMediaSourceProvider("emulator", { AGENT_RUNTIME: "scripted" }).kind).toBe(
|
|
"emulator",
|
|
);
|
|
expect(() => createMediaSourceProvider("emulator", {})).toThrow();
|
|
expect(() => createMediaSourceProvider("apple_photos", {})).toThrow();
|
|
});
|
|
});
|