@@ -3,33 +3,19 @@ import type { OpenClawPluginCommandDefinition } from "openclaw/plugin-sdk/plugin
33import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api" ;
44import { describe , expect , it } from "vitest" ;
55import lineEntry from "./index.js" ;
6- import { registerLineCardCommand } from "./src/card-command.js" ;
76
8- /**
9- * Collect what a registration actually hands the host.
10- *
11- * The bundled entry registers `/card` eagerly and loads its handler lazily, so
12- * the registration the host sees is the one the entry declares, not the one
13- * inside the handler module.
14- */
15- function registeredCommands ( register : ( api : ReturnType < typeof createTestPluginApi > ) => void ) {
7+ function registeredCardCommand ( ) : OpenClawPluginCommandDefinition {
168 const commands : OpenClawPluginCommandDefinition [ ] = [ ] ;
17- register (
9+ lineEntry . register (
1810 createTestPluginApi ( {
19- // Runs the entry's command registration without loading the channel plugin .
11+ // Exercise the shipped registration without loading the full channel runtime .
2012 registrationMode : "tool-discovery" ,
2113 registerCommand ( command ) {
2214 commands . push ( command ) ;
2315 } ,
2416 } ) ,
2517 ) ;
26- return commands ;
27- }
28-
29- function cardCommandFrom (
30- register : ( api : ReturnType < typeof createTestPluginApi > ) => void ,
31- ) : OpenClawPluginCommandDefinition {
32- const card = registeredCommands ( register ) . find ( ( command ) => command . name === "card" ) ;
18+ const card = commands . find ( ( command ) => command . name === "card" ) ;
3319 if ( ! card ) {
3420 throw new Error ( "LINE did not register a /card command" ) ;
3521 }
@@ -38,21 +24,32 @@ function cardCommandFrom(
3824
3925describe ( "line /card registration" , ( ) => {
4026 it ( "offers the command on LINE only" , ( ) => {
41- // Flex cards are a LINE transport feature. Core turns this declaration into
42- // the actual gating for listings, native command menus, text matching and
43- // execution; see src/plugins/commands.test.ts for that behavior.
44- expect ( cardCommandFrom ( ( api ) => lineEntry . register ( api ) ) . channels ) . toEqual ( [ "line" ] ) ;
27+ expect ( registeredCardCommand ( ) ) . toMatchObject ( {
28+ channels : [ "line" ] ,
29+ acceptsArgs : true ,
30+ requireAuth : false ,
31+ } ) ;
4532 } ) ;
4633
47- it ( "keeps the handler module's declaration identical to the shipped one" , ( ) => {
48- // Two copies of this metadata would let the shipped scope drift away from
49- // the one the handler module declares, with nothing reporting the gap.
50- const shipped = cardCommandFrom ( ( api ) => lineEntry . register ( api ) ) ;
51- const local = cardCommandFrom ( registerLineCardCommand ) ;
52- expect ( local . channels ) . toEqual ( shipped . channels ) ;
53- expect ( local . name ) . toBe ( shipped . name ) ;
54- expect ( local . description ) . toBe ( shipped . description ) ;
55- expect ( local . acceptsArgs ) . toBe ( shipped . acceptsArgs ) ;
56- expect ( local . requireAuth ) . toBe ( shipped . requireAuth ) ;
34+ it ( "renders a card through the registered lazy handler" , async ( ) => {
35+ const args = 'info "Welcome" "Thanks for joining!"' ;
36+ await expect (
37+ registeredCardCommand ( ) . handler ( {
38+ channel : "line" ,
39+ isAuthorizedSender : false ,
40+ commandBody : `/card ${ args } ` ,
41+ args,
42+ config : { } ,
43+ requestConversationBinding : async ( ) => ( { status : "error" , message : "unused" } ) ,
44+ detachConversationBinding : async ( ) => ( { removed : false } ) ,
45+ getCurrentConversationBinding : async ( ) => null ,
46+ } ) ,
47+ ) . resolves . toMatchObject ( {
48+ channelData : {
49+ line : {
50+ flexMessage : { altText : "Welcome: Thanks for joining!" , contents : { type : "bubble" } } ,
51+ } ,
52+ } ,
53+ } ) ;
5754 } ) ;
5855} ) ;
0 commit comments