fix(qqbot): surface failed media sends (#92823)

* fix(qqbot): surface media send failures

* test(qqbot): cover text send failures

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
zhang-guiping
2026-06-14 11:13:56 +08:00
committed by GitHub
parent 965fa05df3
commit 650c5cac33
2 changed files with 57 additions and 1 deletions

View File

@@ -114,4 +114,54 @@ describe("qqbot message adapter", () => {
expect(proofResults.find((result) => result.capability === "media")?.status).toBe("verified");
expect(proofResults.find((result) => result.capability === "replyTo")?.status).toBe("verified");
});
it("rejects media sends when QQBot reports an outbound error", async () => {
sendMediaMock.mockResolvedValue({ error: "QQ API returned 400 Bad Request" });
await expect(
qqbotPlugin.message?.send?.media?.({
cfg,
to: "qqbot:c2c:user-1",
text: "image",
mediaUrl: "https://example.com/image.png",
}),
).rejects.toThrow("QQ API returned 400 Bad Request");
});
it("rejects text sends when QQBot reports an outbound error", async () => {
sendTextMock.mockResolvedValue({ error: "QQ API returned 400 Bad Request" });
await expect(
qqbotPlugin.message?.send?.text?.({
cfg,
to: "qqbot:c2c:user-1",
text: "hello",
}),
).rejects.toThrow("QQ API returned 400 Bad Request");
});
it("rejects media sends without a QQ platform message id", async () => {
sendMediaMock.mockResolvedValue({});
await expect(
qqbotPlugin.message?.send?.media?.({
cfg,
to: "qqbot:c2c:user-1",
text: "image",
mediaUrl: "https://example.com/image.png",
}),
).rejects.toThrow("QQBot message adapter send did not return a platform message id");
});
it("rejects text sends without a QQ platform message id", async () => {
sendTextMock.mockResolvedValue({});
await expect(
qqbotPlugin.message?.send?.text?.({
cfg,
to: "qqbot:c2c:user-1",
text: "hello",
}),
).rejects.toThrow("QQBot message adapter send did not return a platform message id");
});
});

View File

@@ -134,8 +134,14 @@ async function sendQQBotMedia(params: {
}
function toQQBotMessageSendResult(result: Awaited<ReturnType<typeof sendQQBotText>>) {
if (result.meta?.error) {
throw new Error(result.meta.error);
}
if (result.receipt.platformMessageIds.length === 0) {
throw new Error("QQBot message adapter send did not return a platform message id");
}
return {
messageId: result.messageId,
messageId: result.messageId || result.receipt.primaryPlatformMessageId,
receipt: result.receipt,
} satisfies ChannelMessageSendResult;
}