feat: switched to native text sanitization, removed Bun.stripANSI
- Added `sanitizeText` function to pi-natives that strips ANSI escape sequences, removes control characters and lone surrogates, and normalizes line endings. - Moved `sanitizeText` function from `@oh-my-pi/pi-utils` to `@oh-my-pi/pi-natives` for better code organization and native performance. - Added line length clamping (4000 characters) to bash and Python execution output to prevent excessively long lines. - Replaced internal `#normalizeOutput` methods with `sanitizeText` utility function in bash and Python execution components. - Fixed bash interactive tool to gracefully handle malformed output chunks by normalizing them with `sanitizeText`. - Simplified documentation by removing WASM terminology from package descriptions and comments.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { getThemeByName } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
|
||||
import { pythonToolRenderer } from "@oh-my-pi/pi-coding-agent/tools/python";
|
||||
import { sanitizeText } from "@oh-my-pi/pi-natives";
|
||||
|
||||
describe("pythonToolRenderer", () => {
|
||||
it("renders truncated output when collapsed and full output when expanded", async () => {
|
||||
@@ -31,13 +32,13 @@ describe("pythonToolRenderer", () => {
|
||||
{ expanded: false, isPartial: false, renderContext: { previewLines: 2 } },
|
||||
uiTheme,
|
||||
);
|
||||
const collapsedLines = Bun.stripANSI(collapsed.render(80).join("\n"));
|
||||
const collapsedLines = sanitizeText(collapsed.render(80).join("\n"));
|
||||
expect(collapsedLines).toContain("line 4");
|
||||
expect(collapsedLines).not.toContain("line 1");
|
||||
expect(collapsedLines).toContain("more lines");
|
||||
|
||||
const expanded = pythonToolRenderer.renderResult(result, { expanded: true, isPartial: false }, uiTheme);
|
||||
const expandedLines = Bun.stripANSI(expanded.render(80).join("\n"));
|
||||
const expandedLines = sanitizeText(expanded.render(80).join("\n"));
|
||||
expect(expandedLines).toContain("line 1");
|
||||
expect(expandedLines).toContain("line 4");
|
||||
expect(expandedLines).not.toContain("more lines");
|
||||
|
||||
Reference in New Issue
Block a user