mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 16:27:26 +00:00
refactor(web): dedupe self-chat response-prefix tests
This commit is contained in:
@@ -127,6 +127,32 @@ describe("web processMessage inbound contract", () => {
|
||||
}
|
||||
});
|
||||
|
||||
async function processSelfDirectMessage(cfg: unknown) {
|
||||
capturedDispatchParams = undefined;
|
||||
await processMessage(
|
||||
makeProcessMessageArgs({
|
||||
routeSessionKey: "agent:main:whatsapp:direct:+1555",
|
||||
groupHistoryKey: "+1555",
|
||||
cfg,
|
||||
msg: {
|
||||
id: "msg1",
|
||||
from: "+1555",
|
||||
to: "+1555",
|
||||
selfE164: "+1555",
|
||||
chatType: "direct",
|
||||
body: "hi",
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function getDispatcherResponsePrefix() {
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
const dispatcherOptions = (capturedDispatchParams as any)?.dispatcherOptions;
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
return dispatcherOptions?.responsePrefix as string | undefined;
|
||||
}
|
||||
|
||||
it("passes a finalized MsgContext to the dispatcher", async () => {
|
||||
await processMessage(
|
||||
makeProcessMessageArgs({
|
||||
@@ -184,66 +210,30 @@ describe("web processMessage inbound contract", () => {
|
||||
});
|
||||
|
||||
it("defaults responsePrefix to identity name in self-chats when unset", async () => {
|
||||
capturedDispatchParams = undefined;
|
||||
|
||||
await processMessage(
|
||||
makeProcessMessageArgs({
|
||||
routeSessionKey: "agent:main:whatsapp:direct:+1555",
|
||||
groupHistoryKey: "+1555",
|
||||
cfg: {
|
||||
agents: {
|
||||
list: [
|
||||
{
|
||||
id: "main",
|
||||
default: true,
|
||||
identity: { name: "Mainbot", emoji: "🦞", theme: "space lobster" },
|
||||
},
|
||||
],
|
||||
await processSelfDirectMessage({
|
||||
agents: {
|
||||
list: [
|
||||
{
|
||||
id: "main",
|
||||
default: true,
|
||||
identity: { name: "Mainbot", emoji: "🦞", theme: "space lobster" },
|
||||
},
|
||||
messages: {},
|
||||
session: { store: sessionStorePath },
|
||||
} as unknown as ReturnType<typeof import("../../../config/config.js").loadConfig>,
|
||||
msg: {
|
||||
id: "msg1",
|
||||
from: "+1555",
|
||||
to: "+1555",
|
||||
selfE164: "+1555",
|
||||
chatType: "direct",
|
||||
body: "hi",
|
||||
},
|
||||
}),
|
||||
);
|
||||
],
|
||||
},
|
||||
messages: {},
|
||||
session: { store: sessionStorePath },
|
||||
} as unknown as ReturnType<typeof import("../../../config/config.js").loadConfig>);
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
const dispatcherOptions = (capturedDispatchParams as any)?.dispatcherOptions;
|
||||
expect(dispatcherOptions?.responsePrefix).toBe("[Mainbot]");
|
||||
expect(getDispatcherResponsePrefix()).toBe("[Mainbot]");
|
||||
});
|
||||
|
||||
it("does not force an [openclaw] response prefix in self-chats when identity is unset", async () => {
|
||||
capturedDispatchParams = undefined;
|
||||
await processSelfDirectMessage({
|
||||
messages: {},
|
||||
session: { store: sessionStorePath },
|
||||
} as unknown as ReturnType<typeof import("../../../config/config.js").loadConfig>);
|
||||
|
||||
await processMessage(
|
||||
makeProcessMessageArgs({
|
||||
routeSessionKey: "agent:main:whatsapp:direct:+1555",
|
||||
groupHistoryKey: "+1555",
|
||||
cfg: {
|
||||
messages: {},
|
||||
session: { store: sessionStorePath },
|
||||
} as unknown as ReturnType<typeof import("../../../config/config.js").loadConfig>,
|
||||
msg: {
|
||||
id: "msg1",
|
||||
from: "+1555",
|
||||
to: "+1555",
|
||||
selfE164: "+1555",
|
||||
chatType: "direct",
|
||||
body: "hi",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
const dispatcherOptions = (capturedDispatchParams as any)?.dispatcherOptions;
|
||||
expect(dispatcherOptions?.responsePrefix).toBeUndefined();
|
||||
expect(getDispatcherResponsePrefix()).toBeUndefined();
|
||||
});
|
||||
|
||||
it("clears pending group history when the dispatcher does not queue a final reply", async () => {
|
||||
|
||||
Reference in New Issue
Block a user