refactor: trim media understanding runner test imports

This commit is contained in:
Shakker
2026-04-01 19:45:54 +01:00
committed by Peter Steinberger
parent 19493b681d
commit 25e9ff01cf
5 changed files with 34 additions and 33 deletions

View File

@@ -0,0 +1,18 @@
import type { MsgContext } from "../auto-reply/templating.js";
import {
MediaAttachmentCache,
type MediaAttachmentCacheOptions,
normalizeAttachments,
} from "./attachments.js";
import type { MediaAttachment } from "./types.js";
export function normalizeMediaAttachments(ctx: MsgContext): MediaAttachment[] {
return normalizeAttachments(ctx);
}
export function createMediaAttachmentCache(
attachments: MediaAttachment[],
options?: MediaAttachmentCacheOptions,
): MediaAttachmentCache {
return new MediaAttachmentCache(attachments, options);
}

View File

@@ -5,12 +5,8 @@ import { describe, expect, it } from "vitest";
import type { MsgContext } from "../auto-reply/templating.js";
import type { OpenClawConfig } from "../config/config.js";
import { MIN_AUDIO_FILE_BYTES } from "./defaults.js";
import {
buildProviderRegistry,
createMediaAttachmentCache,
normalizeMediaAttachments,
runCapability,
} from "./runner.js";
import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.attachments.js";
import { buildProviderRegistry, runCapability } from "./runner.js";
import type { AudioTranscriptionRequest } from "./types.js";
async function withAudioFixture(params: {

View File

@@ -3,7 +3,7 @@ import os from "node:os";
import path from "node:path";
import { withEnvAsync } from "../test-utils/env.js";
import { MIN_AUDIO_FILE_BYTES } from "./defaults.js";
import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.js";
import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.attachments.js";
type MediaFixtureParams = {
ctx: { MediaPath: string; MediaType: string };

View File

@@ -25,12 +25,7 @@ import {
} from "../media/inbound-path-policy.js";
import { getDefaultMediaLocalRoots } from "../media/local-roots.js";
import { runExec } from "../process/exec.js";
import {
MediaAttachmentCache,
type MediaAttachmentCacheOptions,
normalizeAttachments,
selectAttachments,
} from "./attachments.js";
import { MediaAttachmentCache, selectAttachments } from "./attachments.js";
import {
AUTO_AUDIO_KEY_PROVIDERS,
AUTO_IMAGE_KEY_PROVIDERS,
@@ -60,6 +55,7 @@ import type {
MediaUnderstandingOutput,
MediaUnderstandingProvider,
} from "./types.js";
export { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.attachments.js";
export type ActiveMediaModel = {
provider: string;
@@ -80,10 +76,6 @@ export function buildProviderRegistry(
return buildMediaUnderstandingRegistry(overrides, cfg);
}
export function normalizeMediaAttachments(ctx: MsgContext): MediaAttachment[] {
return normalizeAttachments(ctx);
}
export function resolveMediaAttachmentLocalRoots(params: {
cfg: OpenClawConfig;
ctx: MsgContext;
@@ -97,13 +89,6 @@ export function resolveMediaAttachmentLocalRoots(params: {
);
}
export function createMediaAttachmentCache(
attachments: MediaAttachment[],
options?: MediaAttachmentCacheOptions,
): MediaAttachmentCache {
return new MediaAttachmentCache(attachments, options);
}
const binaryCache = new Map<string, Promise<string | null>>();
const geminiProbeCache = new Map<string, Promise<boolean>>();

View File

@@ -10,6 +10,7 @@ import { __testing as loaderTesting } from "../plugins/loader.js";
import { loadPluginManifestRegistry } from "../plugins/manifest-registry.js";
import { createEmptyPluginRegistry } from "../plugins/registry.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.attachments.js";
const catalog = [
{
@@ -33,8 +34,6 @@ vi.mock("../agents/model-catalog.js", async () => {
});
let buildProviderRegistry: typeof import("./runner.js").buildProviderRegistry;
let createMediaAttachmentCache: typeof import("./runner.js").createMediaAttachmentCache;
let normalizeMediaAttachments: typeof import("./runner.js").normalizeMediaAttachments;
let resolveAutoImageModel: typeof import("./runner.js").resolveAutoImageModel;
let runCapability: typeof import("./runner.js").runCapability;
@@ -73,13 +72,16 @@ function setCompatibleActiveMediaUnderstandingRegistry(
describe("runCapability image skip", () => {
beforeAll(async () => {
({
buildProviderRegistry,
createMediaAttachmentCache,
normalizeMediaAttachments,
resolveAutoImageModel,
runCapability,
} = await import("./runner.js"));
vi.doMock("../agents/model-catalog.js", async () => {
const actual = await vi.importActual<typeof import("../agents/model-catalog.js")>(
"../agents/model-catalog.js",
);
return {
...actual,
loadModelCatalog,
};
});
({ buildProviderRegistry, resolveAutoImageModel, runCapability } = await import("./runner.js"));
});
beforeEach(() => {