|
7 | 7 | mockLogger, |
8 | 8 | } from "./mock-adapter"; |
9 | 9 | import { Plan } from "./plan"; |
| 10 | +import { StreamingPlan } from "./streaming-plan"; |
10 | 11 | import { ThreadImpl } from "./thread"; |
11 | 12 | import type { Adapter, Message, ScheduledMessage, StreamChunk } from "./types"; |
12 | 13 | import { NotImplementedError } from "./types"; |
@@ -638,6 +639,151 @@ describe("ThreadImpl", () => { |
638 | 639 | }) |
639 | 640 | ); |
640 | 641 | }); |
| 642 | + |
| 643 | + it("should pass StreamingPlan PostableObject options to adapter.stream", async () => { |
| 644 | + const mockStream = vi.fn().mockResolvedValue({ |
| 645 | + id: "msg-stream", |
| 646 | + threadId: "t1", |
| 647 | + raw: "Hello", |
| 648 | + }); |
| 649 | + mockAdapter.stream = mockStream; |
| 650 | + |
| 651 | + const textStream = createTextStream(["Hello"]); |
| 652 | + const streamMsg = new StreamingPlan(textStream, { |
| 653 | + groupTasks: "plan", |
| 654 | + endWith: [{ type: "actions" }], |
| 655 | + updateIntervalMs: 1000, |
| 656 | + }); |
| 657 | + await thread.post(streamMsg); |
| 658 | + |
| 659 | + expect(mockStream).toHaveBeenCalledWith( |
| 660 | + "slack:C123:1234.5678", |
| 661 | + expect.any(Object), |
| 662 | + expect.objectContaining({ |
| 663 | + taskDisplayMode: "plan", |
| 664 | + stopBlocks: [{ type: "actions" }], |
| 665 | + updateIntervalMs: 1000, |
| 666 | + }) |
| 667 | + ); |
| 668 | + }); |
| 669 | + |
| 670 | + it("should pass StreamingPlan with only groupTasks", async () => { |
| 671 | + const mockStream = vi.fn().mockResolvedValue({ |
| 672 | + id: "msg-stream", |
| 673 | + threadId: "t1", |
| 674 | + raw: "Hello", |
| 675 | + }); |
| 676 | + mockAdapter.stream = mockStream; |
| 677 | + |
| 678 | + const textStream = createTextStream(["Hello"]); |
| 679 | + await thread.post( |
| 680 | + new StreamingPlan(textStream, { groupTasks: "timeline" }) |
| 681 | + ); |
| 682 | + |
| 683 | + expect(mockStream).toHaveBeenCalledWith( |
| 684 | + "slack:C123:1234.5678", |
| 685 | + expect.any(Object), |
| 686 | + expect.objectContaining({ |
| 687 | + taskDisplayMode: "timeline", |
| 688 | + }) |
| 689 | + ); |
| 690 | + const options = mockStream.mock.calls[0][2]; |
| 691 | + expect(options.stopBlocks).toBeUndefined(); |
| 692 | + }); |
| 693 | + |
| 694 | + it("should pass StreamingPlan with only endWith", async () => { |
| 695 | + const mockStream = vi.fn().mockResolvedValue({ |
| 696 | + id: "msg-stream", |
| 697 | + threadId: "t1", |
| 698 | + raw: "Hello", |
| 699 | + }); |
| 700 | + mockAdapter.stream = mockStream; |
| 701 | + |
| 702 | + const textStream = createTextStream(["Hello"]); |
| 703 | + await thread.post( |
| 704 | + new StreamingPlan(textStream, { endWith: [{ type: "actions" }] }) |
| 705 | + ); |
| 706 | + |
| 707 | + expect(mockStream).toHaveBeenCalledWith( |
| 708 | + "slack:C123:1234.5678", |
| 709 | + expect.any(Object), |
| 710 | + expect.objectContaining({ |
| 711 | + stopBlocks: [{ type: "actions" }], |
| 712 | + }) |
| 713 | + ); |
| 714 | + const options = mockStream.mock.calls[0][2]; |
| 715 | + expect(options.taskDisplayMode).toBeUndefined(); |
| 716 | + }); |
| 717 | + |
| 718 | + it("should pass StreamingPlan with only updateIntervalMs", async () => { |
| 719 | + const mockStream = vi.fn().mockResolvedValue({ |
| 720 | + id: "msg-stream", |
| 721 | + threadId: "t1", |
| 722 | + raw: "Hello", |
| 723 | + }); |
| 724 | + mockAdapter.stream = mockStream; |
| 725 | + |
| 726 | + const textStream = createTextStream(["Hello"]); |
| 727 | + await thread.post( |
| 728 | + new StreamingPlan(textStream, { updateIntervalMs: 2000 }) |
| 729 | + ); |
| 730 | + |
| 731 | + expect(mockStream).toHaveBeenCalledWith( |
| 732 | + "slack:C123:1234.5678", |
| 733 | + expect.any(Object), |
| 734 | + expect.objectContaining({ |
| 735 | + updateIntervalMs: 2000, |
| 736 | + }) |
| 737 | + ); |
| 738 | + const options = mockStream.mock.calls[0][2]; |
| 739 | + expect(options.taskDisplayMode).toBeUndefined(); |
| 740 | + expect(options.stopBlocks).toBeUndefined(); |
| 741 | + }); |
| 742 | + |
| 743 | + it("should route StreamingPlan through fallback when adapter has no native streaming", async () => { |
| 744 | + mockAdapter.stream = undefined; |
| 745 | + |
| 746 | + const textStream = createTextStream(["Hello", " ", "World"]); |
| 747 | + await thread.post( |
| 748 | + new StreamingPlan(textStream, { |
| 749 | + groupTasks: "plan", |
| 750 | + endWith: [{ type: "actions" }], |
| 751 | + updateIntervalMs: 2000, |
| 752 | + }) |
| 753 | + ); |
| 754 | + |
| 755 | + // Should post initial placeholder and edit with final content |
| 756 | + expect(mockAdapter.postMessage).toHaveBeenCalledWith( |
| 757 | + "slack:C123:1234.5678", |
| 758 | + "..." |
| 759 | + ); |
| 760 | + expect(mockAdapter.editMessage).toHaveBeenLastCalledWith( |
| 761 | + "slack:C123:1234.5678", |
| 762 | + "msg-1", |
| 763 | + { markdown: "Hello World" } |
| 764 | + ); |
| 765 | + }); |
| 766 | + |
| 767 | + it("should still work without options (backward compat)", async () => { |
| 768 | + const mockStream = vi.fn().mockResolvedValue({ |
| 769 | + id: "msg-stream", |
| 770 | + threadId: "t1", |
| 771 | + raw: "Hello", |
| 772 | + }); |
| 773 | + mockAdapter.stream = mockStream; |
| 774 | + |
| 775 | + const textStream = createTextStream(["Hello"]); |
| 776 | + await thread.post(textStream); |
| 777 | + |
| 778 | + expect(mockStream).toHaveBeenCalledWith( |
| 779 | + "slack:C123:1234.5678", |
| 780 | + expect.any(Object), |
| 781 | + expect.any(Object) |
| 782 | + ); |
| 783 | + const options = mockStream.mock.calls[0][2]; |
| 784 | + expect(options.taskDisplayMode).toBeUndefined(); |
| 785 | + expect(options.stopBlocks).toBeUndefined(); |
| 786 | + }); |
641 | 787 | }); |
642 | 788 |
|
643 | 789 | describe("fallback streaming error logging", () => { |
|
0 commit comments