mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-27 00:29:34 +00:00
refactor(core): remove unused helper wrappers
This commit is contained in:
@@ -3,20 +3,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
extractToolResultMediaArtifact,
|
||||
extractToolResultMediaPaths,
|
||||
filterToolResultMediaUrls,
|
||||
isToolResultMediaTrusted,
|
||||
} from "./embedded-agent-subscribe.tools.js";
|
||||
|
||||
describe("extractToolResultMediaPaths", () => {
|
||||
it("returns empty array for null/undefined", () => {
|
||||
expect(extractToolResultMediaPaths(null)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaPaths(undefined)).toStrictEqual([]);
|
||||
describe("extractToolResultMediaArtifact", () => {
|
||||
it("returns undefined for null/undefined", () => {
|
||||
expect(extractToolResultMediaArtifact(null)).toBeUndefined();
|
||||
expect(extractToolResultMediaArtifact(undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns empty array for non-object", () => {
|
||||
expect(extractToolResultMediaPaths("hello")).toStrictEqual([]);
|
||||
expect(extractToolResultMediaPaths(42)).toStrictEqual([]);
|
||||
it("returns undefined for non-object", () => {
|
||||
expect(extractToolResultMediaArtifact("hello")).toBeUndefined();
|
||||
expect(extractToolResultMediaArtifact(42)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("extracts structured details.media without content blocks", () => {
|
||||
@@ -81,8 +80,8 @@ describe("extractToolResultMediaPaths", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("returns empty array when content has no text or image blocks", () => {
|
||||
expect(extractToolResultMediaPaths({ content: [{ type: "other" }] })).toStrictEqual([]);
|
||||
it("returns undefined when content has no text or image blocks", () => {
|
||||
expect(extractToolResultMediaArtifact({ content: [{ type: "other" }] })).toBeUndefined();
|
||||
});
|
||||
|
||||
it("extracts structured media with audioAsVoice", () => {
|
||||
@@ -125,7 +124,9 @@ describe("extractToolResultMediaPaths", () => {
|
||||
],
|
||||
details: { path: "/tmp/screenshot.png" },
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual(["/tmp/screenshot.png"]);
|
||||
expect(extractToolResultMediaArtifact(result)).toEqual({
|
||||
mediaUrls: ["/tmp/screenshot.png"],
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores media-looking text content without structured media or image fallback", () => {
|
||||
@@ -135,7 +136,7 @@ describe("extractToolResultMediaPaths", () => {
|
||||
{ type: "text", text: "MEDIA:/tmp/page2.png" },
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("falls back to details.path when image content exists", () => {
|
||||
@@ -150,10 +151,12 @@ describe("extractToolResultMediaPaths", () => {
|
||||
],
|
||||
details: { path: "/tmp/generated.png" },
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual(["/tmp/generated.png"]);
|
||||
expect(extractToolResultMediaArtifact(result)).toEqual({
|
||||
mediaUrls: ["/tmp/generated.png"],
|
||||
});
|
||||
});
|
||||
|
||||
it("returns empty array when image content exists but no details.path", () => {
|
||||
it("returns undefined when image content exists but no details.path", () => {
|
||||
// Embedded read tool: has image content but no path anywhere in the result.
|
||||
const result = {
|
||||
content: [
|
||||
@@ -161,21 +164,21 @@ describe("extractToolResultMediaPaths", () => {
|
||||
{ type: "image", data: "base64data", mimeType: "image/png" },
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("ignores null/undefined items in content array", () => {
|
||||
const result = {
|
||||
content: [null, undefined, { type: "text", text: "MEDIA:/tmp/ok.png" }],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns empty array for text-only results", () => {
|
||||
const result = {
|
||||
content: [{ type: "text", text: "Command executed successfully" }],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("ignores details.path when no image content exists", () => {
|
||||
@@ -186,7 +189,7 @@ describe("extractToolResultMediaPaths", () => {
|
||||
content: [{ type: "text", text: "File saved" }],
|
||||
details: { path: "/tmp/data.json" },
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("handles details.path with whitespace", () => {
|
||||
@@ -194,7 +197,9 @@ describe("extractToolResultMediaPaths", () => {
|
||||
content: [{ type: "image", data: "base64", mimeType: "image/png" }],
|
||||
details: { path: " /tmp/image.png " },
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual(["/tmp/image.png"]);
|
||||
expect(extractToolResultMediaArtifact(result)).toEqual({
|
||||
mediaUrls: ["/tmp/image.png"],
|
||||
});
|
||||
});
|
||||
|
||||
it("skips empty details.path", () => {
|
||||
@@ -202,7 +207,7 @@ describe("extractToolResultMediaPaths", () => {
|
||||
content: [{ type: "image", data: "base64", mimeType: "image/png" }],
|
||||
details: { path: " " },
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not match <media:audio> placeholder as media", () => {
|
||||
@@ -214,14 +219,14 @@ describe("extractToolResultMediaPaths", () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not match <media:image> placeholder as media", () => {
|
||||
const result = {
|
||||
content: [{ type: "text", text: "<media:image> (2 images)" }],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not match other media placeholder variants", () => {
|
||||
@@ -234,7 +239,7 @@ describe("extractToolResultMediaPaths", () => {
|
||||
const result = {
|
||||
content: [{ type: "text", text: `${tag} some context` }],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -247,7 +252,7 @@ describe("extractToolResultMediaPaths", () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not treat malformed media-looking prose as a file path", () => {
|
||||
@@ -259,7 +264,7 @@ describe("extractToolResultMediaPaths", () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toStrictEqual([]);
|
||||
expect(extractToolResultMediaArtifact(result)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("trusts image_generate local media paths", () => {
|
||||
|
||||
@@ -673,10 +673,6 @@ export function extractToolResultMediaArtifact(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function extractToolResultMediaPaths(result: unknown): string[] {
|
||||
return extractToolResultMediaArtifact(result)?.mediaUrls ?? [];
|
||||
}
|
||||
|
||||
export function extractToolErrorCode(result: unknown): string | undefined {
|
||||
if (!result || typeof result !== "object") {
|
||||
return undefined;
|
||||
|
||||
@@ -42,10 +42,6 @@ function newStateDir(homedir: () => string = resolveDefaultHomeDir): string {
|
||||
return path.join(homedir(), NEW_STATE_DIRNAME);
|
||||
}
|
||||
|
||||
export function resolveLegacyStateDir(homedir: () => string = resolveDefaultHomeDir): string {
|
||||
return legacyStateDirs(homedir)[0] ?? newStateDir(homedir);
|
||||
}
|
||||
|
||||
export function resolveLegacyStateDirs(homedir: () => string = resolveDefaultHomeDir): string[] {
|
||||
return legacyStateDirs(homedir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user