mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 11:40:35 +00:00
fix: harden queue retry debounce and add regression tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildHistoryContextFromEntries } from "../auto-reply/reply/history.js";
|
||||
import { extractTextFromChatContent } from "../shared/chat-content.js";
|
||||
import { buildAgentMessageFromConversationEntries } from "./agent-prompt.js";
|
||||
|
||||
describe("gateway agent prompt", () => {
|
||||
@@ -15,6 +16,24 @@ describe("gateway agent prompt", () => {
|
||||
).toBe("hi");
|
||||
});
|
||||
|
||||
it("extracts text from content-array body when there is no history", () => {
|
||||
expect(
|
||||
buildAgentMessageFromConversationEntries([
|
||||
{
|
||||
role: "user",
|
||||
entry: {
|
||||
sender: "User",
|
||||
body: [
|
||||
{ type: "text", text: "hi" },
|
||||
{ type: "image", data: "base64-image", mimeType: "image/png" },
|
||||
{ type: "text", text: "there" },
|
||||
] as unknown as string,
|
||||
},
|
||||
},
|
||||
]),
|
||||
).toBe("hi there");
|
||||
});
|
||||
|
||||
it("uses history context when there is history", () => {
|
||||
const entries = [
|
||||
{ role: "assistant", entry: { sender: "Assistant", body: "prev" } },
|
||||
@@ -45,4 +64,34 @@ describe("gateway agent prompt", () => {
|
||||
|
||||
expect(buildAgentMessageFromConversationEntries([...entries])).toBe(expected);
|
||||
});
|
||||
|
||||
it("normalizes content-array bodies in history and current message", () => {
|
||||
const entries = [
|
||||
{
|
||||
role: "assistant",
|
||||
entry: {
|
||||
sender: "Assistant",
|
||||
body: [{ type: "text", text: "prev" }] as unknown as string,
|
||||
},
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
entry: {
|
||||
sender: "User",
|
||||
body: [
|
||||
{ type: "text", text: "next" },
|
||||
{ type: "text", text: "step" },
|
||||
] as unknown as string,
|
||||
},
|
||||
},
|
||||
] as const;
|
||||
|
||||
const expected = buildHistoryContextFromEntries({
|
||||
entries: entries.map((e) => e.entry),
|
||||
currentMessage: "User: next step",
|
||||
formatEntry: (e) => `${e.sender}: ${extractTextFromChatContent(e.body) ?? ""}`,
|
||||
});
|
||||
|
||||
expect(buildAgentMessageFromConversationEntries([...entries])).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user