test: cover browser snapshot labels and efficient mode
This commit is contained in:
@@ -80,14 +80,9 @@ function resolveProviderToolPolicy(params: {
|
||||
const normalizedProvider = normalizeProviderKey(provider);
|
||||
const rawModelId = params.modelId?.trim().toLowerCase();
|
||||
const fullModelId =
|
||||
rawModelId && !rawModelId.includes("/")
|
||||
? `${normalizedProvider}/${rawModelId}`
|
||||
: rawModelId;
|
||||
rawModelId && !rawModelId.includes("/") ? `${normalizedProvider}/${rawModelId}` : rawModelId;
|
||||
|
||||
const candidates = [
|
||||
...(fullModelId ? [fullModelId] : []),
|
||||
normalizedProvider,
|
||||
];
|
||||
const candidates = [...(fullModelId ? [fullModelId] : []), normalizedProvider];
|
||||
|
||||
for (const key of candidates) {
|
||||
const match = lookup.get(key);
|
||||
|
||||
@@ -125,8 +125,7 @@ export function createClawdbotCodingTools(options?: {
|
||||
});
|
||||
const profilePolicy = resolveToolProfilePolicy(profile);
|
||||
const providerProfilePolicy = resolveToolProfilePolicy(providerProfile);
|
||||
const scopeKey =
|
||||
options?.exec?.scopeKey ?? (agentId ? `agent:${agentId}` : undefined);
|
||||
const scopeKey = options?.exec?.scopeKey ?? (agentId ? `agent:${agentId}` : undefined);
|
||||
const subagentPolicy =
|
||||
isSubagentSessionKey(options?.sessionKey) && options?.sessionKey
|
||||
? resolveSubagentToolPolicy(options.config)
|
||||
@@ -240,9 +239,7 @@ export function createClawdbotCodingTools(options?: {
|
||||
hasRepliedRef: options?.hasRepliedRef,
|
||||
}),
|
||||
];
|
||||
const toolsFiltered = profilePolicy
|
||||
? filterToolsByPolicy(tools, profilePolicy)
|
||||
: tools;
|
||||
const toolsFiltered = profilePolicy ? filterToolsByPolicy(tools, profilePolicy) : tools;
|
||||
const providerProfileFiltered = providerProfilePolicy
|
||||
? filterToolsByPolicy(toolsFiltered, providerProfilePolicy)
|
||||
: toolsFiltered;
|
||||
|
||||
@@ -52,6 +52,17 @@ vi.mock("../../config/config.js", () => ({
|
||||
loadConfig: vi.fn(() => ({ browser: {} })),
|
||||
}));
|
||||
|
||||
const toolCommonMocks = vi.hoisted(() => ({
|
||||
imageResultFromFile: vi.fn(),
|
||||
}));
|
||||
vi.mock("./common.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./common.js")>("./common.js");
|
||||
return {
|
||||
...actual,
|
||||
imageResultFromFile: toolCommonMocks.imageResultFromFile,
|
||||
};
|
||||
});
|
||||
|
||||
import { DEFAULT_AI_SNAPSHOT_MAX_CHARS } from "../../browser/constants.js";
|
||||
import { createBrowserTool } from "./browser-tool.js";
|
||||
|
||||
@@ -103,3 +114,47 @@ describe("browser tool snapshot maxChars", () => {
|
||||
expect(Object.hasOwn(opts ?? {}, "maxChars")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("browser tool snapshot labels", () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("returns image + text when labels are requested", async () => {
|
||||
const tool = createBrowserTool();
|
||||
const imageResult = {
|
||||
content: [
|
||||
{ type: "text", text: "label text" },
|
||||
{ type: "image", data: "base64", mimeType: "image/png" },
|
||||
],
|
||||
details: { path: "/tmp/snap.png" },
|
||||
};
|
||||
|
||||
toolCommonMocks.imageResultFromFile.mockResolvedValueOnce(imageResult);
|
||||
browserClientMocks.browserSnapshot.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
format: "ai",
|
||||
targetId: "t1",
|
||||
url: "https://example.com",
|
||||
snapshot: "label text",
|
||||
imagePath: "/tmp/snap.png",
|
||||
});
|
||||
|
||||
const result = await tool.execute?.(null, {
|
||||
action: "snapshot",
|
||||
format: "ai",
|
||||
labels: true,
|
||||
});
|
||||
|
||||
expect(toolCommonMocks.imageResultFromFile).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
path: "/tmp/snap.png",
|
||||
extraText: "label text",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual(imageResult);
|
||||
expect(result?.content).toHaveLength(2);
|
||||
expect(result?.content?.[0]).toMatchObject({ type: "text", text: "label text" });
|
||||
expect(result?.content?.[1]).toMatchObject({ type: "image" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user