clanker-agent/packages/coding-agent/test/tool-execution-component.test.ts
Harivansh Rathi 67168d8289 chore: rebrand companion-os to clanker-agent
- Rename all package names from companion-* to clanker-*
- Update npm scopes from @mariozechner to @harivansh-afk
- Rename config directories .companion -> .clanker
- Rename environment variables COMPANION_* -> CLANKER_*
- Update all documentation, README files, and install scripts
- Rename package directories (companion-channels, companion-grind, companion-teams)
- Update GitHub URLs to harivansh-afk/clanker-agent
- Preserve full git history from companion-cloud monorepo
2026-03-26 16:22:52 -04:00

90 lines
2.4 KiB
TypeScript

import { Text, type TUI } from "@mariozechner/clanker-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");
});
});