1- import { describe , expect , it , vi } from "vitest" ;
1+ import { afterEach , describe , expect , it , vi } from "vitest" ;
22import type { OpenClawConfig } from "../config/types.openclaw.js" ;
33import { loadModelCatalogForBrowse } from "./model-catalog-browse.js" ;
44import type { ModelCatalogEntry } from "./model-catalog.types.js" ;
@@ -23,6 +23,10 @@ function config(params: { providerWildcard?: boolean } = {}): OpenClawConfig {
2323}
2424
2525describe ( "loadModelCatalogForBrowse" , ( ) => {
26+ afterEach ( ( ) => {
27+ vi . useRealTimers ( ) ;
28+ } ) ;
29+
2630 it ( "uses the read-only catalog for default browse views" , async ( ) => {
2731 const loadCatalog = vi . fn ( async ( { readOnly } : { readOnly : boolean } ) =>
2832 readOnly ? readOnlyCatalog : fullCatalog ,
@@ -79,4 +83,27 @@ describe("loadModelCatalogForBrowse", () => {
7983 expect ( onTimeout ) . toHaveBeenCalledExactlyOnceWith ( 5 ) ;
8084 await new Promise ( ( resolve ) => setTimeout ( resolve , 15 ) ) ;
8185 } ) ;
86+
87+ it ( "uses the default timeout when timeoutMs is non-finite" , async ( ) => {
88+ vi . useFakeTimers ( ) ;
89+ const onTimeout = vi . fn ( ) ;
90+ const loadCatalog = vi . fn (
91+ ( ) =>
92+ new Promise < ModelCatalogEntry [ ] > ( ( resolve ) => {
93+ setTimeout ( ( ) => resolve ( readOnlyCatalog ) , 5 ) ;
94+ } ) ,
95+ ) ;
96+
97+ const resultPromise = loadModelCatalogForBrowse ( {
98+ cfg : config ( ) ,
99+ loadCatalog,
100+ timeoutMs : Number . NaN ,
101+ onTimeout,
102+ } ) ;
103+
104+ await vi . advanceTimersByTimeAsync ( 5 ) ;
105+
106+ await expect ( resultPromise ) . resolves . toBe ( readOnlyCatalog ) ;
107+ expect ( onTimeout ) . not . toHaveBeenCalled ( ) ;
108+ } ) ;
82109} ) ;
0 commit comments