11// Verifies configured model selection uses manifest policy only in scoped contexts.
22import { beforeEach , describe , expect , it , vi } from "vitest" ;
33import type { OpenClawConfig } from "../config/types.openclaw.js" ;
4+ import {
5+ buildAllowedModelSet ,
6+ buildConfiguredModelCatalog ,
7+ buildModelAliasIndex ,
8+ resolveConfiguredModelRef ,
9+ } from "./model-selection-shared.js" ;
410
511const loadManifestMetadataSnapshotMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
612const getCurrentPluginMetadataSnapshotMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
@@ -26,7 +32,6 @@ vi.mock("./provider-model-normalization.runtime.js", () => ({
2632
2733describe ( "configured model manifest workspace scope" , ( ) => {
2834 beforeEach ( ( ) => {
29- vi . resetModules ( ) ;
3035 loadManifestMetadataSnapshotMock . mockReset ( ) ;
3136 getCurrentPluginMetadataSnapshotMock . mockReset ( ) ;
3237 getActivePluginRegistryWorkspaceDirFromStateMock . mockReset ( ) ;
@@ -47,10 +52,9 @@ describe("configured model manifest workspace scope", () => {
4752 } ) ;
4853 } ) ;
4954
50- it ( "does not reuse workspace manifest policies without a workspace context" , async ( ) => {
55+ it ( "does not reuse workspace manifest policies without a workspace context" , ( ) => {
5156 // Workspace plugin normalization must not leak into unscoped callers; they
5257 // can only use the current global metadata snapshot.
53- const { buildConfiguredModelCatalog } = await import ( "./model-selection-shared.js" ) ;
5458 const cfg = {
5559 models : {
5660 providers : {
@@ -74,8 +78,7 @@ describe("configured model manifest workspace scope", () => {
7478 expect ( loadManifestMetadataSnapshotMock ) . not . toHaveBeenCalled ( ) ;
7579 } ) ;
7680
77- it ( "uses manifest policies when the workspace context is explicit" , async ( ) => {
78- const { buildConfiguredModelCatalog } = await import ( "./model-selection-shared.js" ) ;
81+ it ( "uses manifest policies when the workspace context is explicit" , ( ) => {
7982 const cfg = {
8083 models : {
8184 providers : {
@@ -100,7 +103,7 @@ describe("configured model manifest workspace scope", () => {
100103 expect ( getCurrentPluginMetadataSnapshotMock ) . not . toHaveBeenCalled ( ) ;
101104 } ) ;
102105
103- it ( "uses an unscoped current snapshot without falling back to a metadata scan" , async ( ) => {
106+ it ( "uses an unscoped current snapshot without falling back to a metadata scan" , ( ) => {
104107 getCurrentPluginMetadataSnapshotMock . mockReturnValue ( {
105108 plugins : [
106109 {
@@ -114,7 +117,6 @@ describe("configured model manifest workspace scope", () => {
114117 } ,
115118 ] ,
116119 } ) ;
117- const { buildConfiguredModelCatalog } = await import ( "./model-selection-shared.js" ) ;
118120 const cfg = {
119121 models : {
120122 providers : {
@@ -134,9 +136,8 @@ describe("configured model manifest workspace scope", () => {
134136 expect ( loadManifestMetadataSnapshotMock ) . not . toHaveBeenCalled ( ) ;
135137 } ) ;
136138
137- it ( "builds configured catalog facts once when resolving allowed models" , async ( ) => {
139+ it ( "builds configured catalog facts once when resolving allowed models" , ( ) => {
138140 getCurrentPluginMetadataSnapshotMock . mockReturnValue ( { plugins : [ ] } ) ;
139- const { buildAllowedModelSet } = await import ( "./model-selection-shared.js" ) ;
140141 const cfg = {
141142 models : {
142143 providers : {
@@ -156,10 +157,9 @@ describe("configured model manifest workspace scope", () => {
156157 expect ( loadManifestMetadataSnapshotMock ) . not . toHaveBeenCalled ( ) ;
157158 } ) ;
158159
159- it ( "does not load manifest metadata for empty configured model aliases" , async ( ) => {
160+ it ( "does not load manifest metadata for empty configured model aliases" , ( ) => {
160161 // Alias indexing is a hot config path. Empty inputs should avoid manifest
161162 // scans entirely.
162- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
163163 const cfg = { } as unknown as OpenClawConfig ;
164164
165165 const aliases = buildModelAliasIndex ( { cfg, defaultProvider : "anthropic" } ) ;
@@ -170,8 +170,7 @@ describe("configured model manifest workspace scope", () => {
170170 expect ( loadManifestMetadataSnapshotMock ) . not . toHaveBeenCalled ( ) ;
171171 } ) ;
172172
173- it ( "does not load manifest metadata for wildcard-only configured model aliases" , async ( ) => {
174- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
173+ it ( "does not load manifest metadata for wildcard-only configured model aliases" , ( ) => {
175174 const cfg = {
176175 agents : {
177176 defaults : {
@@ -190,8 +189,7 @@ describe("configured model manifest workspace scope", () => {
190189 expect ( loadManifestMetadataSnapshotMock ) . not . toHaveBeenCalled ( ) ;
191190 } ) ;
192191
193- it ( "does not load manifest metadata for configured model entries without aliases" , async ( ) => {
194- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
192+ it ( "does not load manifest metadata for configured model entries without aliases" , ( ) => {
195193 const cfg = {
196194 agents : {
197195 defaults : {
@@ -210,8 +208,7 @@ describe("configured model manifest workspace scope", () => {
210208 expect ( loadManifestMetadataSnapshotMock ) . not . toHaveBeenCalled ( ) ;
211209 } ) ;
212210
213- it ( "indexes selected-agent default-provider aliases without cold manifest discovery" , async ( ) => {
214- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
211+ it ( "indexes selected-agent default-provider aliases without cold manifest discovery" , ( ) => {
215212 const cfg = {
216213 agents : {
217214 ownership : "explicit" ,
@@ -237,8 +234,7 @@ describe("configured model manifest workspace scope", () => {
237234 expect ( normalizeProviderModelIdWithRuntimeMock . mock . calls . length ) . toBe ( 0 ) ;
238235 } ) ;
239236
240- it ( "resolves selected-agent default-provider aliases without cold manifest discovery" , async ( ) => {
241- const { resolveConfiguredModelRef } = await import ( "./model-selection-shared.js" ) ;
237+ it ( "resolves selected-agent default-provider aliases without cold manifest discovery" , ( ) => {
242238 const cfg = {
243239 agents : {
244240 ownership : "explicit" ,
@@ -266,7 +262,7 @@ describe("configured model manifest workspace scope", () => {
266262
267263 it . each ( [ "current" , "supplied" ] as const ) (
268264 "preserves %s prepared manifest policy for default-provider aliases" ,
269- async ( source ) => {
265+ ( source ) => {
270266 const manifestPlugins = [
271267 {
272268 modelIdNormalization : {
@@ -279,7 +275,6 @@ describe("configured model manifest workspace scope", () => {
279275 if ( source === "current" ) {
280276 getCurrentPluginMetadataSnapshotMock . mockReturnValue ( { plugins : manifestPlugins } ) ;
281277 }
282- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
283278 const cfg = {
284279 agents : { defaults : { models : { "openai/legacy" : { alias : "Legacy" } } } } ,
285280 } as unknown as OpenClawConfig ;
@@ -299,14 +294,13 @@ describe("configured model manifest workspace scope", () => {
299294 } ,
300295 ) ;
301296
302- it ( "preserves workspace manifest policy for default-provider aliases" , async ( ) => {
297+ it ( "preserves workspace manifest policy for default-provider aliases" , ( ) => {
303298 getActivePluginRegistryWorkspaceDirFromStateMock . mockReturnValue ( "/workspace/a" ) ;
304299 loadManifestMetadataSnapshotMock . mockReturnValue ( {
305300 plugins : [
306301 { modelIdNormalization : { providers : { openai : { aliases : { ops : "workspace-ops" } } } } } ,
307302 ] ,
308303 } ) ;
309- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
310304 const cfg = {
311305 agents : { defaults : { models : { "openai/ops" : { alias : "Operations" } } } } ,
312306 } as unknown as OpenClawConfig ;
@@ -318,8 +312,7 @@ describe("configured model manifest workspace scope", () => {
318312 expect ( loadManifestMetadataSnapshotMock . mock . calls [ 0 ] ?. [ 0 ] ?. workspaceDir ) . toBe ( "/workspace/a" ) ;
319313 } ) ;
320314
321- it ( "preserves provider-owned manifest discovery for non-default aliases" , async ( ) => {
322- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
315+ it ( "preserves provider-owned manifest discovery for non-default aliases" , ( ) => {
323316 const cfg = {
324317 agents : { defaults : { models : { "custom/ops" : { alias : "Operations" } } } } ,
325318 } as unknown as OpenClawConfig ;
@@ -346,7 +339,7 @@ describe("configured model manifest workspace scope", () => {
346339 [ "openai/legacy" , { alias : "Legacy" } ] ,
347340 ] ,
348341 } ,
349- ] ) ( "normalizes mixed aliases consistently with $name" , async ( { models } ) => {
342+ ] ) ( "normalizes mixed aliases consistently with $name" , ( { models } ) => {
350343 loadManifestMetadataSnapshotMock . mockReturnValue ( {
351344 plugins : [
352345 {
@@ -359,7 +352,6 @@ describe("configured model manifest workspace scope", () => {
359352 } ,
360353 ] ,
361354 } ) ;
362- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
363355 const cfg = {
364356 agents : { defaults : { models : Object . fromEntries ( models ) } } ,
365357 } as unknown as OpenClawConfig ;
@@ -377,8 +369,7 @@ describe("configured model manifest workspace scope", () => {
377369 expect ( loadManifestMetadataSnapshotMock ) . toHaveBeenCalledTimes ( 1 ) ;
378370 } ) ;
379371
380- it ( "preserves manifest discovery for default-provider configured API-owner mappings" , async ( ) => {
381- const { buildModelAliasIndex } = await import ( "./model-selection-shared.js" ) ;
372+ it ( "preserves manifest discovery for default-provider configured API-owner mappings" , ( ) => {
382373 const cfg = {
383374 agents : { defaults : { models : { "openai/ops" : { alias : "Operations" } } } } ,
384375 models : { providers : { openai : { api : "custom-owner" , models : [ ] } } } ,
@@ -390,8 +381,7 @@ describe("configured model manifest workspace scope", () => {
390381 expect ( loadManifestMetadataSnapshotMock . mock . calls . length ) . toBe ( 1 ) ;
391382 } ) ;
392383
393- it ( "does not load manifest metadata for statically resolved primary models" , async ( ) => {
394- const { resolveConfiguredModelRef } = await import ( "./model-selection-shared.js" ) ;
384+ it ( "does not load manifest metadata for statically resolved primary models" , ( ) => {
395385 const cases : Array < { cfg : OpenClawConfig ; expected : { provider : string ; model : string } } > = [
396386 {
397387 cfg : {
@@ -423,8 +413,7 @@ describe("configured model manifest workspace scope", () => {
423413 }
424414 } ) ;
425415
426- it ( "does not load manifest metadata for non-alias primary models with configured aliases" , async ( ) => {
427- const { resolveConfiguredModelRef } = await import ( "./model-selection-shared.js" ) ;
416+ it ( "does not load manifest metadata for non-alias primary models with configured aliases" , ( ) => {
428417 const cfg = {
429418 agents : {
430419 defaults : {
@@ -447,7 +436,7 @@ describe("configured model manifest workspace scope", () => {
447436 expect ( loadManifestMetadataSnapshotMock ) . not . toHaveBeenCalled ( ) ;
448437 } ) ;
449438
450- it ( "uses manifest-normalized configured refs to infer providers for bare defaults" , async ( ) => {
439+ it ( "uses manifest-normalized configured refs to infer providers for bare defaults" , ( ) => {
451440 loadManifestMetadataSnapshotMock . mockReturnValue ( {
452441 plugins : [
453442 {
@@ -463,7 +452,6 @@ describe("configured model manifest workspace scope", () => {
463452 } ,
464453 ] ,
465454 } ) ;
466- const { resolveConfiguredModelRef } = await import ( "./model-selection-shared.js" ) ;
467455 const cfg = {
468456 agents : {
469457 defaults : {
@@ -485,7 +473,7 @@ describe("configured model manifest workspace scope", () => {
485473 expect ( loadManifestMetadataSnapshotMock ) . toHaveBeenCalledTimes ( 1 ) ;
486474 } ) ;
487475
488- it ( "reuses resolved manifest plugins while resolving configured model aliases" , async ( ) => {
476+ it ( "reuses resolved manifest plugins while resolving configured model aliases" , ( ) => {
489477 loadManifestMetadataSnapshotMock . mockReturnValue ( {
490478 plugins : [
491479 {
@@ -504,7 +492,6 @@ describe("configured model manifest workspace scope", () => {
504492 } ,
505493 ] ,
506494 } ) ;
507- const { resolveConfiguredModelRef } = await import ( "./model-selection-shared.js" ) ;
508495 const cfg = {
509496 agents : {
510497 defaults : {
@@ -527,7 +514,7 @@ describe("configured model manifest workspace scope", () => {
527514 expect ( loadManifestMetadataSnapshotMock ) . toHaveBeenCalledTimes ( 1 ) ;
528515 } ) ;
529516
530- it ( "reuses resolved manifest plugins while resolving direct primary models" , async ( ) => {
517+ it ( "reuses resolved manifest plugins while resolving direct primary models" , ( ) => {
531518 loadManifestMetadataSnapshotMock . mockReturnValue ( {
532519 plugins : [
533520 {
@@ -546,7 +533,6 @@ describe("configured model manifest workspace scope", () => {
546533 } ,
547534 ] ,
548535 } ) ;
549- const { resolveConfiguredModelRef } = await import ( "./model-selection-shared.js" ) ;
550536 const cfg = {
551537 agents : {
552538 defaults : {
0 commit comments