test(agents): dedupe media and thinking sanitize test setup

This commit is contained in:
Peter Steinberger
2026-02-19 09:06:28 +00:00
parent 4c539f6abc
commit 6f568f3b17
2 changed files with 53 additions and 69 deletions

View File

@@ -59,6 +59,25 @@ function createMockContext(overrides?: {
} as unknown as EmbeddedPiSubscribeContext;
}
async function emitPngMediaToolResult(
ctx: EmbeddedPiSubscribeContext,
opts?: { isError?: boolean },
) {
await handleToolExecutionEnd(ctx, {
type: "tool_execution_end",
toolName: "browser",
toolCallId: "tc-1",
isError: opts?.isError ?? false,
result: {
content: [
{ type: "text", text: "MEDIA:/tmp/screenshot.png" },
{ type: "image", data: "base64", mimeType: "image/png" },
],
details: { path: "/tmp/screenshot.png" },
},
});
}
describe("handleToolExecutionEnd media emission", () => {
it("does not warn for read tool when path is provided via file_path alias", async () => {
const ctx = createMockContext();
@@ -77,19 +96,7 @@ describe("handleToolExecutionEnd media emission", () => {
const onToolResult = vi.fn();
const ctx = createMockContext({ shouldEmitToolOutput: false, onToolResult });
await handleToolExecutionEnd(ctx, {
type: "tool_execution_end",
toolName: "browser",
toolCallId: "tc-1",
isError: false,
result: {
content: [
{ type: "text", text: "MEDIA:/tmp/screenshot.png" },
{ type: "image", data: "base64", mimeType: "image/png" },
],
details: { path: "/tmp/screenshot.png" },
},
});
await emitPngMediaToolResult(ctx);
expect(onToolResult).toHaveBeenCalledWith({
mediaUrls: ["/tmp/screenshot.png"],
@@ -100,19 +107,7 @@ describe("handleToolExecutionEnd media emission", () => {
const onToolResult = vi.fn();
const ctx = createMockContext({ shouldEmitToolOutput: true, onToolResult });
await handleToolExecutionEnd(ctx, {
type: "tool_execution_end",
toolName: "browser",
toolCallId: "tc-1",
isError: false,
result: {
content: [
{ type: "text", text: "MEDIA:/tmp/screenshot.png" },
{ type: "image", data: "base64", mimeType: "image/png" },
],
details: { path: "/tmp/screenshot.png" },
},
});
await emitPngMediaToolResult(ctx);
// onToolResult should NOT be called by the new media path (emitToolOutput handles it).
// It may be called by emitToolOutput, but the new block should not fire.
@@ -133,19 +128,7 @@ describe("handleToolExecutionEnd media emission", () => {
const onToolResult = vi.fn();
const ctx = createMockContext({ shouldEmitToolOutput: false, onToolResult });
await handleToolExecutionEnd(ctx, {
type: "tool_execution_end",
toolName: "browser",
toolCallId: "tc-1",
isError: true,
result: {
content: [
{ type: "text", text: "MEDIA:/tmp/screenshot.png" },
{ type: "image", data: "base64", mimeType: "image/png" },
],
details: { path: "/tmp/screenshot.png" },
},
});
await emitPngMediaToolResult(ctx, { isError: true });
expect(onToolResult).not.toHaveBeenCalled();
});