

























@@ -1139,6 +1139,58 @@ describe("matrix monitor handler pairing account scope", () => {
11391139}
11401140});
114111411142+it("waits for the shared-session notice before dispatching the DM reply", async () => {
1143+const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "matrix-dm-shared-notice-order-"));
1144+const storePath = path.join(tempDir, "sessions.json");
1145+let resolveNotice: ((value: string) => void) | undefined;
1146+const noticeSent = new Promise<string>((resolve) => {
1147+resolveNotice = resolve;
1148+});
1149+const sendNotice = vi.fn(() => noticeSent);
1150+const dispatchReplyFromConfig = vi.fn(async () => ({
1151+counts: { block: 0, final: 0, tool: 0 },
1152+queuedFinal: false,
1153+}));
1154+1155+try {
1156+writeMatrixSessionMeta(storePath, "agent:ops:main", {
1157+chatType: "direct",
1158+from: "matrix:@user:example.org",
1159+to: "room:!other:example.org",
1160+nativeChannelId: "!other:example.org",
1161+});
1162+1163+const { handler } = createMatrixHandlerTestHarness({
1164+ dispatchReplyFromConfig,
1165+isDirectMessage: true,
1166+resolveStorePath: () => storePath,
1167+client: {
1168+sendMessage: sendNotice,
1169+},
1170+});
1171+1172+const handled = handler(
1173+"!dm:example.org",
1174+createMatrixTextMessageEvent({
1175+eventId: "$dm1",
1176+body: "follow up",
1177+}),
1178+);
1179+1180+await vi.waitFor(() => {
1181+expect(sendNotice).toHaveBeenCalledTimes(1);
1182+});
1183+expect(dispatchReplyFromConfig).not.toHaveBeenCalled();
1184+1185+resolveNotice?.("$notice");
1186+await handled;
1187+1188+expect(dispatchReplyFromConfig).toHaveBeenCalledTimes(1);
1189+} finally {
1190+fs.rmSync(tempDir, { recursive: true, force: true });
1191+}
1192+});
1193+11421194it("checks flat DM collision notices against the current DM session key", async () => {
11431195const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "matrix-dm-flat-notice-"));
11441196const storePath = path.join(tempDir, "sessions.json");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。