test: add routing/session isolation edge-case regressions

This commit is contained in:
Peter Steinberger
2026-02-24 23:24:51 +00:00
parent 9fccf60733
commit 9b53102100
4 changed files with 119 additions and 0 deletions

View File

@@ -85,4 +85,27 @@ describe("buildReplyPayloads media filter integration", () => {
expect(replyPayloads).toHaveLength(0);
});
it("does not suppress same-target replies when accountId differs", () => {
const { replyPayloads } = buildReplyPayloads({
...baseParams,
payloads: [{ text: "hello world!" }],
messageProvider: "heartbeat",
originatingChannel: "telegram",
originatingTo: "268300329",
accountId: "personal",
messagingToolSentTexts: ["different message"],
messagingToolSentTargets: [
{
tool: "telegram",
provider: "telegram",
to: "268300329",
accountId: "work",
},
],
});
expect(replyPayloads).toHaveLength(1);
expect(replyPayloads[0]?.text).toBe("hello world!");
});
});

View File

@@ -238,6 +238,36 @@ describe("createFollowupRunner messaging tool dedupe", () => {
expect(onBlockReply).not.toHaveBeenCalled();
});
it("does not suppress replies for same target when account differs", async () => {
const onBlockReply = vi.fn(async () => {});
runEmbeddedPiAgentMock.mockResolvedValueOnce({
payloads: [{ text: "hello world!" }],
messagingToolSentTexts: ["different message"],
messagingToolSentTargets: [
{ tool: "telegram", provider: "telegram", to: "268300329", accountId: "work" },
],
meta: {},
});
const runner = createMessagingDedupeRunner(onBlockReply);
await runner({
...baseQueuedRun("heartbeat"),
originatingChannel: "telegram",
originatingTo: "268300329",
originatingAccountId: "personal",
} as FollowupRun);
expect(routeReplyMock).toHaveBeenCalledWith(
expect.objectContaining({
channel: "telegram",
to: "268300329",
accountId: "personal",
}),
);
expect(onBlockReply).not.toHaveBeenCalled();
});
it("drops media URL from payload when messaging tool already sent it", async () => {
const onBlockReply = vi.fn(async () => {});
runEmbeddedPiAgentMock.mockResolvedValueOnce({
@@ -335,6 +365,34 @@ describe("createFollowupRunner messaging tool dedupe", () => {
expect(routeReplyMock).toHaveBeenCalled();
expect(onBlockReply).not.toHaveBeenCalled();
});
it("routes followups with originating account/thread metadata", async () => {
const onBlockReply = vi.fn(async () => {});
runEmbeddedPiAgentMock.mockResolvedValueOnce({
payloads: [{ text: "hello world!" }],
meta: {},
});
const runner = createMessagingDedupeRunner(onBlockReply);
await runner({
...baseQueuedRun("webchat"),
originatingChannel: "discord",
originatingTo: "channel:C1",
originatingAccountId: "work",
originatingThreadId: "1739142736.000100",
} as FollowupRun);
expect(routeReplyMock).toHaveBeenCalledWith(
expect.objectContaining({
channel: "discord",
to: "channel:C1",
accountId: "work",
threadId: "1739142736.000100",
}),
);
expect(onBlockReply).not.toHaveBeenCalled();
});
});
describe("createFollowupRunner agentDir forwarding", () => {

View File

@@ -1068,6 +1068,7 @@ describe("followup queue collect routing", () => {
prompt: "first",
originatingChannel: "discord",
originatingTo: "channel:C1",
originatingAccountId: "work",
originatingThreadId: "1739142736.000100",
}),
settings,
@@ -1078,6 +1079,7 @@ describe("followup queue collect routing", () => {
prompt: "second",
originatingChannel: "discord",
originatingTo: "channel:C1",
originatingAccountId: "work",
originatingThreadId: "1739142736.000100",
}),
settings,
@@ -1088,6 +1090,7 @@ describe("followup queue collect routing", () => {
expect(calls[0]?.originatingChannel).toBe("discord");
expect(calls[0]?.originatingTo).toBe("channel:C1");
expect(calls[0]?.originatingAccountId).toBe("work");
expect(calls[0]?.originatingThreadId).toBe("1739142736.000100");
expect(calls[0]?.prompt).toContain("[Queue overflow] Dropped 1 message due to cap.");
});

View File

@@ -321,4 +321,39 @@ describe("resolveSessionDeliveryTarget", () => {
expect(resolved.to).toBe("user:U123");
expect(resolved.threadId).toBeUndefined();
});
it("keeps explicit threadId in heartbeat mode", () => {
const resolved = resolveSessionDeliveryTarget({
entry: {
sessionId: "sess-heartbeat-explicit-thread",
updatedAt: 1,
lastChannel: "telegram",
lastTo: "-100123",
lastThreadId: 999,
},
requestedChannel: "last",
mode: "heartbeat",
explicitThreadId: 42,
});
expect(resolved.channel).toBe("telegram");
expect(resolved.to).toBe("-100123");
expect(resolved.threadId).toBe(42);
expect(resolved.threadIdExplicit).toBe(true);
});
it("parses explicit heartbeat topic targets into threadId", () => {
const cfg: OpenClawConfig = {};
const resolved = resolveHeartbeatDeliveryTarget({
cfg,
heartbeat: {
target: "telegram",
to: "63448508:topic:1008013",
},
});
expect(resolved.channel).toBe("telegram");
expect(resolved.to).toBe("63448508");
expect(resolved.threadId).toBe(1008013);
});
});