mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
e4a48157d1
* fix(test): keep bounded child output UTF-8 safe * test: preserve incomplete child output tails --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
// Bounded child output tests cover tail-only test child output buffering.
|
|
import { describe, expect, it } from "vitest";
|
|
import { createBoundedChildOutput } from "./bounded-child-output.js";
|
|
|
|
describe("bounded child output", () => {
|
|
it("keeps only the latest output bytes", () => {
|
|
const output = createBoundedChildOutput(16);
|
|
|
|
output.append(`DO_NOT_KEEP${"x".repeat(32)}`);
|
|
output.append("\nrecent tail");
|
|
|
|
const text = output.text();
|
|
expect(text).toContain("recent tail");
|
|
expect(text).not.toContain("DO_NOT_KEEP");
|
|
expect(Buffer.byteLength(text, "utf8")).toBeLessThanOrEqual(16);
|
|
});
|
|
|
|
it("keeps only the tail of a single oversized chunk", () => {
|
|
const output = createBoundedChildOutput(8);
|
|
|
|
output.append(Buffer.from("old-prefix-recent"));
|
|
|
|
expect(output.text()).toBe("x-recent");
|
|
});
|
|
|
|
it("drops split UTF-8 prefixes after buffered output overflow", () => {
|
|
const output = createBoundedChildOutput(7);
|
|
|
|
output.append(Buffer.from("prefix 😀"));
|
|
output.append(Buffer.from("tail"));
|
|
|
|
expect(output.text()).toBe("tail");
|
|
});
|
|
|
|
it("drops split UTF-8 prefixes from single oversized chunks", () => {
|
|
const output = createBoundedChildOutput(7);
|
|
|
|
output.append(Buffer.from("prefix 😀tail"));
|
|
|
|
expect(output.text()).toBe("tail");
|
|
});
|
|
|
|
it("preserves replacement output for incomplete trailing bytes", () => {
|
|
const output = createBoundedChildOutput(7);
|
|
|
|
output.append(Buffer.from([0x61, 0xe2]));
|
|
|
|
expect(output.text()).toBe("a�");
|
|
});
|
|
});
|