mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 11:18:37 +00:00
perf(test): fold acp event mapper tests into client suite
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
|
import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import { resolvePermissionRequest } from "./client.js";
|
import { resolvePermissionRequest } from "./client.js";
|
||||||
|
import { extractAttachmentsFromPrompt, extractTextFromPrompt } from "./event-mapper.js";
|
||||||
|
|
||||||
function makePermissionRequest(
|
function makePermissionRequest(
|
||||||
overrides: Partial<RequestPermissionRequest> = {},
|
overrides: Partial<RequestPermissionRequest> = {},
|
||||||
@@ -139,3 +140,32 @@ describe("resolvePermissionRequest", () => {
|
|||||||
expect(res).toEqual({ outcome: { outcome: "cancelled" } });
|
expect(res).toEqual({ outcome: { outcome: "cancelled" } });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("acp event mapper", () => {
|
||||||
|
it("extracts text and resource blocks into prompt text", () => {
|
||||||
|
const text = extractTextFromPrompt([
|
||||||
|
{ type: "text", text: "Hello" },
|
||||||
|
{ type: "resource", resource: { text: "File contents" } },
|
||||||
|
{ type: "resource_link", uri: "https://example.com", title: "Spec" },
|
||||||
|
{ type: "image", data: "abc", mimeType: "image/png" },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(text).toBe("Hello\nFile contents\n[Resource link (Spec)] https://example.com");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts image blocks into gateway attachments", () => {
|
||||||
|
const attachments = extractAttachmentsFromPrompt([
|
||||||
|
{ type: "image", data: "abc", mimeType: "image/png" },
|
||||||
|
{ type: "image", data: "", mimeType: "image/png" },
|
||||||
|
{ type: "text", text: "ignored" },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(attachments).toEqual([
|
||||||
|
{
|
||||||
|
type: "image",
|
||||||
|
mimeType: "image/png",
|
||||||
|
content: "abc",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import { extractAttachmentsFromPrompt, extractTextFromPrompt } from "./event-mapper.js";
|
|
||||||
|
|
||||||
describe("acp event mapper", () => {
|
|
||||||
it("extracts text and resource blocks into prompt text", () => {
|
|
||||||
const text = extractTextFromPrompt([
|
|
||||||
{ type: "text", text: "Hello" },
|
|
||||||
{ type: "resource", resource: { text: "File contents" } },
|
|
||||||
{ type: "resource_link", uri: "https://example.com", title: "Spec" },
|
|
||||||
{ type: "image", data: "abc", mimeType: "image/png" },
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(text).toBe("Hello\nFile contents\n[Resource link (Spec)] https://example.com");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("extracts image blocks into gateway attachments", () => {
|
|
||||||
const attachments = extractAttachmentsFromPrompt([
|
|
||||||
{ type: "image", data: "abc", mimeType: "image/png" },
|
|
||||||
{ type: "image", data: "", mimeType: "image/png" },
|
|
||||||
{ type: "text", text: "ignored" },
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(attachments).toEqual([
|
|
||||||
{
|
|
||||||
type: "image",
|
|
||||||
mimeType: "image/png",
|
|
||||||
content: "abc",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user