11// Runner entry policy tests cover resolveImageCompressionPolicyFromConfig merge
2- // precedence between agents.defaults, configured model metadata, and the bundled
3- // static catalog. Catalog lookup is mocked for determinism so the merge contract
4- // is proved without coupling to shipped catalog contents.
2+ // precedence between agents.defaults, configured model metadata, and the shared
3+ // model-aware compression resolver. The shared resolver is mocked so the merge
4+ // contract is proved without coupling to shipped catalog contents.
55import { beforeEach , describe , expect , it , vi } from "vitest" ;
6+ import type { ImageCompressionModelPolicy } from "../media/web-media.js" ;
67import type { OpenClawConfig } from "../config/types.js" ;
78
8- const { resolveBundledStaticCatalogModelMock } = vi . hoisted ( ( ) => ( {
9- resolveBundledStaticCatalogModelMock : vi . fn ( ) ,
9+ const { resolveCompressionModelPolicyMock } = vi . hoisted ( ( ) => ( {
10+ resolveCompressionModelPolicyMock : vi . fn < ( ) => Promise < ImageCompressionModelPolicy > > ( ) ,
1011} ) ) ;
1112
12- vi . mock ( "../agents/embedded-agent-runner/model.static-catalog .js" , ( ) => ( {
13- resolveBundledStaticCatalogModel : resolveBundledStaticCatalogModelMock ,
13+ vi . mock ( "../agents/tools/image-tool .js" , ( ) => ( {
14+ resolveCompressionModelPolicy : resolveCompressionModelPolicyMock ,
1415} ) ) ;
1516
1617import { resolveImageCompressionPolicyFromConfig } from "./runner.entries.js" ;
@@ -20,106 +21,70 @@ function makeCfg(overrides: unknown): OpenClawConfig {
2021}
2122
2223beforeEach ( ( ) => {
23- resolveBundledStaticCatalogModelMock . mockReset ( ) ;
24- resolveBundledStaticCatalogModelMock . mockReturnValue ( undefined ) ;
24+ resolveCompressionModelPolicyMock . mockReset ( ) ;
25+ resolveCompressionModelPolicyMock . mockResolvedValue ( { } ) ;
2526} ) ;
2627
2728describe ( "media-understanding resolveImageCompressionPolicyFromConfig" , ( ) => {
28- it ( "returns quality-only policy without imageMaxDimensionPx or provider/model" , ( ) => {
29+ it ( "returns quality-only policy without imageMaxDimensionPx or provider/model" , async ( ) => {
2930 const cfg = makeCfg ( { agents : { defaults : { imageQuality : "high" } } } ) ;
30- expect ( resolveImageCompressionPolicyFromConfig ( cfg ) ) . toEqual ( { quality : "high" } ) ;
31+ await expect ( resolveImageCompressionPolicyFromConfig ( cfg ) ) . resolves . toEqual ( { quality : "high" } ) ;
3132 } ) ;
3233
33- it ( "emits agents.defaults.imageMaxDimensionPx as a preferredSidePx entry" , ( ) => {
34+ it ( "emits agents.defaults.imageMaxDimensionPx as a preferredSidePx entry" , async ( ) => {
3435 const cfg = makeCfg ( {
3536 agents : { defaults : { imageQuality : "balanced" , imageMaxDimensionPx : 1024 } } ,
3637 } ) ;
37- expect ( resolveImageCompressionPolicyFromConfig ( cfg ) ) . toEqual ( {
38+ await expect ( resolveImageCompressionPolicyFromConfig ( cfg ) ) . resolves . toEqual ( {
3839 quality : "balanced" ,
3940 models : [ { preferredSidePx : 1024 } ] ,
4041 } ) ;
4142 } ) ;
4243
43- it ( "skips model merge when only provider is given (no model id)" , ( ) => {
44- const cfg = makeCfg ( {
45- models : {
46- providers : {
47- anthropic : {
48- models : [ { id : "claude-sonnet-5" , mediaInput : { image : { maxSidePx : 1234 } } } ] ,
49- } ,
50- } ,
51- } ,
52- } ) ;
53- expect ( resolveImageCompressionPolicyFromConfig ( cfg , { provider : "anthropic" } ) ) . toEqual ( {
54- quality : undefined ,
55- } ) ;
44+ it ( "skips model merge when only provider is given (no model id)" , async ( ) => {
45+ const cfg = makeCfg ( { } ) ;
46+ await expect (
47+ resolveImageCompressionPolicyFromConfig ( cfg , { provider : "anthropic" } ) ,
48+ ) . resolves . toEqual ( { } ) ;
5649 } ) ;
5750
58- it ( "skips model merge when only model is given (no provider)" , ( ) => {
59- const cfg = makeCfg ( {
60- models : {
61- providers : {
62- anthropic : {
63- models : [ { id : "claude-sonnet-5" , mediaInput : { image : { maxSidePx : 1234 } } } ] ,
64- } ,
65- } ,
66- } ,
67- } ) ;
68- expect ( resolveImageCompressionPolicyFromConfig ( cfg , { model : "claude-sonnet-5" } ) ) . toEqual ( {
69- quality : undefined ,
70- } ) ;
51+ it ( "skips model merge when only model is given (no provider)" , async ( ) => {
52+ const cfg = makeCfg ( { } ) ;
53+ await expect (
54+ resolveImageCompressionPolicyFromConfig ( cfg , { model : "claude-sonnet-5" } ) ,
55+ ) . resolves . toEqual ( { } ) ;
7156 } ) ;
7257
73- it ( "uses configured model mediaInput.image when catalog has no entry" , ( ) => {
74- resolveBundledStaticCatalogModelMock . mockReturnValue ( undefined ) ;
58+ it ( "includes shared resolver policy when provider+model are given" , async ( ) => {
59+ resolveCompressionModelPolicyMock . mockResolvedValue ( {
60+ maxSidePx : 4096 ,
61+ maxBytes : 5_000_000 ,
62+ } ) ;
7563 const cfg = makeCfg ( {
7664 agents : { defaults : { imageQuality : "balanced" } } ,
77- models : {
78- providers : {
79- "my-vendor" : {
80- models : [
81- {
82- id : "vision-9000" ,
83- mediaInput : { image : { maxSidePx : 4096 , maxBytes : 5_000_000 } } ,
84- } ,
85- ] ,
86- } ,
87- } ,
88- } ,
8965 } ) ;
90- const policy = resolveImageCompressionPolicyFromConfig ( cfg , {
66+ const policy = await resolveImageCompressionPolicyFromConfig ( cfg , {
9167 provider : "my-vendor" ,
9268 model : "vision-9000" ,
9369 } ) ;
9470 expect ( policy . models ) . toContainEqual ( { maxSidePx : 4096 , maxBytes : 5_000_000 } ) ;
9571 } ) ;
9672
97- it ( "configured limits override catalog limits; catalog fills missing fields" , ( ) => {
98- resolveBundledStaticCatalogModelMock . mockReturnValue ( {
99- mediaInput : {
100- image : { maxSidePx : 2576 , preferredSidePx : 2576 , maxPixels : 1_000_000 } ,
101- } ,
73+ it ( "merges defaults preferredSidePx with shared resolver model policy" , async ( ) => {
74+ resolveCompressionModelPolicyMock . mockResolvedValue ( {
75+ maxSidePx : 2576 ,
76+ preferredSidePx : 2576 ,
77+ maxPixels : 1_000_000 ,
78+ maxBytes : 8_000_000 ,
10279 } ) ;
10380 const cfg = makeCfg ( {
10481 agents : { defaults : { imageQuality : "balanced" , imageMaxDimensionPx : 1024 } } ,
105- models : {
106- providers : {
107- anthropic : {
108- models : [
109- {
110- id : "claude-sonnet-5" ,
111- mediaInput : { image : { maxBytes : 8_000_000 } } ,
112- } ,
113- ] ,
114- } ,
115- } ,
116- } ,
11782 } ) ;
118- const policy = resolveImageCompressionPolicyFromConfig ( cfg , {
83+ const policy = await resolveImageCompressionPolicyFromConfig ( cfg , {
11984 provider : "anthropic" ,
12085 model : "claude-sonnet-5" ,
12186 } ) ;
122- // Two model entries: [defaults preferredSidePx] then merged configured+catalog .
87+ // Two model entries: [defaults preferredSidePx] then shared resolver policy .
12388 expect ( policy . models ) . toEqual ( [
12489 { preferredSidePx : 1024 } ,
12590 {
@@ -131,13 +96,12 @@ describe("media-understanding resolveImageCompressionPolicyFromConfig", () => {
13196 ] ) ;
13297 } ) ;
13398
134- it ( "string model entries match by id but yield no object metadata and no models entry" , ( ) => {
135- resolveBundledStaticCatalogModelMock . mockReturnValue ( undefined ) ;
99+ it ( "skips empty shared resolver policy" , async ( ) => {
100+ resolveCompressionModelPolicyMock . mockResolvedValue ( { } ) ;
136101 const cfg = makeCfg ( {
137102 agents : { defaults : { imageQuality : "balanced" } } ,
138- models : { providers : { anthropic : { models : [ "claude-sonnet-5" ] } } } ,
139103 } ) ;
140- const policy = resolveImageCompressionPolicyFromConfig ( cfg , {
104+ const policy = await resolveImageCompressionPolicyFromConfig ( cfg , {
141105 provider : "anthropic" ,
142106 model : "claude-sonnet-5" ,
143107 } ) ;
0 commit comments