@@ -37,6 +37,179 @@ describe("huggingface models", () => {
3737 const models = await discoverHuggingfaceModels ( "" ) ;
3838 expect ( models ) . toHaveLength ( HUGGINGFACE_MODEL_CATALOG . length ) ;
3939 expect ( models . map ( ( m ) => m . id ) ) . toEqual ( HUGGINGFACE_MODEL_CATALOG . map ( ( m ) => m . id ) ) ;
40+ expect ( models [ 0 ] ?. contextWindow ) . toBe ( 131072 ) ;
41+ expect ( models [ 0 ] ?. compat ) . toBeUndefined ( ) ;
42+ } ) ;
43+
44+ it ( "uses the live route context for bundled models while preserving their catalog metadata" , async ( ) => {
45+ const bundledModel = HUGGINGFACE_MODEL_CATALOG [ 0 ] ! ;
46+ vi . stubGlobal (
47+ "fetch" ,
48+ vi . fn ( async ( ) =>
49+ Response . json ( {
50+ data : [
51+ {
52+ id : bundledModel . id ,
53+ name : "Upstream name must not replace bundled metadata" ,
54+ architecture : { input_modalities : [ "text" , "image" ] } ,
55+ providers : [ { context_length : 64000 , supports_tools : true } ] ,
56+ } ,
57+ ] ,
58+ } ) ,
59+ ) ,
60+ ) ;
61+
62+ const models = await discoverHuggingfaceModels ( "hf_test_token" ) ;
63+
64+ expect ( models ) . toEqual ( [ { ...bundledModel , contextWindow : 64000 } ] ) ;
65+ } ) ;
66+
67+ it ( "limits discovered models to every available route regardless of provider order" , async ( ) => {
68+ const bundledModel = HUGGINGFACE_MODEL_CATALOG [ 0 ] ! ;
69+ vi . stubGlobal (
70+ "fetch" ,
71+ vi . fn ( async ( ) =>
72+ Response . json ( {
73+ data : [
74+ {
75+ id : "Qwen/Qwen3.8-2.4T-A95B" ,
76+ providers : [ { context_length : 1010000 } , { context_length : 262144 } ] ,
77+ } ,
78+ {
79+ id : "test/reversed-provider-order" ,
80+ providers : [ { context_length : 262144 } , { context_length : 1010000 } ] ,
81+ } ,
82+ {
83+ id : bundledModel . id ,
84+ providers : [
85+ { status : "error" , context_length : 16000 } ,
86+ { context_length : 96000 } ,
87+ { context_length : 0 } ,
88+ { context_length : 64000 } ,
89+ ] ,
90+ } ,
91+ ] ,
92+ } ) ,
93+ ) ,
94+ ) ;
95+
96+ const models = await discoverHuggingfaceModels ( "hf_test_token" ) ;
97+
98+ expect ( models . map ( ( { id, contextWindow } ) => ( { id, contextWindow } ) ) ) . toEqual ( [
99+ { id : "Qwen/Qwen3.8-2.4T-A95B" , contextWindow : 262144 } ,
100+ { id : "test/reversed-provider-order" , contextWindow : 262144 } ,
101+ { id : bundledModel . id , contextWindow : 64000 } ,
102+ ] ) ;
103+ } ) ;
104+
105+ it ( "disables tools whenever an available route explicitly rejects them" , async ( ) => {
106+ vi . stubGlobal (
107+ "fetch" ,
108+ vi . fn ( async ( ) =>
109+ Response . json ( {
110+ data : [
111+ {
112+ id : "test/no-tools-vision" ,
113+ architecture : { input_modalities : [ "text" , "image" ] } ,
114+ providers : [
115+ { context_length : 96000 , supports_tools : false } ,
116+ { context_length : 64000 , supports_tools : false } ,
117+ ] ,
118+ } ,
119+ {
120+ id : "test/mixed-routes" ,
121+ providers : [ { supports_tools : false } , { supports_tools : true } ] ,
122+ } ,
123+ {
124+ id : "test/reversed-mixed-routes" ,
125+ providers : [ { supports_tools : true } , { supports_tools : false } ] ,
126+ } ,
127+ {
128+ id : "test/unknown-route" ,
129+ providers : [ { supports_tools : false } , { context_length : 48000 } ] ,
130+ } ,
131+ {
132+ id : "test/errored-route" ,
133+ providers : [
134+ { status : "error" , context_length : 262144 , supports_tools : true } ,
135+ { status : "live" , context_length : 32000 , supports_tools : false } ,
136+ ] ,
137+ } ,
138+ {
139+ id : "test/errored-unsupported-route" ,
140+ providers : [
141+ { status : "error" , supports_tools : false } ,
142+ { status : "live" , supports_tools : true } ,
143+ ] ,
144+ } ,
145+ { id : "test/no-routes" } ,
146+ { id : "test/unknown-only" , providers : [ { } ] } ,
147+ { id : "test/tools" , providers : [ { supports_tools : true } ] } ,
148+ ] ,
149+ } ) ,
150+ ) ,
151+ ) ;
152+
153+ const models = await discoverHuggingfaceModels ( "hf_test_token" ) ;
154+
155+ expect (
156+ models . map ( ( { id, input, contextWindow, compat } ) => ( { id, input, contextWindow, compat } ) ) ,
157+ ) . toEqual ( [
158+ {
159+ id : "test/no-tools-vision" ,
160+ input : [ "text" , "image" ] ,
161+ contextWindow : 64000 ,
162+ compat : { supportsTools : false } ,
163+ } ,
164+ {
165+ id : "test/mixed-routes" ,
166+ input : [ "text" ] ,
167+ contextWindow : 131072 ,
168+ compat : { supportsTools : false } ,
169+ } ,
170+ {
171+ id : "test/reversed-mixed-routes" ,
172+ input : [ "text" ] ,
173+ contextWindow : 131072 ,
174+ compat : { supportsTools : false } ,
175+ } ,
176+ {
177+ id : "test/unknown-route" ,
178+ input : [ "text" ] ,
179+ contextWindow : 48000 ,
180+ compat : { supportsTools : false } ,
181+ } ,
182+ {
183+ id : "test/errored-route" ,
184+ input : [ "text" ] ,
185+ contextWindow : 32000 ,
186+ compat : { supportsTools : false } ,
187+ } ,
188+ {
189+ id : "test/errored-unsupported-route" ,
190+ input : [ "text" ] ,
191+ contextWindow : 131072 ,
192+ compat : undefined ,
193+ } ,
194+ {
195+ id : "test/no-routes" ,
196+ input : [ "text" ] ,
197+ contextWindow : 131072 ,
198+ compat : undefined ,
199+ } ,
200+ {
201+ id : "test/unknown-only" ,
202+ input : [ "text" ] ,
203+ contextWindow : 131072 ,
204+ compat : undefined ,
205+ } ,
206+ {
207+ id : "test/tools" ,
208+ input : [ "text" ] ,
209+ contextWindow : 131072 ,
210+ compat : undefined ,
211+ } ,
212+ ] ) ;
40213 } ) ;
41214
42215 it ( "uses the default discovery timeout for live Hugging Face fetches" , async ( ) => {
0 commit comments