fix(agent): preserve oversized tail output with trailing newline
closes #4715
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed tail truncation for oversized single-line output that ends with a trailing newline ([#4715](https://github.com/earendil-works/pi/issues/4715)).
|
||||||
|
|
||||||
## [0.75.3] - 2026-05-18
|
## [0.75.3] - 2026-05-18
|
||||||
|
|
||||||
## [0.75.2] - 2026-05-18
|
## [0.75.2] - 2026-05-18
|
||||||
|
|||||||
@@ -218,6 +218,7 @@ export function truncateTail(content: string, options: TruncationOptions = {}):
|
|||||||
|
|
||||||
const totalBytes = utf8ByteLength(content);
|
const totalBytes = utf8ByteLength(content);
|
||||||
const lines = content.split("\n");
|
const lines = content.split("\n");
|
||||||
|
if (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
|
||||||
const totalLines = lines.length;
|
const totalLines = lines.length;
|
||||||
|
|
||||||
// Check if no truncation needed
|
// Check if no truncation needed
|
||||||
|
|||||||
@@ -102,6 +102,17 @@ describe("truncate utilities", () => {
|
|||||||
expect(result.outputBytes).toBe(5);
|
expect(result.outputBytes).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("truncates an oversized single line with a trailing newline", () => {
|
||||||
|
const input = `${"X".repeat(300_000)}\n`;
|
||||||
|
const result = truncateTail(input, { maxBytes: 1024, maxLines: 100 });
|
||||||
|
|
||||||
|
expect(result.content).toBe("X".repeat(1024));
|
||||||
|
expect(result.outputBytes).toBe(1024);
|
||||||
|
expect(result.outputLines).toBe(1);
|
||||||
|
expect(result.lastLinePartial).toBe(true);
|
||||||
|
expect(result.truncatedBy).toBe("bytes");
|
||||||
|
});
|
||||||
|
|
||||||
it("drops an oversized trailing character when it cannot fit in tail byte limit", () => {
|
it("drops an oversized trailing character when it cannot fit in tail byte limit", () => {
|
||||||
const result = truncateTail("abc🙂", { maxBytes: 3, maxLines: 10 });
|
const result = truncateTail("abc🙂", { maxBytes: 3, maxLines: 10 });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user