@@ -16,12 +16,16 @@ import type {
1616 ImagesDescriptionRequest ,
1717 MediaUnderstandingProvider ,
1818} from "../../plugin-sdk/media-understanding.js" ;
19- import { installTemporaryCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-snapshot.js" ;
19+ import {
20+ getCurrentPluginMetadataSnapshot ,
21+ installTemporaryCurrentPluginMetadataSnapshot ,
22+ } from "../../plugins/current-plugin-metadata-snapshot.js" ;
2023import type { PluginManifestRecord } from "../../plugins/manifest-registry.js" ;
2124import { withEnvAsync } from "../../test-utils/env.js" ;
2225import { withFetchPreconnect } from "../../test-utils/fetch-mock.js" ;
2326import type { AuthProfileCredential , AuthProfileStore } from "../auth-profiles/types.js" ;
2427import { minimaxUnderstandImage } from "../minimax-vlm.js" ;
28+ import type { PreparedModelRuntimeSnapshot } from "../prepared-model-runtime.js" ;
2529import {
2630 createContainerWorkspaceSandboxFsBridge ,
2731 createHostSandboxFsBridge ,
@@ -653,6 +657,7 @@ function installImageUnderstandingProviderDeps(
653657 resolveModelAsync ?: NonNullable <
654658 Parameters < typeof testing . setProviderDepsForTest > [ 0 ]
655659 > [ "resolveModelAsync" ] ;
660+ useDefaultResolveModelAsync ?: boolean ;
656661 } ,
657662) {
658663 imageProviderHarness . setProviders ( providers ) ;
@@ -686,7 +691,9 @@ function installImageUnderstandingProviderDeps(
686691 providerId ,
687692 imageProviderHarness . buildProviderRegistry ( ) ,
688693 ) ,
689- resolveModelAsync : options ?. resolveModelAsync ?? resolveConfiguredImageModelForTest ,
694+ ...( options ?. useDefaultResolveModelAsync
695+ ? { }
696+ : { resolveModelAsync : options ?. resolveModelAsync ?? resolveConfiguredImageModelForTest } ) ,
690697 ...( options ?. resolveImageCompressionPolicy
691698 ? { resolveImageCompressionPolicy : options . resolveImageCompressionPolicy }
692699 : { } ) ,
@@ -3184,28 +3191,16 @@ describe("image compression policy", () => {
31843191 it ( "keeps runtime augmentation pinned to the prepared plugin generation" , async ( ) => {
31853192 const provider = "prepared-image-provider" ;
31863193 const model = "prepared-image-model" ;
3187- const cfg = {
3188- models : {
3189- providers : {
3190- [ provider ] : {
3191- baseUrl : "https://prepared-image.example.test/v1" ,
3192- api : "openai-completions" ,
3193- models : [
3194- {
3195- id : model ,
3196- name : "Prepared image model" ,
3197- reasoning : false ,
3198- input : [ "text" , "image" ] ,
3199- cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 } ,
3200- contextWindow : 128_000 ,
3201- maxTokens : 8_192 ,
3202- } ,
3203- ] ,
3204- } ,
3205- } ,
3194+ const workspaceDir = "/fake/prepared-image-workspace" ;
3195+ const cfg = { } satisfies OpenClawConfig ;
3196+ const createSnapshot = (
3197+ runtimeAugment : boolean ,
3198+ imagePolicy : {
3199+ maxBytes : number ;
3200+ preferredSidePx : number ;
3201+ tokenMode : "detail" | "provider" ;
32063202 } ,
3207- } satisfies OpenClawConfig ;
3208- const createSnapshot = ( runtimeAugment : boolean ) => {
3203+ ) => {
32093204 const plugin = {
32103205 id : "prepared-image-plugin" ,
32113206 enabledByDefault : true ,
@@ -3220,60 +3215,90 @@ describe("image compression policy", () => {
32203215 manifestPath : "/fake/prepared-image-plugin/openclaw.plugin.json" ,
32213216 modelCatalog : {
32223217 runtimeAugment,
3218+ discovery : { [ provider ] : "static" } ,
32233219 providers : {
32243220 [ provider ] : {
32253221 baseUrl : "https://prepared-image.example.test/v1" ,
32263222 api : "openai-completions" ,
3227- models : [ { id : model , name : "Prepared image model" } ] ,
3223+ models : [
3224+ {
3225+ id : model ,
3226+ name : "Prepared image model" ,
3227+ mediaInput : { image : imagePolicy } ,
3228+ } ,
3229+ ] ,
32283230 } ,
32293231 } ,
32303232 } ,
32313233 } satisfies PluginManifestRecord ;
32323234 return createPluginMetadataSnapshot ( {
32333235 config : cfg ,
32343236 manifestRegistry : { plugins : [ plugin ] , diagnostics : [ ] } ,
3237+ workspaceDir,
32353238 } ) ;
32363239 } ;
3237- const preparedSnapshot = createSnapshot ( false ) ;
3238- const currentSnapshot = createSnapshot ( true ) ;
3239- const hookModes : Array < boolean | undefined > = [ ] ;
3240+ const preparedSnapshot = createSnapshot ( true , {
3241+ maxBytes : 1_000_000 ,
3242+ preferredSidePx : 1_280 ,
3243+ tokenMode : "detail" ,
3244+ } ) ;
3245+ const currentSnapshot = createSnapshot ( false , {
3246+ maxBytes : 2_000_000 ,
3247+ preferredSidePx : 2_560 ,
3248+ tokenMode : "provider" ,
3249+ } ) ;
3250+ const preparedModelRuntime = {
3251+ agentDir : "/fake/prepared-image-agent" ,
3252+ workspaceDir,
3253+ activeProjectKeys : [ ] ,
3254+ allowGatewaySubagentBinding : false ,
3255+ config : cfg ,
3256+ authModes : { } ,
3257+ metadataSnapshot : preparedSnapshot ,
3258+ modelCatalog : { entries : [ ] , routeVariants : [ ] } ,
3259+ configuredRuntimeModels : [ ] ,
3260+ inlineProviderModels : [ ] ,
3261+ createStores : ( ) => ( { authStorage : { } as never , modelRegistry : { } as never } ) ,
3262+ } satisfies PreparedModelRuntimeSnapshot ;
3263+ const modelModule = await import ( "../embedded-agent-runner/model.js" ) ;
3264+ const resolveModelAsyncSpy = vi . spyOn ( modelModule , "resolveModelAsync" ) ;
32403265 installImageUnderstandingProviderDeps ( [ ] , {
3241- resolveModelAsync : async ( resolvedProvider , resolvedModel , _agentDir , _cfg , options ) => {
3242- hookModes . push ( options ?. skipProviderRuntimeHooks ) ;
3243- return {
3244- model : {
3245- id : resolvedModel ,
3246- provider : resolvedProvider ,
3247- input : [ "text" , "image" ] ,
3248- mediaInput : {
3249- image : options ?. skipProviderRuntimeHooks
3250- ? { maxBytes : 1_000_000 }
3251- : { maxSidePx : 4096 } ,
3252- } ,
3253- } as never ,
3254- authStorage : { } as never ,
3255- modelRegistry : { } as never ,
3256- } ;
3257- } ,
3266+ useDefaultResolveModelAsync : true ,
32583267 } ) ;
32593268 const currentLease = installTemporaryCurrentPluginMetadataSnapshot ( currentSnapshot , {
32603269 config : cfg ,
3270+ workspaceDir,
32613271 } ) ;
32623272
32633273 try {
3274+ expect ( getCurrentPluginMetadataSnapshot ( { config : cfg , workspaceDir } ) ) . toBe ( currentSnapshot ) ;
32643275 await expect (
32653276 testing . resolveImageCompressionPolicy ( {
32663277 cfg,
32673278 imageModelConfig : { primary : `${ provider } /${ model } ` } ,
32683279 imageCount : 1 ,
3269- metadataSnapshot : preparedSnapshot ,
3280+ preparedModelRuntime,
3281+ workspaceDir,
32703282 } ) ,
32713283 ) . resolves . toEqual ( {
32723284 imageCount : 1 ,
3273- models : [ { maxBytes : 1_000_000 } ] ,
3285+ models : [
3286+ {
3287+ maxBytes : 1_000_000 ,
3288+ preferredSidePx : 1_280 ,
3289+ tokenMode : "detail" ,
3290+ } ,
3291+ ] ,
32743292 } ) ;
3275- expect ( hookModes ) . toEqual ( [ true ] ) ;
3293+ expect ( resolveModelAsyncSpy ) . toHaveBeenCalledTimes ( 2 ) ;
3294+ expect (
3295+ resolveModelAsyncSpy . mock . calls . map ( ( call ) => call [ 4 ] ?. skipProviderRuntimeHooks ) ,
3296+ ) . toEqual ( [ true , false ] ) ;
3297+ for ( const call of resolveModelAsyncSpy . mock . calls ) {
3298+ expect ( call [ 4 ] ?. preparedModelRuntime ) . toBe ( preparedModelRuntime ) ;
3299+ }
32763300 } finally {
3301+ resolveModelAsyncSpy . mockRestore ( ) ;
32773302 currentLease . release ( ) ;
32783303 }
32793304 } ) ;
0 commit comments