fix(coding-agent): tighten HTML export tool spacing
This commit is contained in:
@@ -1,12 +1,41 @@
|
||||
import type { Component } from "@mariozechner/pi-tui";
|
||||
import { readFileSync } from "fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ansiLinesToHtml } from "../src/core/export-html/ansi-to-html.js";
|
||||
import { createToolHtmlRenderer } from "../src/core/export-html/tool-renderer.js";
|
||||
import type { ToolDefinition } from "../src/core/extensions/types.js";
|
||||
import type { Theme } from "../src/modes/interactive/theme/theme.js";
|
||||
|
||||
describe("export HTML tool output whitespace", () => {
|
||||
it("preserves whitespace for plain-text tool output containers", () => {
|
||||
it("preserves whitespace for plain-text tool output lines without preserving template whitespace", () => {
|
||||
const css = readFileSync(new URL("../src/core/export-html/template.css", import.meta.url), "utf-8");
|
||||
|
||||
expect(css).toMatch(
|
||||
/\.tool-output > div,\s*\.output-preview,\s*\.output-full\s*\{[\s\S]*?white-space:\s*pre-wrap;/,
|
||||
/\.output-preview > div:not\(\.expand-hint\),\s*\.output-full > div:not\(\.expand-hint\) \{[\s\S]*?white-space:\s*pre-wrap;/,
|
||||
);
|
||||
expect(css).not.toMatch(/\.output-preview,\s*\.output-full\s*\{[\s\S]*?white-space:\s*pre-wrap;/);
|
||||
});
|
||||
|
||||
it("does not insert source whitespace between ANSI-rendered lines", () => {
|
||||
expect(ansiLinesToHtml(["one", "two"])).toBe('<div class="ansi-line">one</div><div class="ansi-line">two</div>');
|
||||
});
|
||||
|
||||
it("trims TUI spacing lines from custom tool result HTML", () => {
|
||||
const component: Component = { render: () => ["", "\u001b[31mone\u001b[0m", "two", ""], invalidate: () => {} };
|
||||
const tool = {
|
||||
name: "custom",
|
||||
label: "custom",
|
||||
description: "custom",
|
||||
renderResult: () => component,
|
||||
} as unknown as ToolDefinition;
|
||||
const renderer = createToolHtmlRenderer({
|
||||
getToolDefinition: () => tool,
|
||||
theme: {} as Theme,
|
||||
cwd: "/tmp",
|
||||
});
|
||||
|
||||
expect(renderer.renderResult("id", "custom", [], undefined, false)?.expanded).toBe(
|
||||
'<div class="ansi-line"><span style="color:#800000">one</span></div><div class="ansi-line">two</div>',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user