Download packages/coding-agent/test/custom-message.test.ts from SaylorTwift/pi: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/SaylorTwift/pi/resolve/main/packages/coding-agent/test/custom-message.test.ts
- Command line
-
hf download hf://SaylorTwift/pi/packages/coding-agent/test/custom-message.test.ts
-
curl -L -o custom-message.test.ts https://huggingface.co/SaylorTwift/pi/resolve/main/packages/coding-agent/test/custom-message.test.ts
1.46 kB
| import { Text } from "@earendil-works/pi-tui"; | |
| import { describe, expect, test } from "vitest"; | |
| import type { MessageRenderer, MessageRenderOptions } from "../src/core/extensions/types.ts"; | |
| import type { CustomMessage } from "../src/core/messages.ts"; | |
| import { CustomMessageComponent } from "../src/modes/interactive/components/custom-message.ts"; | |
| import { initTheme } from "../src/modes/interactive/theme/theme.ts"; | |
| import { stripAnsi } from "../src/utils/ansi.ts"; | |
| describe("CustomMessageComponent", () => { | |
| test("provides output padding to custom renderers and updates it", () => { | |
| initTheme("dark"); | |
| const optionsSeen: MessageRenderOptions[] = []; | |
| const renderer: MessageRenderer = (_message, options) => { | |
| optionsSeen.push(options); | |
| return new Text("custom", options.outputPad, 0); | |
| }; | |
| const message: CustomMessage = { | |
| role: "custom", | |
| customType: "test", | |
| content: "custom", | |
| display: true, | |
| timestamp: Date.now(), | |
| }; | |
| const component = new CustomMessageComponent(message, renderer, undefined, 1); | |
| expect(optionsSeen).toEqual([{ expanded: false, outputPad: 1 }]); | |
| expect( | |
| component | |
| .render(40) | |
| .map(stripAnsi) | |
| .some((line) => line.startsWith(" custom")), | |
| ).toBe(true); | |
| component.setOutputPad(0); | |
| expect(optionsSeen.at(-1)).toEqual({ expanded: false, outputPad: 0 }); | |
| expect( | |
| component | |
| .render(40) | |
| .map(stripAnsi) | |
| .some((line) => line.startsWith("custom")), | |
| ).toBe(true); | |
| }); | |
| }); | |