@@ -13,7 +13,7 @@ import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js";
1313import { createEmptyPluginRegistry } from "../plugins/registry-empty.js" ;
1414import { resetPluginRuntimeStateForTest , setActivePluginRegistry } from "../plugins/runtime.js" ;
1515import { withEnvAsync } from "../test-utils/env.js" ;
16- import { resizeToJpeg } from "./media-services.js" ;
16+ import { createImageProcessor , resizeToJpeg } from "./media-services.js" ;
1717import { encodePngRgba , fillPixel } from "./png-encode.js" ;
1818
1919let effectiveImageBytesCap : typeof import ( "./web-media.js" ) . effectiveImageBytesCap ;
@@ -488,6 +488,35 @@ describe("loadWebMedia", () => {
488488 }
489489 } ) ;
490490
491+ it ( "renames transparent WebP images converted to PNG across direct and local image owners" , async ( ) => {
492+ const { optimizeImageBufferForWebMedia } = await import ( "./web-media.js" ) ;
493+ const sourcePng = createLargeTransparentColorBlockPng ( 64 ) ;
494+ const sourceWebp = ( await createImageProcessor ( ) . encode ( sourcePng , { format : "webp" } ) ) . data ;
495+ const imageCompression = { models : [ { maxSidePx : 32 , preferredSidePx : 32 } ] } ;
496+
497+ const direct = await optimizeImageBufferForWebMedia ( {
498+ buffer : sourceWebp ,
499+ contentType : "image/webp" ,
500+ fileName : "portrait.WebP" ,
501+ maxBytes : 1024 * 1024 ,
502+ imageCompression,
503+ } ) ;
504+ const convertedPath = path . join ( fixtureRoot , "portrait.WebP" ) ;
505+ await fs . writeFile ( convertedPath , sourceWebp ) ;
506+ const loaded = await loadWebMedia ( convertedPath , {
507+ maxBytes : 1024 * 1024 ,
508+ localRoots : [ fixtureRoot ] ,
509+ imageCompression,
510+ } ) ;
511+
512+ for ( const result of [ direct , loaded ] ) {
513+ expect ( result . kind ) . toBe ( "image" ) ;
514+ expect ( result . contentType ) . toBe ( "image/png" ) ;
515+ expect ( result . fileName ) . toBe ( "portrait.png" ) ;
516+ expect ( readPngDimensions ( result . buffer ) ) . toEqual ( { width : 32 , height : 32 } ) ;
517+ }
518+ } ) ;
519+
491520 it ( "applies model image maxBytes to the effective image cap" , async ( ) => {
492521 await expect (
493522 loadWebMediaRaw ( tinyPngFile , {
0 commit comments