test: dedupe fixtures and test harness setup

This commit is contained in:
Peter Steinberger
2026-02-23 05:43:30 +00:00
parent 8af19ddc5b
commit 1c753ea786
75 changed files with 1886 additions and 2136 deletions

View File

@@ -78,6 +78,21 @@ async function emitPngMediaToolResult(
});
}
async function emitUntrustedToolMediaResult(
ctx: EmbeddedPiSubscribeContext,
mediaPathOrUrl: string,
) {
await handleToolExecutionEnd(ctx, {
type: "tool_execution_end",
toolName: "plugin_tool",
toolCallId: "tc-1",
isError: false,
result: {
content: [{ type: "text", text: `MEDIA:${mediaPathOrUrl}` }],
},
});
}
describe("handleToolExecutionEnd media emission", () => {
it("does not warn for read tool when path is provided via file_path alias", async () => {
const ctx = createMockContext();
@@ -107,15 +122,7 @@ describe("handleToolExecutionEnd media emission", () => {
const onToolResult = vi.fn();
const ctx = createMockContext({ shouldEmitToolOutput: false, onToolResult });
await handleToolExecutionEnd(ctx, {
type: "tool_execution_end",
toolName: "plugin_tool",
toolCallId: "tc-1",
isError: false,
result: {
content: [{ type: "text", text: "MEDIA:/tmp/secret.png" }],
},
});
await emitUntrustedToolMediaResult(ctx, "/tmp/secret.png");
expect(onToolResult).not.toHaveBeenCalled();
});
@@ -124,15 +131,7 @@ describe("handleToolExecutionEnd media emission", () => {
const onToolResult = vi.fn();
const ctx = createMockContext({ shouldEmitToolOutput: false, onToolResult });
await handleToolExecutionEnd(ctx, {
type: "tool_execution_end",
toolName: "plugin_tool",
toolCallId: "tc-1",
isError: false,
result: {
content: [{ type: "text", text: "MEDIA:https://example.com/file.png" }],
},
});
await emitUntrustedToolMediaResult(ctx, "https://example.com/file.png");
expect(onToolResult).toHaveBeenCalledWith({
mediaUrls: ["https://example.com/file.png"],