char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somtests: cut test sprawl1c0a335

main
1.5 KiB38 linesraw
1import { assertEquals } from "@std/assert";
2import type { ImageContent, ToolResultMessage } from "@earendil-works/pi-ai";
3import { isImageResult, toolResult } from "./tool-result.ts";
4
5const first: ImageContent = { type: "image", data: "first-image-data", mimeType: "image/png" };
6const second: ImageContent = { type: "image", data: "second-image-data", mimeType: "image/jpeg" };
7const result = (content: ToolResultMessage["content"], isError = false): ToolResultMessage => ({
8  role: "toolResult",
9  toolCallId: "image-call",
10  toolName: "read",
11  content,
12  isError,
13  timestamp: 0,
14});
15
16Deno.test("tool results keep every image beside their text or error, and only real images count", () => {
17  const text = (text: string) => ({ type: "text" as const, text });
18  assertEquals(
19    toolResult(result([text("before"), first, text("between"), second])),
20    { result: "before\nbetween", error: null, images: [first, second] },
21  );
22  assertEquals(toolResult(result([first])), { result: "", error: null, images: [first] });
23  assertEquals(
24    toolResult(result([first, text("Script failed")], true)),
25    { result: null, error: "Script failed", images: [first] },
26  );
27  assertEquals(toolResult(null), { result: null, error: null, images: [] });
28  assertEquals(toolResult(result([text("plain output")])), {
29    result: "plain output",
30    error: null,
31    images: [],
32  });
33
34  assertEquals(isImageResult({ ...first, id: "screenshot-id" }), true);
35  for (const value of [null, "image", { type: "image", data: "bytes" }]) {
36    assertEquals(isImageResult(value), false);
37  }
38});