mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 11:02:17 +00:00
fix(coding-agent): allow suppressing custom tool transcript blocks
This commit is contained in:
parent
95276df060
commit
480d6bc62d
4 changed files with 114 additions and 5 deletions
72
packages/coding-agent/test/tool-execution-component.test.ts
Normal file
72
packages/coding-agent/test/tool-execution-component.test.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { Text, type TUI } from "@mariozechner/pi-tui";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import stripAnsi from "strip-ansi";
|
||||
import { beforeAll, describe, expect, test } from "vitest";
|
||||
import type { ToolDefinition } from "../src/core/extensions/types.js";
|
||||
import { ToolExecutionComponent } from "../src/modes/interactive/components/tool-execution.js";
|
||||
import { initTheme } from "../src/modes/interactive/theme/theme.js";
|
||||
|
||||
function createBaseToolDefinition(): ToolDefinition {
|
||||
return {
|
||||
name: "custom_tool",
|
||||
label: "custom_tool",
|
||||
description: "custom tool",
|
||||
parameters: Type.Any(),
|
||||
execute: async () => ({
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
details: {},
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function createFakeTui(): TUI {
|
||||
return {
|
||||
requestRender: () => {},
|
||||
} as unknown as TUI;
|
||||
}
|
||||
|
||||
describe("ToolExecutionComponent custom renderer suppression", () => {
|
||||
beforeAll(() => {
|
||||
initTheme("dark");
|
||||
});
|
||||
|
||||
test("renders no lines when custom renderers return undefined", () => {
|
||||
const toolDefinition: ToolDefinition = {
|
||||
...createBaseToolDefinition(),
|
||||
renderCall: () => undefined,
|
||||
renderResult: () => undefined,
|
||||
};
|
||||
|
||||
const component = new ToolExecutionComponent("custom_tool", {}, {}, toolDefinition, createFakeTui());
|
||||
expect(component.render(120)).toEqual([]);
|
||||
|
||||
component.updateResult(
|
||||
{
|
||||
content: [{ type: "text", text: "hidden" }],
|
||||
details: {},
|
||||
isError: false,
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
expect(component.render(120)).toEqual([]);
|
||||
});
|
||||
|
||||
test("keeps built-in tool rendering visible", () => {
|
||||
const component = new ToolExecutionComponent("read", { path: "README.md" }, {}, undefined, createFakeTui());
|
||||
const rendered = stripAnsi(component.render(120).join("\n"));
|
||||
expect(rendered).toContain("read");
|
||||
});
|
||||
|
||||
test("keeps custom tool rendering visible when renderer returns a component", () => {
|
||||
const toolDefinition: ToolDefinition = {
|
||||
...createBaseToolDefinition(),
|
||||
renderCall: () => new Text("custom call", 0, 0),
|
||||
renderResult: () => undefined,
|
||||
};
|
||||
|
||||
const component = new ToolExecutionComponent("custom_tool", {}, {}, toolDefinition, createFakeTui());
|
||||
const rendered = stripAnsi(component.render(120).join("\n"));
|
||||
expect(rendered).toContain("custom call");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue