





















@@ -683,6 +683,72 @@ describe("dispatchTelegramMessage draft streaming", () => {
683683expect(deliverReplies).not.toHaveBeenCalled();
684684});
685685686+it("does not recover forum thread context from malformed payload thread ids", async () => {
687+const generalHistoryKey = "-1003774691294:topic:1";
688+const spoofedHistoryKey = "-1003774691294:topic:3731";
689+const groupHistories = new Map([
690+[generalHistoryKey, [{ sender: "Alice", body: "general topic context", timestamp: 1 }]],
691+[spoofedHistoryKey, [{ sender: "Bob", body: "spoofed topic context", timestamp: 2 }]],
692+]);
693+deliverInboundReplyWithMessageSendContext.mockResolvedValue({
694+status: "handled_visible",
695+delivery: {
696+messageIds: ["1"],
697+visibleReplySent: true,
698+},
699+});
700+dispatchReplyWithBufferedBlockDispatcher.mockImplementation(async ({ dispatcherOptions }) => {
701+await dispatcherOptions.deliver({ text: "general final" }, { kind: "final" });
702+return { queuedFinal: true };
703+});
704+705+await dispatchWithContext({
706+context: createContext({
707+ctxPayload: {
708+Body:
709+"[Chat messages since your last reply - for context]\n" +
710+"general topic context\n" +
711+"[Current message - respond to this]\n" +
712+"current general question",
713+BodyForAgent: "current general question",
714+ChatType: "group",
715+From: "telegram:group:-1003774691294:topic:1",
716+MessageThreadId: "0xE93",
717+OriginatingTo: "telegram:-1003774691294",
718+SessionKey: "agent:main:telegram:group:-1003774691294:topic:1",
719+To: "telegram:-1003774691294",
720+TransportThreadId: "0xE93",
721+} as unknown as TelegramMessageContext["ctxPayload"],
722+msg: {
723+chat: { id: -1003774691294, type: "supergroup" },
724+message_id: 27788,
725+message_thread_id: undefined,
726+} as unknown as TelegramMessageContext["msg"],
727+primaryCtx: {
728+message: { chat: { id: -1003774691294, type: "supergroup" } },
729+} as unknown as TelegramMessageContext["primaryCtx"],
730+chatId: -1003774691294,
731+isGroup: true,
732+replyThreadId: undefined,
733+resolvedThreadId: undefined,
734+threadSpec: { id: 1, scope: "forum" },
735+historyKey: generalHistoryKey,
736+historyLimit: 10,
737+ groupHistories,
738+}),
739+replyToMode: "off",
740+streamMode: "off",
741+});
742+743+const outbound = expectRecordFields(mockCallArg(deliverInboundReplyWithMessageSendContext), {
744+threadId: 1,
745+});
746+expectRecordFields(outbound.ctxPayload, {
747+MessageThreadId: 1,
748+TransportThreadId: 1,
749+});
750+});
751+686752it("does not recover forum thread context from a different group session key", async () => {
687753const currentHistoryKey = "-100555:topic:1";
688754const otherGroupHistoryKey = "-1003774691294:topic:3731";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。