Skip to content

Commit 84dc9f1

Browse files
committed
test(agents): cover single image generation media delivery
1 parent e174d96 commit 84dc9f1

2 files changed

Lines changed: 61 additions & 1 deletion

src/agents/pi-embedded-subscribe.handlers.tools.media.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ describe("handleToolExecutionEnd media emission", () => {
388388
expect(ctx.state.pendingToolMediaUrls).toEqual([]);
389389
});
390390

391-
it("still queues structured media for markdown verbose output", async () => {
391+
it("queues structured media once for markdown verbose output", async () => {
392392
const ctx = await handleVerboseGeneratedImage("markdown");
393393

394394
expect(ctx.emitToolOutput).toHaveBeenCalled();

src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.subscribeembeddedpisession.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,66 @@ describe("subscribeEmbeddedPiSession", () => {
309309
expect(payload?.mediaUrls).toBeUndefined();
310310
});
311311

312+
it("delivers generated image media once in markdown verbose output", async () => {
313+
const onToolResult = vi.fn();
314+
const onBlockReply = vi.fn();
315+
const { emit } = createSubscribedHarness({
316+
runId: "run",
317+
onToolResult,
318+
onBlockReply,
319+
verboseLevel: "full",
320+
blockReplyBreak: "message_end",
321+
builtinToolNames: new Set(["image_generate"]),
322+
});
323+
324+
emitToolRun({
325+
emit,
326+
toolName: "image_generate",
327+
toolCallId: "tool-1",
328+
isError: false,
329+
result: {
330+
content: [
331+
{
332+
type: "text",
333+
text: "Generated 1 image with google/gemini-3.1-flash-image-preview.\nMEDIA:/tmp/generated.png",
334+
},
335+
],
336+
details: {
337+
media: {
338+
mediaUrls: ["/tmp/generated.png"],
339+
},
340+
},
341+
},
342+
});
343+
344+
await vi.waitFor(() => {
345+
expect(onToolResult).toHaveBeenCalled();
346+
});
347+
const toolPayload = onToolResult.mock.calls.at(-1)?.[0] as
348+
| { text?: string; mediaUrls?: string[] }
349+
| undefined;
350+
expect(toolPayload?.text ?? "").toContain("Generated 1 image");
351+
expect(toolPayload?.mediaUrls).toBeUndefined();
352+
353+
emit({ type: "message_start", message: { role: "assistant" } });
354+
emitAssistantTextDelta(emit, "Here is the image.");
355+
emit({
356+
type: "message_end",
357+
message: {
358+
role: "assistant",
359+
content: [{ type: "text", text: "Here is the image." }],
360+
},
361+
});
362+
await flushBlockReplyCallbacks();
363+
364+
expect(onBlockReply).toHaveBeenCalledWith(
365+
expect.objectContaining({
366+
text: "Here is the image.",
367+
mediaUrls: ["/tmp/generated.png"],
368+
}),
369+
);
370+
});
371+
312372
it("attaches media from internal completion events even when assistant omits MEDIA lines", async () => {
313373
const onBlockReply = vi.fn();
314374
const { emit } = createSubscribedHarness({

0 commit comments

Comments
 (0)