77} from "openclaw/plugin-sdk/channel-outbound" ;
88import { chunkMarkdownText as chunkMarkdownTextForLine } from "openclaw/plugin-sdk/reply-runtime" ;
99import { afterAll , afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
10- import type { OpenClawConfig , PluginRuntime } from "../api.js" ;
10+ import type { OpenClawConfig } from "../api.js" ;
1111import { linePlugin } from "./channel.js" ;
12+ import { createRuntime , lineResult } from "./channel.sendPayload.test-support.js" ;
1213import { lineConfigAdapter } from "./config-adapter.js" ;
1314import { resolveLineGroupRequireMention } from "./group-policy.js" ;
1415import { lineOutboundAdapter } from "./outbound.js" ;
@@ -28,21 +29,6 @@ afterAll(() => {
2829 vi . resetModules ( ) ;
2930} ) ;
3031
31- type LineRuntimeMocks = {
32- pushMessageLine : ReturnType < typeof vi . fn > ;
33- pushMessagesLine : ReturnType < typeof vi . fn > ;
34- pushFlexMessage : ReturnType < typeof vi . fn > ;
35- pushTemplateMessage : ReturnType < typeof vi . fn > ;
36- pushLocationMessage : ReturnType < typeof vi . fn > ;
37- pushTextMessageWithQuickReplies : ReturnType < typeof vi . fn > ;
38- createQuickReplyItems : ReturnType < typeof vi . fn > ;
39- buildTemplateMessageFromPayload : ReturnType < typeof vi . fn > ;
40- sendMessageLine : ReturnType < typeof vi . fn > ;
41- chunkMarkdownText : ReturnType < typeof vi . fn > ;
42- resolveLineAccount : ReturnType < typeof vi . fn > ;
43- resolveTextChunkLimit : ReturnType < typeof vi . fn > ;
44- } ;
45-
4632beforeEach ( ( ) => {
4733 vi . setSystemTime ( 1_800_000_000_000 ) ;
4834 ssrfMocks . resolvePinnedHostnameWithPolicy . mockReset ( ) ;
@@ -57,14 +43,6 @@ afterEach(() => {
5743 vi . useRealTimers ( ) ;
5844} ) ;
5945
60- function lineResult ( messageId : string , chatId = "c1" ) {
61- return {
62- messageId,
63- chatId,
64- receipt : createLineSendReceipt ( { messageId, chatId, kind : "text" } ) ,
65- } ;
66- }
67-
6846function createCredentialBearingHttpUrl ( ) : string {
6947 const url = new URL ( "http://example.com/image.jpg" ) ;
7048 url . username = [ "line" , "user" ] . join ( "-" ) ;
@@ -73,72 +51,6 @@ function createCredentialBearingHttpUrl(): string {
7351 return url . href ;
7452}
7553
76- function createRuntime ( ) : { runtime : PluginRuntime ; mocks : LineRuntimeMocks } {
77- const pushMessageLine = vi . fn ( async ( ) => lineResult ( "m-text" ) ) ;
78- const pushMessagesLine = vi . fn ( async ( ) => lineResult ( "m-batch" ) ) ;
79- const pushFlexMessage = vi . fn ( async ( ) => lineResult ( "m-flex" ) ) ;
80- const pushTemplateMessage = vi . fn ( async ( ) => lineResult ( "m-template" ) ) ;
81- const pushLocationMessage = vi . fn ( async ( ) => lineResult ( "m-loc" ) ) ;
82- const pushTextMessageWithQuickReplies = vi . fn ( async ( ) => lineResult ( "m-quick" ) ) ;
83- const createQuickReplyItems = vi . fn ( ( labels : string [ ] ) => ( { items : labels } ) ) ;
84- const buildTemplateMessageFromPayload = vi . fn ( ( ) => ( { type : "buttons" } ) ) ;
85- const sendMessageLine = vi . fn ( async ( ) => lineResult ( "m-media" ) ) ;
86- const chunkMarkdownText = vi . fn ( ( text : string ) => [ text ] ) ;
87- const resolveTextChunkLimit = vi . fn ( ( ) => 123 ) ;
88- const resolveLineAccount = vi . fn (
89- ( { cfg, accountId } : { cfg : OpenClawConfig ; accountId ?: string } ) => {
90- const resolved = accountId ?? "default" ;
91- const lineConfig = ( cfg . channels ?. line ?? { } ) as {
92- accounts ?: Record < string , Record < string , unknown > > ;
93- } ;
94- const accountConfig = resolved !== "default" ? ( lineConfig . accounts ?. [ resolved ] ?? { } ) : { } ;
95- return {
96- accountId : resolved ,
97- config : { ...lineConfig , ...accountConfig } ,
98- } ;
99- } ,
100- ) ;
101-
102- const runtime = {
103- channel : {
104- line : {
105- pushMessageLine,
106- pushMessagesLine,
107- pushFlexMessage,
108- pushTemplateMessage,
109- pushLocationMessage,
110- pushTextMessageWithQuickReplies,
111- createQuickReplyItems,
112- buildTemplateMessageFromPayload,
113- sendMessageLine,
114- resolveLineAccount,
115- } ,
116- text : {
117- chunkMarkdownText,
118- resolveTextChunkLimit,
119- } ,
120- } ,
121- } as unknown as PluginRuntime ;
122-
123- return {
124- runtime,
125- mocks : {
126- pushMessageLine,
127- pushMessagesLine,
128- pushFlexMessage,
129- pushTemplateMessage,
130- pushLocationMessage,
131- pushTextMessageWithQuickReplies,
132- createQuickReplyItems,
133- buildTemplateMessageFromPayload,
134- sendMessageLine,
135- chunkMarkdownText,
136- resolveLineAccount,
137- resolveTextChunkLimit,
138- } ,
139- } ;
140- }
141-
14254describe ( "line outbound sendPayload" , ( ) => {
14355 it . each ( [
14456 { name : "without quick replies" , quickReplies : [ ] as string [ ] } ,
0 commit comments