refactor(agents): unify subagent announce delivery pipeline

Co-authored-by: Smith Labs <SmithLabsLLC@users.noreply.github.com>
Co-authored-by: Do Cao Hieu <docaohieu2808@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-02-26 00:30:19 +00:00
parent aedf62ac7e
commit 4258a3307f
14 changed files with 623 additions and 132 deletions

View File

@@ -196,6 +196,10 @@ describe("sendMessageTelegram", () => {
for (const testCase of cases) {
botCtorSpy.mockClear();
loadConfig.mockReturnValue(testCase.cfg);
botApi.sendMessage.mockResolvedValue({
message_id: 1,
chat: { id: "123" },
});
await sendMessageTelegram("123", "hi", testCase.opts);
expect(botCtorSpy, testCase.name).toHaveBeenCalledWith(
"tok",
@@ -325,6 +329,40 @@ describe("sendMessageTelegram", () => {
}
});
it("fails when Telegram text send returns no message_id", async () => {
const sendMessage = vi.fn().mockResolvedValue({
chat: { id: "123" },
});
const api = { sendMessage } as unknown as {
sendMessage: typeof sendMessage;
};
await expect(
sendMessageTelegram("123", "hi", {
token: "tok",
api,
}),
).rejects.toThrow(/returned no message_id/i);
});
it("fails when Telegram media send returns no message_id", async () => {
mockLoadedMedia({ contentType: "image/png", fileName: "photo.png" });
const sendPhoto = vi.fn().mockResolvedValue({
chat: { id: "123" },
});
const api = { sendPhoto } as unknown as {
sendPhoto: typeof sendPhoto;
};
await expect(
sendMessageTelegram("123", "caption", {
token: "tok",
api,
mediaUrl: "https://example.com/photo.png",
}),
).rejects.toThrow(/returned no message_id/i);
});
it("uses native fetch for BAN compatibility when api is omitted", async () => {
const originalFetch = globalThis.fetch;
const originalBun = (globalThis as { Bun?: unknown }).Bun;