|
1 | 1 | // Shared media tool tests cover root separation, provider availability, and |
2 | 2 | // model-registry normalization for generation/understanding tools. |
| 3 | +import fs from "node:fs/promises"; |
3 | 4 | import path from "node:path"; |
4 | 5 | import { pathToFileURL } from "node:url"; |
5 | | -import { describe, expect, it, vi } from "vitest"; |
| 6 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 7 | +import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js"; |
6 | 8 | import type { OpenClawConfig } from "../../config/config.js"; |
7 | 9 | import { withEnvAsync } from "../../test-utils/env.js"; |
| 10 | +import { createHostSandboxFsBridge } from "../test-helpers/host-sandbox-fs-bridge.js"; |
8 | 11 | import { |
9 | 12 | hasGenerationToolAvailability, |
10 | 13 | isCapabilityProviderConfigured, |
| 14 | + loadMediaToolReferences, |
11 | 15 | resolveGenerateAction, |
12 | 16 | resolveMediaToolInboundRoots, |
13 | 17 | resolveCapabilityModelConfigForTool, |
14 | 18 | resolveMediaToolReferenceAccess, |
| 19 | + resolveMediaToolSandboxConfig, |
15 | 20 | } from "./media-tool-shared.js"; |
16 | 21 |
|
| 22 | +const tempDirs = useAutoCleanupTempDirTracker(afterEach); |
| 23 | + |
17 | 24 | // Keep media-tool-shared tests focused on root separation; channel-inbound |
18 | 25 | // tests cover the real bundled contract loader. |
19 | 26 | vi.mock("../../media/channel-inbound-roots.js", () => ({ |
@@ -186,6 +193,45 @@ describe("resolveMediaToolReferenceAccess", () => { |
186 | 193 | }), |
187 | 194 | ).rejects.toThrow(expected); |
188 | 195 | }); |
| 196 | + |
| 197 | + it.each(["image_generate", "video_generate", "music_generate"] as const)( |
| 198 | + "loads a producer-staged bare handle for %s references", |
| 199 | + async (toolName) => { |
| 200 | + const root = tempDirs.make("openclaw-media-tool-staged-"); |
| 201 | + const stagedPath = "media/inbound/openclaw-staged-proof/input-file_upload.png"; |
| 202 | + const fullPath = path.join(root, stagedPath); |
| 203 | + await fs.mkdir(path.dirname(fullPath), { recursive: true }); |
| 204 | + await fs.writeFile( |
| 205 | + fullPath, |
| 206 | + Buffer.from( |
| 207 | + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO2f7z8AAAAASUVORK5CYII=", |
| 208 | + "base64", |
| 209 | + ), |
| 210 | + ); |
| 211 | + const sandbox = resolveMediaToolSandboxConfig( |
| 212 | + { |
| 213 | + root, |
| 214 | + bridge: createHostSandboxFsBridge(root), |
| 215 | + stagedMediaPaths: new Map([["file_upload", stagedPath]]), |
| 216 | + }, |
| 217 | + true, |
| 218 | + ); |
| 219 | + |
| 220 | + const loaded = await loadMediaToolReferences({ |
| 221 | + inputs: ["file_upload"], |
| 222 | + toolName, |
| 223 | + expectedKind: "image", |
| 224 | + sandbox, |
| 225 | + workspaceDir: root, |
| 226 | + maxBytes: 1024, |
| 227 | + mapMedia: (media) => media.buffer, |
| 228 | + }); |
| 229 | + |
| 230 | + expect(loaded).toMatchObject([ |
| 231 | + { resolvedInput: "file_upload", rewrittenFrom: "file_upload" }, |
| 232 | + ]); |
| 233 | + }, |
| 234 | + ); |
189 | 235 | }); |
190 | 236 |
|
191 | 237 | describe("hasGenerationToolAvailability", () => { |
|
0 commit comments