mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 06:24:34 +00:00
test(image-tool): dedupe repeated image tool fixture assertions
This commit is contained in:
@@ -92,6 +92,14 @@ async function expectImageToolExecOk(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requireImageTool<T>(tool: T | null | undefined): T {
|
||||||
|
expect(tool).not.toBeNull();
|
||||||
|
if (!tool) {
|
||||||
|
throw new Error("expected image tool");
|
||||||
|
}
|
||||||
|
return tool;
|
||||||
|
}
|
||||||
|
|
||||||
function findSchemaUnionKeywords(schema: unknown, path = "root"): string[] {
|
function findSchemaUnionKeywords(schema: unknown, path = "root"): string[] {
|
||||||
if (!schema || typeof schema !== "object") {
|
if (!schema || typeof schema !== "object") {
|
||||||
return [];
|
return [];
|
||||||
@@ -249,11 +257,7 @@ describe("image tool implicit imageModel config", () => {
|
|||||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-image-"));
|
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-image-"));
|
||||||
try {
|
try {
|
||||||
const cfg = createMinimaxImageConfig();
|
const cfg = createMinimaxImageConfig();
|
||||||
const tool = createImageTool({ config: cfg, agentDir });
|
const tool = requireImageTool(createImageTool({ config: cfg, agentDir }));
|
||||||
expect(tool).not.toBeNull();
|
|
||||||
if (!tool) {
|
|
||||||
throw new Error("expected image tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const violations = findSchemaUnionKeywords(tool.parameters, "image.parameters");
|
const violations = findSchemaUnionKeywords(tool.parameters, "image.parameters");
|
||||||
expect(violations).toEqual([]);
|
expect(violations).toEqual([]);
|
||||||
@@ -279,11 +283,7 @@ describe("image tool implicit imageModel config", () => {
|
|||||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-image-"));
|
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-image-"));
|
||||||
try {
|
try {
|
||||||
const cfg = createMinimaxImageConfig();
|
const cfg = createMinimaxImageConfig();
|
||||||
const tool = createImageTool({ config: cfg, agentDir });
|
const tool = requireImageTool(createImageTool({ config: cfg, agentDir }));
|
||||||
expect(tool).not.toBeNull();
|
|
||||||
if (!tool) {
|
|
||||||
throw new Error("expected image tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(JSON.parse(JSON.stringify(tool.parameters))).toEqual({
|
expect(JSON.parse(JSON.stringify(tool.parameters))).toEqual({
|
||||||
type: "object",
|
type: "object",
|
||||||
@@ -312,11 +312,7 @@ describe("image tool implicit imageModel config", () => {
|
|||||||
try {
|
try {
|
||||||
const cfg = createMinimaxImageConfig();
|
const cfg = createMinimaxImageConfig();
|
||||||
|
|
||||||
const withoutWorkspace = createImageTool({ config: cfg, agentDir });
|
const withoutWorkspace = requireImageTool(createImageTool({ config: cfg, agentDir }));
|
||||||
expect(withoutWorkspace).not.toBeNull();
|
|
||||||
if (!withoutWorkspace) {
|
|
||||||
throw new Error("expected image tool");
|
|
||||||
}
|
|
||||||
await expect(
|
await expect(
|
||||||
withoutWorkspace.execute("t0", {
|
withoutWorkspace.execute("t0", {
|
||||||
prompt: "Describe the image.",
|
prompt: "Describe the image.",
|
||||||
@@ -324,11 +320,9 @@ describe("image tool implicit imageModel config", () => {
|
|||||||
}),
|
}),
|
||||||
).rejects.toThrow(/Local media path is not under an allowed directory/i);
|
).rejects.toThrow(/Local media path is not under an allowed directory/i);
|
||||||
|
|
||||||
const withWorkspace = createImageTool({ config: cfg, agentDir, workspaceDir });
|
const withWorkspace = requireImageTool(
|
||||||
expect(withWorkspace).not.toBeNull();
|
createImageTool({ config: cfg, agentDir, workspaceDir }),
|
||||||
if (!withWorkspace) {
|
);
|
||||||
throw new Error("expected image tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
await expectImageToolExecOk(withWorkspace, imagePath);
|
await expectImageToolExecOk(withWorkspace, imagePath);
|
||||||
|
|
||||||
@@ -347,11 +341,7 @@ describe("image tool implicit imageModel config", () => {
|
|||||||
const cfg = createMinimaxImageConfig();
|
const cfg = createMinimaxImageConfig();
|
||||||
|
|
||||||
const tools = createOpenClawCodingTools({ config: cfg, agentDir });
|
const tools = createOpenClawCodingTools({ config: cfg, agentDir });
|
||||||
const tool = tools.find((candidate) => candidate.name === "image");
|
const tool = requireImageTool(tools.find((candidate) => candidate.name === "image"));
|
||||||
expect(tool).not.toBeNull();
|
|
||||||
if (!tool) {
|
|
||||||
throw new Error("expected image tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
await expectImageToolExecOk(tool, imagePath);
|
await expectImageToolExecOk(tool, imagePath);
|
||||||
|
|
||||||
@@ -375,11 +365,7 @@ describe("image tool implicit imageModel config", () => {
|
|||||||
const cfg: OpenClawConfig = {
|
const cfg: OpenClawConfig = {
|
||||||
agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
|
agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
|
||||||
};
|
};
|
||||||
const tool = createImageTool({ config: cfg, agentDir, sandbox });
|
const tool = requireImageTool(createImageTool({ config: cfg, agentDir, sandbox }));
|
||||||
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(
|
await expect(tool.execute("t1", { image: "https://example.com/a.png" })).rejects.toThrow(
|
||||||
/Sandboxed image tool does not allow remote URLs/i,
|
/Sandboxed image tool does not allow remote URLs/i,
|
||||||
@@ -405,18 +391,7 @@ describe("image tool implicit imageModel config", () => {
|
|||||||
Buffer.from(pngB64, "base64"),
|
Buffer.from(pngB64, "base64"),
|
||||||
);
|
);
|
||||||
|
|
||||||
const fetch = vi.fn().mockResolvedValue({
|
const fetch = stubMinimaxOkFetch();
|
||||||
ok: true,
|
|
||||||
status: 200,
|
|
||||||
statusText: "OK",
|
|
||||||
headers: new Headers(),
|
|
||||||
json: async () => ({
|
|
||||||
content: "ok",
|
|
||||||
base_resp: { status_code: 0, status_msg: "" },
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
global.fetch = withFetchPreconnect(fetch);
|
|
||||||
vi.stubEnv("MINIMAX_API_KEY", "minimax-test");
|
|
||||||
|
|
||||||
const cfg: OpenClawConfig = {
|
const cfg: OpenClawConfig = {
|
||||||
agents: {
|
agents: {
|
||||||
@@ -427,11 +402,7 @@ describe("image tool implicit imageModel config", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
const sandbox = { root: sandboxRoot, bridge: createHostSandboxFsBridge(sandboxRoot) };
|
const sandbox = { root: sandboxRoot, bridge: createHostSandboxFsBridge(sandboxRoot) };
|
||||||
const tool = createImageTool({ config: cfg, agentDir, sandbox });
|
const tool = requireImageTool(createImageTool({ config: cfg, agentDir, sandbox }));
|
||||||
expect(tool).not.toBeNull();
|
|
||||||
if (!tool) {
|
|
||||||
throw new Error("expected image tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await tool.execute("t1", {
|
const res = await tool.execute("t1", {
|
||||||
prompt: "Describe the image.",
|
prompt: "Describe the image.",
|
||||||
@@ -495,11 +466,7 @@ describe("image tool MiniMax VLM routing", () => {
|
|||||||
const cfg: OpenClawConfig = {
|
const cfg: OpenClawConfig = {
|
||||||
agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
|
agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
|
||||||
};
|
};
|
||||||
const tool = createImageTool({ config: cfg, agentDir });
|
const tool = requireImageTool(createImageTool({ config: cfg, agentDir }));
|
||||||
expect(tool).not.toBeNull();
|
|
||||||
if (!tool) {
|
|
||||||
throw new Error("expected image tool");
|
|
||||||
}
|
|
||||||
return { fetch, tool };
|
return { fetch, tool };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user