mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 16:54:31 +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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -87,6 +87,38 @@ describe("gateway sessions patch", () => {
|
||||
expect(res.entry.thinkingLevel).toBeUndefined();
|
||||
});
|
||||
|
||||
test("persists reasoningLevel=off (does not clear)", async () => {
|
||||
const store: Record<string, SessionEntry> = {};
|
||||
const res = await applySessionsPatchToStore({
|
||||
cfg: {} as OpenClawConfig,
|
||||
store,
|
||||
storeKey: "agent:main:main",
|
||||
patch: { key: "agent:main:main", reasoningLevel: "off" },
|
||||
});
|
||||
expect(res.ok).toBe(true);
|
||||
if (!res.ok) {
|
||||
return;
|
||||
}
|
||||
expect(res.entry.reasoningLevel).toBe("off");
|
||||
});
|
||||
|
||||
test("clears reasoningLevel when patch sets null", async () => {
|
||||
const store: Record<string, SessionEntry> = {
|
||||
"agent:main:main": { reasoningLevel: "stream" } as SessionEntry,
|
||||
};
|
||||
const res = await applySessionsPatchToStore({
|
||||
cfg: {} as OpenClawConfig,
|
||||
store,
|
||||
storeKey: "agent:main:main",
|
||||
patch: { key: "agent:main:main", reasoningLevel: null },
|
||||
});
|
||||
expect(res.ok).toBe(true);
|
||||
if (!res.ok) {
|
||||
return;
|
||||
}
|
||||
expect(res.entry.reasoningLevel).toBeUndefined();
|
||||
});
|
||||
|
||||
test("persists elevatedLevel=off (does not clear)", async () => {
|
||||
const store: Record<string, SessionEntry> = {};
|
||||
const res = await applySessionsPatchToStore({
|
||||
|
||||
Reference in New Issue
Block a user