|
5 | 5 | verifyChannelMessageAdapterCapabilityProofs, |
6 | 6 | verifyChannelMessageReceiveAckPolicyAdapterProofs, |
7 | 7 | } from "openclaw/plugin-sdk/channel-outbound"; |
| 8 | +import { chunkMarkdownText as chunkMarkdownTextForLine } from "openclaw/plugin-sdk/reply-runtime"; |
8 | 9 | import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
9 | 10 | import type { OpenClawConfig, PluginRuntime } from "../api.js"; |
10 | 11 | import { linePlugin } from "./channel.js"; |
@@ -139,6 +140,63 @@ function createRuntime(): { runtime: PluginRuntime; mocks: LineRuntimeMocks } { |
139 | 140 | } |
140 | 141 |
|
141 | 142 | describe("line outbound sendPayload", () => { |
| 143 | + it.each([ |
| 144 | + { name: "without quick replies", quickReplies: [] as string[] }, |
| 145 | + { name: "with final quick replies", quickReplies: ["Continue"] }, |
| 146 | + ])("sends oversized tables in their source position $name", async ({ quickReplies }) => { |
| 147 | + const { runtime, mocks } = createRuntime(); |
| 148 | + setLineRuntime(runtime); |
| 149 | + mocks.resolveTextChunkLimit.mockReturnValue(5000); |
| 150 | + mocks.chunkMarkdownText.mockImplementation((text: string) => |
| 151 | + chunkMarkdownTextForLine(text, 5000), |
| 152 | + ); |
| 153 | + const markdown = `First\n\n| Small | Value |\n|---|---|\n| Kept | card |\n\nBetween\n\n| Name | Value |\n|---|---|\n| Large | ${"x".repeat(30_000)} |\n\nAfter\n\n\`\`\`js\nconsole.log("still a card")\n\`\`\``; |
| 154 | + |
| 155 | + await lineOutboundAdapter.sendPayload!({ |
| 156 | + to: "line:user:ordered", |
| 157 | + text: markdown, |
| 158 | + payload: { |
| 159 | + text: markdown, |
| 160 | + ...(quickReplies.length > 0 ? { channelData: { line: { quickReplies } } } : {}), |
| 161 | + }, |
| 162 | + accountId: "default", |
| 163 | + cfg: { channels: { line: {} } } as OpenClawConfig, |
| 164 | + }); |
| 165 | + |
| 166 | + const messages = [ |
| 167 | + ...mocks.pushFlexMessage.mock.calls.map((args, index) => ({ |
| 168 | + position: mocks.pushFlexMessage.mock.invocationCallOrder[index], |
| 169 | + type: args[1] === "Code" ? "code-card" : "valid-table-card", |
| 170 | + })), |
| 171 | + ...mocks.pushMessageLine.mock.calls.map((args, index) => ({ |
| 172 | + position: mocks.pushMessageLine.mock.invocationCallOrder[index], |
| 173 | + type: String(args[1]).includes("Large") ? "oversized-table-text" : "text", |
| 174 | + })), |
| 175 | + ...mocks.pushMessagesLine.mock.calls.flatMap((args, index) => |
| 176 | + args[1].map((message: { type: string; altText?: string }) => ({ |
| 177 | + position: mocks.pushMessagesLine.mock.invocationCallOrder[index], |
| 178 | + type: message.altText === "Code" ? "code-card" : message.type, |
| 179 | + })), |
| 180 | + ), |
| 181 | + ] |
| 182 | + .toSorted((left, right) => left.position - right.position) |
| 183 | + .map((message) => message.type) |
| 184 | + .filter((type) => type !== "text"); |
| 185 | + |
| 186 | + expect(messages).toEqual(["valid-table-card", "oversized-table-text", "code-card"]); |
| 187 | + expect(mocks.pushMessageLine.mock.calls.every((args) => String(args[1]).length <= 5000)).toBe( |
| 188 | + true, |
| 189 | + ); |
| 190 | + if (quickReplies.length > 0) { |
| 191 | + expect(mocks.pushMessagesLine).toHaveBeenCalledExactlyOnceWith( |
| 192 | + "line:user:ordered", |
| 193 | + [expect.objectContaining({ altText: "Code", quickReply: { items: quickReplies } })], |
| 194 | + expect.any(Object), |
| 195 | + ); |
| 196 | + expect(mocks.pushTextMessageWithQuickReplies).not.toHaveBeenCalled(); |
| 197 | + } |
| 198 | + }); |
| 199 | + |
142 | 200 | it.each([ |
143 | 201 | { name: "empty", text: "" }, |
144 | 202 | { name: "whitespace-only", text: " " }, |
|
0 commit comments