@@ -18,6 +18,16 @@ import { buildLineMessageContext, buildLinePostbackContext } from "./bot-message
1818import type { ResolvedLineAccount } from "./types.js" ;
1919
2020const logVerboseMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
21+ const toInboundMediaFactsWithMetadataMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
22+
23+ vi . mock ( "openclaw/plugin-sdk/channel-inbound" , async ( importOriginal ) => {
24+ const actual = await importOriginal < typeof import ( "openclaw/plugin-sdk/channel-inbound" ) > ( ) ;
25+ toInboundMediaFactsWithMetadataMock . mockImplementation ( actual . toInboundMediaFactsWithMetadata ) ;
26+ return {
27+ ...actual ,
28+ toInboundMediaFactsWithMetadata : toInboundMediaFactsWithMetadataMock ,
29+ } ;
30+ } ) ;
2131
2232vi . mock ( "openclaw/plugin-sdk/runtime-env" , async ( ) => {
2333 const actual = await vi . importActual < typeof import ( "openclaw/plugin-sdk/runtime-env" ) > (
@@ -89,6 +99,7 @@ describe("buildLineMessageContext", () => {
8999
90100 beforeEach ( async ( ) => {
91101 logVerboseMock . mockClear ( ) ;
102+ toInboundMediaFactsWithMetadataMock . mockClear ( ) ;
92103 setActivePluginRegistry (
93104 createTestRegistry ( [
94105 {
@@ -129,6 +140,21 @@ describe("buildLineMessageContext", () => {
129140 expect ( context ?. ctxPayload . To ) . toBe ( "line:group:group-1" ) ;
130141 } ) ;
131142
143+ it ( "skips media metadata projection for text-only messages" , async ( ) => {
144+ const event = createMessageEvent ( { type : "user" , userId : "user-1" } ) ;
145+
146+ const context = await buildLineMessageContext ( {
147+ event,
148+ allMedia : [ ] ,
149+ cfg,
150+ account,
151+ commandAuthorized : true ,
152+ } ) ;
153+
154+ expect ( context ?. ctxPayload . media ) . toEqual ( [ ] ) ;
155+ expect ( toInboundMediaFactsWithMetadataMock ) . not . toHaveBeenCalled ( ) ;
156+ } ) ;
157+
132158 it ( "passes the caller-provided inbound history through to the context payload" , async ( ) => {
133159 const event = createMessageEvent ( { type : "group" , groupId : "group-1" , userId : "user-1" } ) ;
134160
0 commit comments