fix: harden queue retry debounce and add regression tests

This commit is contained in:
Peter Steinberger
2026-02-24 03:52:31 +00:00
parent a216f2dabe
commit 6c1ed9493c
9 changed files with 257 additions and 6 deletions

View File

@@ -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);
});
});

View File

@@ -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({