mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:21:26 +00:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -5,11 +5,7 @@ import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { ClawdbotConfig } from "../../config/config.js";
|
||||
import {
|
||||
__testing,
|
||||
createImageTool,
|
||||
resolveImageModelConfigForTool,
|
||||
} from "./image-tool.js";
|
||||
import { __testing, createImageTool, resolveImageModelConfigForTool } from "./image-tool.js";
|
||||
|
||||
async function writeAuthProfiles(agentDir: string, profiles: unknown) {
|
||||
await fs.mkdir(agentDir, { recursive: true });
|
||||
@@ -41,9 +37,7 @@ describe("image tool implicit imageModel config", () => {
|
||||
});
|
||||
|
||||
it("stays disabled without auth when no pairing is possible", async () => {
|
||||
const agentDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-image-"),
|
||||
);
|
||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-image-"));
|
||||
const cfg: ClawdbotConfig = {
|
||||
agents: { defaults: { model: { primary: "openai/gpt-5.2" } } },
|
||||
};
|
||||
@@ -52,9 +46,7 @@ describe("image tool implicit imageModel config", () => {
|
||||
});
|
||||
|
||||
it("pairs minimax primary with MiniMax-VL-01 (and fallbacks) when auth exists", async () => {
|
||||
const agentDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-image-"),
|
||||
);
|
||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-image-"));
|
||||
vi.stubEnv("MINIMAX_API_KEY", "minimax-test");
|
||||
vi.stubEnv("OPENAI_API_KEY", "openai-test");
|
||||
vi.stubEnv("ANTHROPIC_API_KEY", "anthropic-test");
|
||||
@@ -69,9 +61,7 @@ describe("image tool implicit imageModel config", () => {
|
||||
});
|
||||
|
||||
it("pairs a custom provider when it declares an image-capable model", async () => {
|
||||
const agentDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-image-"),
|
||||
);
|
||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-image-"));
|
||||
await writeAuthProfiles(agentDir, {
|
||||
version: 1,
|
||||
profiles: {
|
||||
@@ -98,9 +88,7 @@ describe("image tool implicit imageModel config", () => {
|
||||
});
|
||||
|
||||
it("prefers explicit agents.defaults.imageModel", async () => {
|
||||
const agentDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-image-"),
|
||||
);
|
||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-image-"));
|
||||
const cfg: ClawdbotConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
@@ -115,9 +103,7 @@ describe("image tool implicit imageModel config", () => {
|
||||
});
|
||||
|
||||
it("sandboxes image paths like the read tool", async () => {
|
||||
const stateDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-image-sandbox-"),
|
||||
);
|
||||
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-image-sandbox-"));
|
||||
const agentDir = path.join(stateDir, "agent");
|
||||
const sandboxRoot = path.join(stateDir, "sandbox");
|
||||
await fs.mkdir(agentDir, { recursive: true });
|
||||
@@ -132,19 +118,17 @@ describe("image tool implicit imageModel config", () => {
|
||||
expect(tool).not.toBeNull();
|
||||
if (!tool) throw new Error("expected image tool");
|
||||
|
||||
await expect(
|
||||
tool.execute("t1", { image: "https://example.com/a.png" }),
|
||||
).rejects.toThrow(/Sandboxed image tool does not allow remote URLs/i);
|
||||
await expect(tool.execute("t1", { image: "https://example.com/a.png" })).rejects.toThrow(
|
||||
/Sandboxed image tool does not allow remote URLs/i,
|
||||
);
|
||||
|
||||
await expect(
|
||||
tool.execute("t2", { image: "../escape.png" }),
|
||||
).rejects.toThrow(/escapes sandbox root/i);
|
||||
await expect(tool.execute("t2", { image: "../escape.png" })).rejects.toThrow(
|
||||
/escapes sandbox root/i,
|
||||
);
|
||||
});
|
||||
|
||||
it("rewrites inbound absolute paths into sandbox media/inbound", async () => {
|
||||
const stateDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-image-sandbox-"),
|
||||
);
|
||||
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-image-sandbox-"));
|
||||
const agentDir = path.join(stateDir, "agent");
|
||||
const sandboxRoot = path.join(stateDir, "sandbox");
|
||||
await fs.mkdir(agentDir, { recursive: true });
|
||||
@@ -190,9 +174,7 @@ describe("image tool implicit imageModel config", () => {
|
||||
});
|
||||
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
expect((res.details as { rewrittenFrom?: string }).rewrittenFrom).toContain(
|
||||
"photo.png",
|
||||
);
|
||||
expect((res.details as { rewrittenFrom?: string }).rewrittenFrom).toContain("photo.png");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -207,9 +189,9 @@ describe("image tool data URL support", () => {
|
||||
});
|
||||
|
||||
it("rejects non-image data URLs", () => {
|
||||
expect(() =>
|
||||
__testing.decodeDataUrl("data:text/plain;base64,SGVsbG8="),
|
||||
).toThrow(/Unsupported data URL type/i);
|
||||
expect(() => __testing.decodeDataUrl("data:text/plain;base64,SGVsbG8=")).toThrow(
|
||||
/Unsupported data URL type/i,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -245,9 +227,7 @@ describe("image tool MiniMax VLM routing", () => {
|
||||
// @ts-expect-error partial global
|
||||
global.fetch = fetch;
|
||||
|
||||
const agentDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-minimax-vlm-"),
|
||||
);
|
||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-minimax-vlm-"));
|
||||
vi.stubEnv("MINIMAX_API_KEY", "minimax-test");
|
||||
const cfg: ClawdbotConfig = {
|
||||
agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
|
||||
@@ -265,9 +245,9 @@ describe("image tool MiniMax VLM routing", () => {
|
||||
const [url, init] = fetch.mock.calls[0];
|
||||
expect(String(url)).toBe("https://api.minimax.io/v1/coding_plan/vlm");
|
||||
expect(init?.method).toBe("POST");
|
||||
expect(
|
||||
String((init?.headers as Record<string, string>)?.Authorization),
|
||||
).toBe("Bearer minimax-test");
|
||||
expect(String((init?.headers as Record<string, string>)?.Authorization)).toBe(
|
||||
"Bearer minimax-test",
|
||||
);
|
||||
expect(String(init?.body)).toContain('"prompt":"Describe the image."');
|
||||
expect(String(init?.body)).toContain('"image_url":"data:image/png;base64,');
|
||||
|
||||
@@ -289,9 +269,7 @@ describe("image tool MiniMax VLM routing", () => {
|
||||
// @ts-expect-error partial global
|
||||
global.fetch = fetch;
|
||||
|
||||
const agentDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "clawdbot-minimax-vlm-"),
|
||||
);
|
||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-minimax-vlm-"));
|
||||
vi.stubEnv("MINIMAX_API_KEY", "minimax-test");
|
||||
const cfg: ClawdbotConfig = {
|
||||
agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
|
||||
|
||||
Reference in New Issue
Block a user