|
1 | 1 | // Isolated agent delivery target tests cover target resolution for cron runs. |
2 | 2 | import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | | -import type { ChannelOutboundAdapter } from "../../channels/plugins/types.js"; |
| 3 | +import type { |
| 4 | +ChannelDirectoryEntry, |
| 5 | +ChannelOutboundAdapter, |
| 6 | +} from "../../channels/plugins/types.js"; |
4 | 7 | import type { OpenClawConfig } from "../../config/config.js"; |
5 | 8 | import type { SessionEntry } from "../../config/sessions/types.js"; |
6 | 9 | import { |
@@ -741,6 +744,57 @@ describe("resolveDeliveryTarget", () => {
|
741 | 744 | expect(result.threadId).toBeUndefined(); |
742 | 745 | }); |
743 | 746 | |
| 747 | +it("resolves cron reserved explicit targets through directory entries", async () => { |
| 748 | +setMainSessionEntry(undefined); |
| 749 | +const listGroups = vi.fn(async () => [ |
| 750 | +{ |
| 751 | +kind: "group", |
| 752 | +id: "-1002458651455", |
| 753 | +name: "current", |
| 754 | +handle: "@current", |
| 755 | +} satisfies ChannelDirectoryEntry, |
| 756 | +]); |
| 757 | +setActivePluginRegistry( |
| 758 | +createTestRegistry([ |
| 759 | +{ |
| 760 | +pluginId: "telegram", |
| 761 | +source: "test", |
| 762 | +plugin: { |
| 763 | + ...createOutboundTestPlugin({ |
| 764 | +id: "telegram", |
| 765 | +outbound: createStubOutbound("Telegram"), |
| 766 | +capabilities: { chatTypes: ["direct", "group", "channel"] }, |
| 767 | +messaging: { |
| 768 | + ...telegramMessagingForTest, |
| 769 | +normalizeTarget: normalizeTelegramTargetForDeliveryTest, |
| 770 | +targetResolver: { |
| 771 | +reservedLiterals: ["current", "self", "this", "me"], |
| 772 | +hint: "<chatId>", |
| 773 | +}, |
| 774 | +}, |
| 775 | +}), |
| 776 | +directory: { listGroups }, |
| 777 | +}, |
| 778 | +}, |
| 779 | +]), |
| 780 | +); |
| 781 | + |
| 782 | +const result = await resolveDeliveryTarget(makeCfg({ bindings: [] }), AGENT_ID, { |
| 783 | +channel: "telegram", |
| 784 | +to: "current", |
| 785 | +}); |
| 786 | + |
| 787 | +expect(result.ok).toBe(true); |
| 788 | +expect(result.to).toBe("-1002458651455"); |
| 789 | +expect(result.threadId).toBeUndefined(); |
| 790 | +expect(listGroups).toHaveBeenCalledWith( |
| 791 | +expect.objectContaining({ |
| 792 | +accountId: undefined, |
| 793 | +query: "current", |
| 794 | +}), |
| 795 | +); |
| 796 | +}); |
| 797 | + |
744 | 798 | it("uses canonical route targets even when the route has no thread", async () => { |
745 | 799 | setMainSessionEntry(undefined); |
746 | 800 | setActivePluginRegistry( |
|