mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 06:12:45 +00:00
fix(tests): update thread ID handling in Slack message collection tests (#14108)
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
3696b15abc
commit
472808a207
@@ -9,7 +9,7 @@ function createRun(params: {
|
|||||||
originatingChannel?: FollowupRun["originatingChannel"];
|
originatingChannel?: FollowupRun["originatingChannel"];
|
||||||
originatingTo?: string;
|
originatingTo?: string;
|
||||||
originatingAccountId?: string;
|
originatingAccountId?: string;
|
||||||
originatingThreadId?: number;
|
originatingThreadId?: string | number;
|
||||||
}): FollowupRun {
|
}): FollowupRun {
|
||||||
return {
|
return {
|
||||||
prompt: params.prompt,
|
prompt: params.prompt,
|
||||||
@@ -283,4 +283,86 @@ describe("followup queue collect routing", () => {
|
|||||||
expect(calls[0]?.originatingChannel).toBe("slack");
|
expect(calls[0]?.originatingChannel).toBe("slack");
|
||||||
expect(calls[0]?.originatingTo).toBe("channel:A");
|
expect(calls[0]?.originatingTo).toBe("channel:A");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("collects Slack messages in same thread and preserves string thread id", async () => {
|
||||||
|
const key = `test-collect-slack-thread-same-${Date.now()}`;
|
||||||
|
const calls: FollowupRun[] = [];
|
||||||
|
const runFollowup = async (run: FollowupRun) => {
|
||||||
|
calls.push(run);
|
||||||
|
};
|
||||||
|
const settings: QueueSettings = {
|
||||||
|
mode: "collect",
|
||||||
|
debounceMs: 0,
|
||||||
|
cap: 50,
|
||||||
|
dropPolicy: "summarize",
|
||||||
|
};
|
||||||
|
|
||||||
|
enqueueFollowupRun(
|
||||||
|
key,
|
||||||
|
createRun({
|
||||||
|
prompt: "one",
|
||||||
|
originatingChannel: "slack",
|
||||||
|
originatingTo: "channel:A",
|
||||||
|
originatingThreadId: "1706000000.000001",
|
||||||
|
}),
|
||||||
|
settings,
|
||||||
|
);
|
||||||
|
enqueueFollowupRun(
|
||||||
|
key,
|
||||||
|
createRun({
|
||||||
|
prompt: "two",
|
||||||
|
originatingChannel: "slack",
|
||||||
|
originatingTo: "channel:A",
|
||||||
|
originatingThreadId: "1706000000.000001",
|
||||||
|
}),
|
||||||
|
settings,
|
||||||
|
);
|
||||||
|
|
||||||
|
scheduleFollowupDrain(key, runFollowup);
|
||||||
|
await expect.poll(() => calls.length).toBe(1);
|
||||||
|
expect(calls[0]?.prompt).toContain("[Queued messages while agent was busy]");
|
||||||
|
expect(calls[0]?.originatingThreadId).toBe("1706000000.000001");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not collect Slack messages when thread ids differ", async () => {
|
||||||
|
const key = `test-collect-slack-thread-diff-${Date.now()}`;
|
||||||
|
const calls: FollowupRun[] = [];
|
||||||
|
const runFollowup = async (run: FollowupRun) => {
|
||||||
|
calls.push(run);
|
||||||
|
};
|
||||||
|
const settings: QueueSettings = {
|
||||||
|
mode: "collect",
|
||||||
|
debounceMs: 0,
|
||||||
|
cap: 50,
|
||||||
|
dropPolicy: "summarize",
|
||||||
|
};
|
||||||
|
|
||||||
|
enqueueFollowupRun(
|
||||||
|
key,
|
||||||
|
createRun({
|
||||||
|
prompt: "one",
|
||||||
|
originatingChannel: "slack",
|
||||||
|
originatingTo: "channel:A",
|
||||||
|
originatingThreadId: "1706000000.000001",
|
||||||
|
}),
|
||||||
|
settings,
|
||||||
|
);
|
||||||
|
enqueueFollowupRun(
|
||||||
|
key,
|
||||||
|
createRun({
|
||||||
|
prompt: "two",
|
||||||
|
originatingChannel: "slack",
|
||||||
|
originatingTo: "channel:A",
|
||||||
|
originatingThreadId: "1706000000.000002",
|
||||||
|
}),
|
||||||
|
settings,
|
||||||
|
);
|
||||||
|
|
||||||
|
scheduleFollowupDrain(key, runFollowup);
|
||||||
|
await expect.poll(() => calls.length).toBe(2);
|
||||||
|
expect(calls[0]?.prompt).toBe("one");
|
||||||
|
expect(calls[1]?.prompt).toBe("two");
|
||||||
|
expect(calls[0]?.originatingThreadId).toBe("1706000000.000001");
|
||||||
|
expect(calls[1]?.originatingThreadId).toBe("1706000000.000002");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ export function scheduleFollowupDrain(
|
|||||||
const to = item.originatingTo;
|
const to = item.originatingTo;
|
||||||
const accountId = item.originatingAccountId;
|
const accountId = item.originatingAccountId;
|
||||||
const threadId = item.originatingThreadId;
|
const threadId = item.originatingThreadId;
|
||||||
if (!channel && !to && !accountId && typeof threadId !== "number") {
|
if (!channel && !to && !accountId && threadId == null) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (!isRoutableChannel(channel) || !to) {
|
if (!isRoutableChannel(channel) || !to) {
|
||||||
return { cross: true };
|
return { cross: true };
|
||||||
}
|
}
|
||||||
const threadKey = typeof threadId === "number" ? String(threadId) : "";
|
const threadKey = threadId != null ? String(threadId) : "";
|
||||||
return {
|
return {
|
||||||
key: [channel, to, accountId || "", threadKey].join("|"),
|
key: [channel, to, accountId || "", threadKey].join("|"),
|
||||||
};
|
};
|
||||||
@@ -80,7 +80,7 @@ export function scheduleFollowupDrain(
|
|||||||
(i) => i.originatingAccountId,
|
(i) => i.originatingAccountId,
|
||||||
)?.originatingAccountId;
|
)?.originatingAccountId;
|
||||||
const originatingThreadId = items.find(
|
const originatingThreadId = items.find(
|
||||||
(i) => typeof i.originatingThreadId === "number",
|
(i) => i.originatingThreadId != null,
|
||||||
)?.originatingThreadId;
|
)?.originatingThreadId;
|
||||||
|
|
||||||
const prompt = buildCollectPrompt({
|
const prompt = buildCollectPrompt({
|
||||||
|
|||||||
Reference in New Issue
Block a user