@@ -8,13 +8,16 @@ import { isInboundPathAllowed } from "@openclaw/media-core/inbound-path-policy";
88import { expectDefined } from "@openclaw/normalization-core" ;
99import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
1010import type { OpenClawConfig } from "../../config/config.js" ;
11+ import { createPluginMetadataSnapshot } from "../../config/plugin-auto-enable.test-helpers.js" ;
1112import type { ModelDefinitionConfig } from "../../config/types.models.js" ;
1213import { encodePngRgba , fillPixel } from "../../media/png-encode.js" ;
1314import type {
1415 ImageDescriptionRequest ,
1516 ImagesDescriptionRequest ,
1617 MediaUnderstandingProvider ,
1718} from "../../plugin-sdk/media-understanding.js" ;
19+ import { installTemporaryCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-snapshot.js" ;
20+ import type { PluginManifestRecord } from "../../plugins/manifest-registry.js" ;
1821import { withEnvAsync } from "../../test-utils/env.js" ;
1922import { withFetchPreconnect } from "../../test-utils/fetch-mock.js" ;
2023import type { AuthProfileCredential , AuthProfileStore } from "../auth-profiles/types.js" ;
@@ -3149,6 +3152,103 @@ describe("image compression policy", () => {
31493152 testing . setProviderDepsForTest ( ) ;
31503153 } ) ;
31513154
3155+ it ( "keeps runtime augmentation pinned to the prepared plugin generation" , async ( ) => {
3156+ const provider = "prepared-image-provider" ;
3157+ const model = "prepared-image-model" ;
3158+ const cfg = {
3159+ models : {
3160+ providers : {
3161+ [ provider ] : {
3162+ baseUrl : "https://prepared-image.example.test/v1" ,
3163+ api : "openai-completions" ,
3164+ models : [
3165+ {
3166+ id : model ,
3167+ name : "Prepared image model" ,
3168+ reasoning : false ,
3169+ input : [ "text" , "image" ] ,
3170+ cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 } ,
3171+ contextWindow : 128_000 ,
3172+ maxTokens : 8_192 ,
3173+ } ,
3174+ ] ,
3175+ } ,
3176+ } ,
3177+ } ,
3178+ } satisfies OpenClawConfig ;
3179+ const createSnapshot = ( runtimeAugment : boolean ) => {
3180+ const plugin = {
3181+ id : "prepared-image-plugin" ,
3182+ enabledByDefault : true ,
3183+ channels : [ ] ,
3184+ providers : [ provider ] ,
3185+ cliBackends : [ ] ,
3186+ skills : [ ] ,
3187+ hooks : [ ] ,
3188+ origin : "bundled" ,
3189+ rootDir : "/fake/prepared-image-plugin" ,
3190+ source : "/fake/prepared-image-plugin/index.js" ,
3191+ manifestPath : "/fake/prepared-image-plugin/openclaw.plugin.json" ,
3192+ modelCatalog : {
3193+ runtimeAugment,
3194+ providers : {
3195+ [ provider ] : {
3196+ baseUrl : "https://prepared-image.example.test/v1" ,
3197+ api : "openai-completions" ,
3198+ models : [ { id : model , name : "Prepared image model" } ] ,
3199+ } ,
3200+ } ,
3201+ } ,
3202+ } satisfies PluginManifestRecord ;
3203+ return createPluginMetadataSnapshot ( {
3204+ config : cfg ,
3205+ manifestRegistry : { plugins : [ plugin ] , diagnostics : [ ] } ,
3206+ } ) ;
3207+ } ;
3208+ const preparedSnapshot = createSnapshot ( false ) ;
3209+ const currentSnapshot = createSnapshot ( true ) ;
3210+ const hookModes : Array < boolean | undefined > = [ ] ;
3211+ installImageUnderstandingProviderDeps ( [ ] , {
3212+ resolveModelAsync : async ( resolvedProvider , resolvedModel , _agentDir , _cfg , options ) => {
3213+ hookModes . push ( options ?. skipProviderRuntimeHooks ) ;
3214+ return {
3215+ model : {
3216+ id : resolvedModel ,
3217+ provider : resolvedProvider ,
3218+ input : [ "text" , "image" ] ,
3219+ mediaInput : {
3220+ image : options ?. skipProviderRuntimeHooks
3221+ ? { maxBytes : 1_000_000 }
3222+ : { maxSidePx : 4096 } ,
3223+ } ,
3224+ } as never ,
3225+ authStorage : { } as never ,
3226+ modelRegistry : { } as never ,
3227+ } ;
3228+ } ,
3229+ } ) ;
3230+ const currentLease = installTemporaryCurrentPluginMetadataSnapshot ( currentSnapshot , {
3231+ config : cfg ,
3232+ } ) ;
3233+
3234+ try {
3235+ await expect (
3236+ testing . resolveImageCompressionPolicy ( {
3237+ cfg,
3238+ imageModelConfig : { primary : `${ provider } /${ model } ` } ,
3239+ imageCount : 1 ,
3240+ metadataSnapshot : preparedSnapshot ,
3241+ } ) ,
3242+ ) . resolves . toEqual ( {
3243+ imageCount : 1 ,
3244+ models : [ { maxBytes : 1_000_000 } ] ,
3245+ } ) ;
3246+ expect ( hookModes ) . toEqual ( [ true ] ) ;
3247+ } finally {
3248+ currentLease . release ( ) ;
3249+ }
3250+ } ) ;
3251+
31523252 it ( "derives model metadata, quality preference, and image count from config" , async ( ) => {
31533253 const cfg = {
31543254 ...cfgWithImageModelMetadata ,
0 commit comments