@@ -30,18 +30,18 @@ describe("openrouter provider hooks", () => {
3030 kind : "video_generation" ,
3131 } ) ;
3232
33- expect ( providers ) . toEqual ( [ expect . objectContaining ( { id : "openrouter" } ) ] ) ;
34- expect ( speechProviders ) . toEqual ( [ expect . objectContaining ( { id : "openrouter" } ) ] ) ;
35- expect ( mediaProviders ) . toEqual ( [ expect . objectContaining ( { id : "openrouter" } ) ] ) ;
36- expect ( imageProviders ) . toEqual ( [ expect . objectContaining ( { id : "openrouter" } ) ] ) ;
37- expect ( videoProviders ) . toEqual ( [ expect . objectContaining ( { id : "openrouter" } ) ] ) ;
38- expect ( modelCatalogProvider . liveCatalog ) . toEqual ( expect . any ( Function ) ) ;
33+ expect ( providers . map ( ( provider ) => provider . id ) ) . toEqual ( [ "openrouter" ] ) ;
34+ expect ( speechProviders . map ( ( provider ) => provider . id ) ) . toEqual ( [ "openrouter" ] ) ;
35+ expect ( mediaProviders . map ( ( provider ) => provider . id ) ) . toEqual ( [ "openrouter" ] ) ;
36+ expect ( imageProviders . map ( ( provider ) => provider . id ) ) . toEqual ( [ "openrouter" ] ) ;
37+ expect ( videoProviders . map ( ( provider ) => provider . id ) ) . toEqual ( [ "openrouter" ] ) ;
38+ expect ( modelCatalogProvider . liveCatalog ) . toBeTypeOf ( "function" ) ;
3939 } ) ;
4040
4141 it ( "includes current Kimi models in the bundled catalog" , ( ) => {
42- expect ( buildOpenrouterProvider ( ) . models ?. map ( ( model ) => model . id ) ) . toEqual (
43- expect . arrayContaining ( [ "moonshotai/kimi-k2.6" , "moonshotai/kimi-k2.5" ] ) ,
44- ) ;
42+ const modelIds = buildOpenrouterProvider ( ) . models ?. map ( ( model ) => model . id ) ?? [ ] ;
43+ expect ( modelIds ) . toContain ( "moonshotai/kimi-k2.6" ) ;
44+ expect ( modelIds ) . toContain ( "moonshotai/kimi-k2.5" ) ;
4545 } ) ;
4646
4747 it ( "uses the canonical prefixed OpenRouter auto model id" , ( ) => {
@@ -50,9 +50,9 @@ describe("openrouter provider hooks", () => {
5050 } ) ;
5151
5252 it ( "does not include retired stealth models in the bundled catalog" , ( ) => {
53- expect ( buildOpenrouterProvider ( ) . models ?. map ( ( model ) => model . id ) ) . not . toEqual (
54- expect . arrayContaining ( [ "openrouter/hunter-alpha" , "openrouter/healer-alpha" ] ) ,
55- ) ;
53+ const modelIds = buildOpenrouterProvider ( ) . models ?. map ( ( model ) => model . id ) ?? [ ] ;
54+ expect ( modelIds ) . not . toContain ( "openrouter/hunter-alpha" ) ;
55+ expect ( modelIds ) . not . toContain ( "openrouter/healer-alpha" ) ;
5656 } ) ;
5757
5858 it ( "keeps stale Hunter Alpha configs out of OpenRouter proxy reasoning" , ( ) => {
@@ -137,58 +137,49 @@ describe("openrouter provider hooks", () => {
137137 it ( "canonicalizes stale OpenRouter /v1 config and runtime metadata" , async ( ) => {
138138 const provider = await registerSingleProviderPlugin ( openrouterPlugin ) ;
139139
140- expect (
141- provider . normalizeConfig ?.( {
142- provider : "openrouter" ,
143- providerConfig : {
144- api : "openai-completions" ,
145- baseUrl : "https://openrouter.ai/v1/" ,
146- models : [ ] ,
147- } ,
148- } as never ) ,
149- ) . toMatchObject ( {
150- baseUrl : "https://openrouter.ai/api/v1" ,
151- } ) ;
140+ const normalizedConfig = provider . normalizeConfig ?.( {
141+ provider : "openrouter" ,
142+ providerConfig : {
143+ api : "openai-completions" ,
144+ baseUrl : "https://openrouter.ai/v1/" ,
145+ models : [ ] ,
146+ } ,
147+ } as never ) ;
148+ expect ( normalizedConfig ?. baseUrl ) . toBe ( "https://openrouter.ai/api/v1" ) ;
152149
153- expect (
154- provider . normalizeResolvedModel ?.( {
150+ const normalizedGptModel = provider . normalizeResolvedModel ?.( {
151+ provider : "openrouter" ,
152+ model : {
155153 provider : "openrouter" ,
156- model : {
157- provider : "openrouter" ,
158- id : "openai/gpt-5.4" ,
159- name : "openai/gpt-5.4" ,
160- api : "openai-completions" ,
161- baseUrl : "https://openrouter.ai/v1" ,
162- reasoning : true ,
163- input : [ "text" , "image" ] ,
164- cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 } ,
165- contextWindow : 200_000 ,
166- maxTokens : 8192 ,
167- } ,
168- } as never ) ,
169- ) . toMatchObject ( {
170- baseUrl : "https://openrouter.ai/api/v1" ,
171- } ) ;
154+ id : "openai/gpt-5.4" ,
155+ name : "openai/gpt-5.4" ,
156+ api : "openai-completions" ,
157+ baseUrl : "https://openrouter.ai/v1" ,
158+ reasoning : true ,
159+ input : [ "text" , "image" ] ,
160+ cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 } ,
161+ contextWindow : 200_000 ,
162+ maxTokens : 8192 ,
163+ } ,
164+ } as never ) ;
165+ expect ( normalizedGptModel ?. baseUrl ) . toBe ( "https://openrouter.ai/api/v1" ) ;
172166
173- expect (
174- provider . normalizeResolvedModel ?.( {
167+ const normalizedHunterModel = provider . normalizeResolvedModel ?.( {
168+ provider : "openrouter" ,
169+ model : {
175170 provider : "openrouter" ,
176- model : {
177- provider : "openrouter" ,
178- id : "openrouter/hunter-alpha" ,
179- name : "Hunter Alpha" ,
180- api : "openai-completions" ,
181- baseUrl : "https://openrouter.ai/api/v1" ,
182- reasoning : true ,
183- input : [ "text" ] ,
184- cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 } ,
185- contextWindow : 1_048_576 ,
186- maxTokens : 65_536 ,
187- } ,
188- } as never ) ,
189- ) . toMatchObject ( {
190- reasoning : false ,
191- } ) ;
171+ id : "openrouter/hunter-alpha" ,
172+ name : "Hunter Alpha" ,
173+ api : "openai-completions" ,
174+ baseUrl : "https://openrouter.ai/api/v1" ,
175+ reasoning : true ,
176+ input : [ "text" ] ,
177+ cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 } ,
178+ contextWindow : 1_048_576 ,
179+ maxTokens : 65_536 ,
180+ } ,
181+ } as never ) ;
182+ expect ( normalizedHunterModel ?. reasoning ) . toBe ( false ) ;
192183
193184 expect (
194185 provider . normalizeTransport ?.( {
@@ -235,13 +226,8 @@ describe("openrouter provider hooks", () => {
235226 expect ( baseStreamFn ) . toHaveBeenCalledOnce ( ) ;
236227 const firstCall = baseStreamFn . mock . calls [ 0 ] ;
237228 const firstModel = firstCall ?. [ 0 ] ;
238- expect ( firstModel ) . toMatchObject ( {
239- compat : {
240- openRouterRouting : {
241- order : [ "moonshot" ] ,
242- } ,
243- } ,
244- } ) ;
229+ const compat = ( firstModel as { compat ?: { openRouterRouting ?: { order ?: unknown } } } ) . compat ;
230+ expect ( compat ?. openRouterRouting ?. order ) . toEqual ( [ "moonshot" ] ) ;
245231 } ) ;
246232
247233 it ( "does not inject OpenRouter reasoning for Hunter Alpha" , async ( ) => {
@@ -323,20 +309,18 @@ describe("openrouter provider hooks", () => {
323309 { } ,
324310 ) ;
325311
326- expect ( capturedPayload ) . toMatchObject ( {
327- thinking : { type : "enabled" } ,
328- reasoning_effort : "xhigh" ,
329- messages : [
330- { role : "user" , content : "read file" } ,
331- {
332- role : "assistant" ,
333- tool_calls : [ { id : "call_1" , type : "function" } ] ,
334- reasoning_content : "" ,
335- } ,
336- { role : "tool" , content : "ok" } ,
337- { role : "assistant" , content : "done" , reasoning_content : "" } ,
338- ] ,
339- } ) ;
312+ expect ( capturedPayload ?. thinking ) . toEqual ( { type : "enabled" } ) ;
313+ expect ( capturedPayload ?. reasoning_effort ) . toBe ( "xhigh" ) ;
314+ expect ( capturedPayload ?. messages ) . toEqual ( [
315+ { role : "user" , content : "read file" } ,
316+ {
317+ role : "assistant" ,
318+ tool_calls : [ { id : "call_1" , type : "function" } ] ,
319+ reasoning_content : "" ,
320+ } ,
321+ { role : "tool" , content : "ok" } ,
322+ { role : "assistant" , content : "done" , reasoning_content : "" } ,
323+ ] ) ;
340324 expect ( baseStreamFn ) . toHaveBeenCalledOnce ( ) ;
341325 } ) ;
342326
@@ -486,10 +470,8 @@ describe("openrouter provider hooks", () => {
486470 { } ,
487471 ) ;
488472
489- expect ( capturedPayload ) . toMatchObject ( {
490- messages : [ { role : "user" , content : "Return JSON." } ] ,
491- reasoning : { effort : "high" } ,
492- } ) ;
473+ expect ( capturedPayload ?. messages ) . toEqual ( [ { role : "user" , content : "Return JSON." } ] ) ;
474+ expect ( capturedPayload ?. reasoning ) . toEqual ( { effort : "high" } ) ;
493475 expect ( baseStreamFn ) . toHaveBeenCalledOnce ( ) ;
494476 } ) ;
495477
@@ -552,6 +534,6 @@ describe("openrouter provider hooks", () => {
552534 expect ( payloads [ 0 ] ?. messages ) . toHaveLength ( 2 ) ;
553535 expect ( payloads [ 0 ] ) . not . toHaveProperty ( "reasoning" ) ;
554536 expect ( payloads [ 1 ] ?. messages ) . toHaveLength ( 2 ) ;
555- expect ( payloads [ 1 ] ) . toMatchObject ( { reasoning : { effort : "high" } } ) ;
537+ expect ( payloads [ 1 ] ?. reasoning ) . toEqual ( { effort : "high" } ) ;
556538 } ) ;
557539} ) ;
0 commit comments