mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:11:25 +00:00
refactor(tui): dedupe handlers and formatter test setup
This commit is contained in:
@@ -1,6 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { TuiStreamAssembler } from "./tui-stream-assembler.js";
|
||||
|
||||
const STREAM_WITH_TOOL_BLOCKS = {
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "text", text: "Before tool call" },
|
||||
{ type: "tool_use", name: "search" },
|
||||
{ type: "text", text: "After tool call" },
|
||||
],
|
||||
} as const;
|
||||
|
||||
const STREAM_AFTER_TOOL_BLOCKS = {
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "tool_use", name: "search" },
|
||||
{ type: "text", text: "After tool call" },
|
||||
],
|
||||
} as const;
|
||||
|
||||
describe("TuiStreamAssembler", () => {
|
||||
it("keeps thinking before content even when thinking arrives later", () => {
|
||||
const assembler = new TuiStreamAssembler();
|
||||
@@ -92,61 +109,19 @@ describe("TuiStreamAssembler", () => {
|
||||
|
||||
it("keeps richer streamed text when final payload drops earlier blocks", () => {
|
||||
const assembler = new TuiStreamAssembler();
|
||||
assembler.ingestDelta(
|
||||
"run-5",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "text", text: "Before tool call" },
|
||||
{ type: "tool_use", name: "search" },
|
||||
{ type: "text", text: "After tool call" },
|
||||
],
|
||||
},
|
||||
false,
|
||||
);
|
||||
assembler.ingestDelta("run-5", STREAM_WITH_TOOL_BLOCKS, false);
|
||||
|
||||
const finalText = assembler.finalize(
|
||||
"run-5",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "tool_use", name: "search" },
|
||||
{ type: "text", text: "After tool call" },
|
||||
],
|
||||
},
|
||||
false,
|
||||
);
|
||||
const finalText = assembler.finalize("run-5", STREAM_AFTER_TOOL_BLOCKS, false);
|
||||
|
||||
expect(finalText).toBe("Before tool call\nAfter tool call");
|
||||
});
|
||||
|
||||
it("does not regress streamed text when a delta drops boundary blocks after tool calls", () => {
|
||||
const assembler = new TuiStreamAssembler();
|
||||
const first = assembler.ingestDelta(
|
||||
"run-5-stream",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "text", text: "Before tool call" },
|
||||
{ type: "tool_use", name: "search" },
|
||||
{ type: "text", text: "After tool call" },
|
||||
],
|
||||
},
|
||||
false,
|
||||
);
|
||||
const first = assembler.ingestDelta("run-5-stream", STREAM_WITH_TOOL_BLOCKS, false);
|
||||
expect(first).toBe("Before tool call\nAfter tool call");
|
||||
|
||||
const second = assembler.ingestDelta(
|
||||
"run-5-stream",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "tool_use", name: "search" },
|
||||
{ type: "text", text: "After tool call" },
|
||||
],
|
||||
},
|
||||
false,
|
||||
);
|
||||
const second = assembler.ingestDelta("run-5-stream", STREAM_AFTER_TOOL_BLOCKS, false);
|
||||
|
||||
expect(second).toBeNull();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user