Files
adolf/extensions/deepinfra/surface-model-catalogs.test.ts
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

274 lines
8.7 KiB
TypeScript

// Deepinfra tests cover surface model catalogs plugin behavior.
import { beforeEach, describe, expect, it, vi } from "vitest";
import { resetDeepInfraModelCacheForTest } from "./provider-models.js";
import {
listDeepInfraImageGenCatalog,
listDeepInfraVideoGenCatalog,
resolveDeepInfraVideoModelCapabilities,
} from "./surface-model-catalogs.js";
beforeEach(() => {
resetDeepInfraModelCacheForTest();
});
function makeCtx(overrides: Partial<Parameters<typeof listDeepInfraImageGenCatalog>[0]> = {}) {
return {
config: {},
env: { ...process.env },
resolveProviderApiKey: (_id?: string) => ({
apiKey: undefined,
discoveryApiKey: undefined,
}),
resolveProviderAuth: () => ({
apiKey: undefined,
mode: "none" as const,
source: "none" as const,
}),
...overrides,
} as Parameters<typeof listDeepInfraImageGenCatalog>[0];
}
function withKeyCtx(): Parameters<typeof listDeepInfraImageGenCatalog>[0] {
return makeCtx({
resolveProviderApiKey: () => ({
apiKey: "sk-test",
discoveryApiKey: "sk-test",
}),
});
}
const surfaceEntry = (id: string, surfaceTag: string, extra: Record<string, unknown> = {}) => ({
id,
object: "model" as const,
owned_by: "deepinfra",
metadata: {
description: id,
tags: [surfaceTag],
pricing: {},
...extra,
},
});
function jsonResponse(payload: unknown, init: ResponseInit = {}): Response {
return new Response(JSON.stringify(payload), {
status: 200,
headers: { "Content-Type": "application/json" },
...init,
});
}
async function withLiveFetch(mockFetch: ReturnType<typeof vi.fn>, run: () => Promise<void>) {
const env = { ...process.env };
delete process.env.NODE_ENV;
delete process.env.VITEST;
process.env.DEEPINFRA_API_KEY = "sk-test";
vi.stubGlobal("fetch", mockFetch);
try {
await run();
} finally {
if (env.NODE_ENV !== undefined) {
process.env.NODE_ENV = env.NODE_ENV;
} else {
delete process.env.NODE_ENV;
}
if (env.VITEST !== undefined) {
process.env.VITEST = env.VITEST;
} else {
delete process.env.VITEST;
}
if (env.DEEPINFRA_API_KEY !== undefined) {
process.env.DEEPINFRA_API_KEY = env.DEEPINFRA_API_KEY;
} else {
delete process.env.DEEPINFRA_API_KEY;
}
vi.unstubAllGlobals();
}
}
describe("DeepInfra generation catalogs", () => {
it("return null when no discoveryApiKey is configured", async () => {
await expect(listDeepInfraImageGenCatalog(makeCtx())).resolves.toBeNull();
await expect(listDeepInfraVideoGenCatalog(makeCtx())).resolves.toBeNull();
});
});
describe("listDeepInfraImageGenCatalog", () => {
it("returns null when live discovery succeeds but the response has zero image-gen entries", async () => {
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
data: [
surfaceEntry("anthropic/claude-sonnet-4-6", "chat", {
context_length: 200000,
max_tokens: 8192,
pricing: { input_tokens: 3, output_tokens: 15 },
}),
],
}),
);
await withLiveFetch(mockFetch, async () => {
const result = await listDeepInfraImageGenCatalog(withKeyCtx());
expect(result).toBeNull();
});
});
it("returns null under VITEST even with a key (static fallback owns offline)", async () => {
// The default VITEST env path makes discoverDeepInfraSurfaces emit the
// manifest fallback (live=false), and the catalog provider rejects
// non-live results so it cannot serve stale offline data as "live".
const result = await listDeepInfraImageGenCatalog(withKeyCtx());
expect(result).toBeNull();
});
it("projects discovered image-gen entries when a key is configured and discovery is live", async () => {
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
data: [
surfaceEntry("black-forest-labs/FLUX-2-pro", "image-gen", {
pricing: { per_image_unit: 0.08 },
default_width: 1024,
default_height: 1024,
default_iterations: 28,
}),
surfaceEntry("ByteDance/Seedream-4", "image-gen", {
pricing: { per_image_unit: 0.03 },
}),
surfaceEntry("anthropic/claude-sonnet-4-6", "chat", {
context_length: 200000,
max_tokens: 8192,
pricing: { input_tokens: 3, output_tokens: 15 },
}),
],
}),
);
await withLiveFetch(mockFetch, async () => {
const result = await listDeepInfraImageGenCatalog(withKeyCtx());
expect(result).not.toBeNull();
expect(result?.map((e) => e.model)).toEqual([
"black-forest-labs/FLUX-2-pro",
"ByteDance/Seedream-4",
]);
for (const entry of result ?? []) {
expect(entry.kind).toBe("image_generation");
expect(entry.provider).toBe("deepinfra");
expect(entry.source).toBe("live");
}
});
});
});
describe("listDeepInfraVideoGenCatalog", () => {
it("returns null when live discovery succeeds but the response has zero video-gen entries", async () => {
// Current production state: TTS/STT/T2V models lack the OPENAI tag the
// backend filter requires, so a key-authenticated discovery still
// produces zero video-gen entries. We must return null so the registered
// provider's static fallback list is consulted instead of an empty
// "live" answer.
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
data: [
surfaceEntry("anthropic/claude-sonnet-4-6", "chat", {
context_length: 200000,
max_tokens: 8192,
pricing: { input_tokens: 3, output_tokens: 15 },
}),
surfaceEntry("black-forest-labs/FLUX-2-pro", "image-gen", {
pricing: { per_image_unit: 0.08 },
}),
],
}),
);
await withLiveFetch(mockFetch, async () => {
const result = await listDeepInfraVideoGenCatalog(withKeyCtx());
expect(result).toBeNull();
});
});
it("projects discovered video-gen entries with capability shape", async () => {
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
data: [
surfaceEntry("Wan-AI/Wan2.6-T2V", "video-gen", {
pricing: { output_seconds: 0.05 },
}),
surfaceEntry("ByteDance/Seedance-2.0", "video-gen", {
pricing: { output_seconds: 0.08 },
}),
],
}),
);
await withLiveFetch(mockFetch, async () => {
const result = await listDeepInfraVideoGenCatalog(withKeyCtx());
expect(result).not.toBeNull();
expect(result?.map((e) => e.model)).toEqual(["Wan-AI/Wan2.6-T2V", "ByteDance/Seedance-2.0"]);
const first = result?.[0];
expect(first?.kind).toBe("video_generation");
expect(first?.capabilities?.generate?.supportsAspectRatio).toBe(true);
expect(first?.capabilities?.generate?.supportedDurationSeconds).toEqual([5, 8]);
});
});
});
describe("resolveDeepInfraVideoModelCapabilities", () => {
it("returns capabilities for a discovered video-gen model", async () => {
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
data: [
surfaceEntry("Wan-AI/Wan2.6-T2V", "video-gen", {
pricing: { output_seconds: 0.05 },
}),
],
}),
);
await withLiveFetch(mockFetch, async () => {
const caps = await resolveDeepInfraVideoModelCapabilities({
model: "Wan-AI/Wan2.6-T2V",
} as Parameters<typeof resolveDeepInfraVideoModelCapabilities>[0]);
expect(caps).toBeDefined();
expect(caps?.generate?.supportsAspectRatio).toBe(true);
});
});
it("strips the deepinfra/ prefix when matching", async () => {
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
data: [
surfaceEntry("Wan-AI/Wan2.6-T2V", "video-gen", {
pricing: { output_seconds: 0.05 },
}),
],
}),
);
await withLiveFetch(mockFetch, async () => {
const caps = await resolveDeepInfraVideoModelCapabilities({
model: "deepinfra/Wan-AI/Wan2.6-T2V",
} as Parameters<typeof resolveDeepInfraVideoModelCapabilities>[0]);
expect(caps).toBeDefined();
});
});
it("returns undefined for an unknown model", async () => {
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
data: [
surfaceEntry("Wan-AI/Wan2.6-T2V", "video-gen", {
pricing: { output_seconds: 0.05 },
}),
],
}),
);
await withLiveFetch(mockFetch, async () => {
const caps = await resolveDeepInfraVideoModelCapabilities({
model: "ByteDance/Seedance-2.0",
} as Parameters<typeof resolveDeepInfraVideoModelCapabilities>[0]);
expect(caps).toBeUndefined();
});
});
});