

























@@ -221,15 +221,13 @@ describe("sendMessageMattermost", () => {
221221accountId: "work",
222222});
223223224-expect(result).toMatchObject({
225-messageId: "post-1",
226-channelId: "town-square",
227-receipt: {
228-primaryPlatformMessageId: "post-1",
229-platformMessageIds: ["post-1"],
230-parts: [expect.objectContaining({ platformMessageId: "post-1", kind: "text" })],
231-},
232-});
224+expect(result.messageId).toBe("post-1");
225+expect(result.channelId).toBe("town-square");
226+expect(result.receipt.primaryPlatformMessageId).toBe("post-1");
227+expect(result.receipt.platformMessageIds).toEqual(["post-1"]);
228+expect(result.receipt.parts).toHaveLength(1);
229+expect(result.receipt.parts[0]?.platformMessageId).toBe("post-1");
230+expect(result.receipt.parts[0]?.kind).toBe("text");
233231expect(mockState.loadConfig).not.toHaveBeenCalled();
234232});
235233@@ -259,14 +257,11 @@ describe("sendMessageMattermost", () => {
259257mediaLocalRoots: ["/tmp/agent-workspace"],
260258},
261259);
262-expect(mockState.uploadMattermostFile).toHaveBeenCalledWith(
263-{},
264-expect.objectContaining({
265-channelId: "town-square",
266-fileName: "photo.png",
267-contentType: "image/png",
268-}),
269-);
260+const uploadCall = mockState.uploadMattermostFile.mock.calls[0];
261+expect(uploadCall?.[0]).toEqual({});
262+expect(uploadCall?.[1]?.channelId).toBe("town-square");
263+expect(uploadCall?.[1]?.fileName).toBe("photo.png");
264+expect(uploadCall?.[1]?.contentType).toBe("image/png");
270265});
271266272267it("builds interactive button props when buttons are provided", async () => {
@@ -282,25 +277,16 @@ describe("sendMessageMattermost", () => {
282277buttons: [[{ callback_data: "mdlprov", text: "Browse providers" }]],
283278});
284279285-expect(mockState.createMattermostPost).toHaveBeenCalledWith(
286-{},
287-expect.objectContaining({
288-channelId: "town-square",
289-message: "Pick a model",
290-props: expect.objectContaining({
291-attachments: expect.arrayContaining([
292-expect.objectContaining({
293-actions: expect.arrayContaining([
294-expect.objectContaining({
295-id: "mdlprov",
296-name: "Browse providers",
297-}),
298-]),
299-}),
300-]),
301-}),
302-}),
303-);
280+const postCall = mockState.createMattermostPost.mock.calls[0];
281+expect(postCall?.[0]).toEqual({});
282+expect(postCall?.[1]?.channelId).toBe("town-square");
283+expect(postCall?.[1]?.message).toBe("Pick a model");
284+const attachments = postCall?.[1]?.props?.attachments;
285+expect(Array.isArray(attachments)).toBe(true);
286+const actions = attachments?.[0]?.actions;
287+expect(Array.isArray(actions)).toBe(true);
288+expect(actions?.[0]?.id).toBe("mdlprov");
289+expect(actions?.[0]?.name).toBe("Browse providers");
304290});
305291306292it("resolves a bare Mattermost user id as a DM target before upload", async () => {
@@ -331,12 +317,9 @@ describe("sendMessageMattermost", () => {
331317expect(dmRetryCall?.[1]).toEqual(["bot-user", userId]);
332318expect(Object.keys(dmRetryCall?.[2] ?? {})).toEqual(["onRetry"]);
333319expect(dmRetryCall?.[2]?.onRetry).toBeTypeOf("function");
334-expect(mockState.uploadMattermostFile).toHaveBeenCalledWith(
335-{},
336-expect.objectContaining({
337-channelId: "dm-channel-1",
338-}),
339-);
320+const uploadCall = mockState.uploadMattermostFile.mock.calls[0];
321+expect(uploadCall?.[0]).toEqual({});
322+expect(uploadCall?.[1]?.channelId).toBe("dm-channel-1");
340323expect(result.channelId).toBe("dm-channel-1");
341324});
342325@@ -366,12 +349,9 @@ describe("sendMessageMattermost", () => {
366349367350expect(mockState.fetchMattermostUser).toHaveBeenCalledWith({}, channelId);
368351expect(mockState.createMattermostDirectChannelWithRetry).not.toHaveBeenCalled();
369-expect(mockState.uploadMattermostFile).toHaveBeenCalledWith(
370-{},
371-expect.objectContaining({
372- channelId,
373-}),
374-);
352+const uploadCall = mockState.uploadMattermostFile.mock.calls[0];
353+expect(uploadCall?.[0]).toEqual({});
354+expect(uploadCall?.[1]?.channelId).toBe(channelId);
375355expect(result.channelId).toBe(channelId);
376356});
377357});
@@ -495,10 +475,8 @@ describe("sendMessageMattermost user-first resolution", () => {
495475expect(params.channelId).toBe("dm-channel-id");
496476expect(res.channelId).toBe("dm-channel-id");
497477expect(res.messageId).toBe("post-id");
498-expect(res.receipt).toMatchObject({
499-primaryPlatformMessageId: "post-id",
500-platformMessageIds: ["post-id"],
501-});
478+expect(res.receipt.primaryPlatformMessageId).toBe("post-id");
479+expect(res.receipt.platformMessageIds).toEqual(["post-id"]);
502480});
503481504482it("falls back to channel id when user lookup returns 404", async () => {
@@ -589,11 +567,13 @@ describe("sendMessageMattermost user-first resolution", () => {
589567dmRetryOptions: retryOptions,
590568});
591569592-expect(mockState.createMattermostDirectChannelWithRetry).toHaveBeenCalledWith(
593-{},
594-["bot-id", userId],
595-expect.objectContaining(retryOptions),
596-);
570+const retryCall = mockState.createMattermostDirectChannelWithRetry.mock.calls[0];
571+expect(retryCall?.[0]).toEqual({});
572+expect(retryCall?.[1]).toEqual(["bot-id", userId]);
573+expect(retryCall?.[2]?.maxRetries).toBe(retryOptions.maxRetries);
574+expect(retryCall?.[2]?.initialDelayMs).toBe(retryOptions.initialDelayMs);
575+expect(retryCall?.[2]?.maxDelayMs).toBe(retryOptions.maxDelayMs);
576+expect(retryCall?.[2]?.timeoutMs).toBe(retryOptions.timeoutMs);
597577});
598578599579it("uses dmChannelRetry from account config when opts.dmRetryOptions not provided", async () => {
@@ -615,16 +595,13 @@ describe("sendMessageMattermost user-first resolution", () => {
615595616596await sendMessageMattermost(`user:${userId}`, "hello", { cfg: TEST_CFG });
617597618-expect(mockState.createMattermostDirectChannelWithRetry).toHaveBeenCalledWith(
619-{},
620-["bot-id", userId],
621-expect.objectContaining({
622-maxRetries: 4,
623-initialDelayMs: 2000,
624-maxDelayMs: 8000,
625-timeoutMs: 15000,
626-}),
627-);
598+const retryCall = mockState.createMattermostDirectChannelWithRetry.mock.calls[0];
599+expect(retryCall?.[0]).toEqual({});
600+expect(retryCall?.[1]).toEqual(["bot-id", userId]);
601+expect(retryCall?.[2]?.maxRetries).toBe(4);
602+expect(retryCall?.[2]?.initialDelayMs).toBe(2000);
603+expect(retryCall?.[2]?.maxDelayMs).toBe(8000);
604+expect(retryCall?.[2]?.timeoutMs).toBe(15000);
628605});
629606630607it("opts.dmRetryOptions overrides provided fields and preserves account defaults", async () => {
@@ -652,17 +629,11 @@ describe("sendMessageMattermost user-first resolution", () => {
652629dmRetryOptions: overrideOptions,
653630});
654631655-expect(mockState.createMattermostDirectChannelWithRetry).toHaveBeenCalledWith(
656-{},
657-["bot-id", userId],
658-expect.objectContaining(overrideOptions),
659-);
660-expect(mockState.createMattermostDirectChannelWithRetry).toHaveBeenCalledWith(
661-{},
662-["bot-id", userId],
663-expect.objectContaining({
664-initialDelayMs: 1000,
665-}),
666-);
632+const retryCall = mockState.createMattermostDirectChannelWithRetry.mock.calls[0];
633+expect(retryCall?.[0]).toEqual({});
634+expect(retryCall?.[1]).toEqual(["bot-id", userId]);
635+expect(retryCall?.[2]?.maxRetries).toBe(overrideOptions.maxRetries);
636+expect(retryCall?.[2]?.timeoutMs).toBe(overrideOptions.timeoutMs);
637+expect(retryCall?.[2]?.initialDelayMs).toBe(1000);
667638});
668639});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。