






















@@ -2190,6 +2190,80 @@ describe("dispatchTelegramMessage draft streaming", () => {
21902190expect(deliveredTexts).toContain("fresh request answer");
21912191});
219221922193+it("keeps /btw side questions from aborting an active same-session dispatch", async () => {
2194+const historyKey = "telegram:group:-100123";
2195+const groupHistories = new Map([[historyKey, []]]);
2196+let firstStarted: (() => void) | undefined;
2197+const firstStartGate = new Promise<void>((resolve) => {
2198+firstStarted = resolve;
2199+});
2200+let releaseFirst: (() => void) | undefined;
2201+const firstGate = new Promise<void>((resolve) => {
2202+releaseFirst = resolve;
2203+});
2204+let sideStarted: (() => void) | undefined;
2205+const sideStartGate = new Promise<void>((resolve) => {
2206+sideStarted = resolve;
2207+});
2208+let firstAbortSignal: AbortSignal | undefined;
2209+dispatchReplyWithBufferedBlockDispatcher
2210+.mockImplementationOnce(async ({ replyOptions }) => {
2211+firstAbortSignal = replyOptions?.abortSignal;
2212+firstStarted?.();
2213+await firstGate;
2214+return {
2215+queuedFinal: false,
2216+counts: { block: 0, final: 0, tool: 0 },
2217+};
2218+})
2219+.mockImplementationOnce(async () => {
2220+sideStarted?.();
2221+return {
2222+queuedFinal: false,
2223+counts: { block: 0, final: 0, tool: 0 },
2224+};
2225+});
2226+2227+const createGroupContext = (messageId: number, body: string) =>
2228+createContext({
2229+ctxPayload: {
2230+SessionKey: "agent:main:telegram:group:-100123",
2231+ChatType: "group",
2232+MessageSid: String(messageId),
2233+RawBody: body,
2234+BodyForAgent: body,
2235+CommandBody: body,
2236+CommandAuthorized: true,
2237+} as unknown as TelegramMessageContext["ctxPayload"],
2238+msg: {
2239+chat: { id: -100123, type: "supergroup" },
2240+message_id: messageId,
2241+text: body,
2242+} as unknown as TelegramMessageContext["msg"],
2243+chatId: -100123,
2244+isGroup: true,
2245+ historyKey,
2246+historyLimit: 10,
2247+ groupHistories,
2248+threadSpec: { id: undefined, scope: "none" },
2249+});
2250+2251+const firstPromise = dispatchWithContext({
2252+context: createGroupContext(99, "@bot first request"),
2253+streamMode: "off",
2254+});
2255+await firstStartGate;
2256+const sidePromise = dispatchWithContext({
2257+context: createGroupContext(100, "/btw what changed?"),
2258+streamMode: "off",
2259+});
2260+await sideStartGate;
2261+2262+expect(firstAbortSignal?.aborted).toBe(false);
2263+releaseFirst?.();
2264+await Promise.all([firstPromise, sidePromise]);
2265+});
2266+21932267it("keeps queued room events abortable after their source dispatch returns", async () => {
21942268const historyKey = "telegram:group:-100123";
21952269const groupHistories = new Map([[historyKey, []]]);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。