@@ -13,7 +13,11 @@ vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({
1313 } ) ,
1414} ) ) ;
1515
16- import { discoverKilocodeModels , KILOCODE_MODELS_URL } from "./provider-models.js" ;
16+ import {
17+ discoverKilocodeModels ,
18+ KILOCODE_DEFAULT_COST ,
19+ KILOCODE_MODELS_URL ,
20+ } from "./provider-models.js" ;
1721
1822type MockKilocodeFetch = ( ( url : string , init ?: RequestInit ) => Promise < Response > ) & {
1923 mock : { calls : unknown [ ] [ ] } ;
@@ -188,6 +192,69 @@ describe("discoverKilocodeModels (fetch path)", () => {
188192 } ) ;
189193 } ) ;
190194
195+ it . each ( [
196+ {
197+ label : "negative routing rates with missing cache prices" ,
198+ pricing : { prompt : "-1" , completion : "-1" } ,
199+ cacheRead : 0 ,
200+ cacheWrite : 0 ,
201+ } ,
202+ {
203+ label : "unknown routing rates with valid cache prices" ,
204+ pricing : {
205+ prompt : "unavailable" ,
206+ completion : "-1" ,
207+ input_cache_read : "0.0000003" ,
208+ input_cache_write : "0.00000375" ,
209+ } ,
210+ cacheRead : 0.3 ,
211+ cacheWrite : 3.75 ,
212+ } ,
213+ ] ) (
214+ "preserves known default-model pricing for $label" ,
215+ async ( { pricing, cacheRead, cacheWrite } ) => {
216+ const mockFetch = vi . fn ( ) . mockResolvedValue (
217+ jsonResponse ( {
218+ data : [
219+ makeAutoModel ( { pricing } ) ,
220+ makeGatewayModel ( {
221+ id : "kilo-auto/frontier" ,
222+ pricing : { prompt : "-1" , completion : "-1" } ,
223+ } ) ,
224+ makeGatewayModel ( {
225+ id : "kilo-auto/free" ,
226+ pricing : {
227+ prompt : "0" ,
228+ completion : "0" ,
229+ input_cache_read : "0" ,
230+ input_cache_write : "0" ,
231+ } ,
232+ } ) ,
233+ ] ,
234+ } ) ,
235+ ) ;
236+
237+ await withFetchPathTest ( mockFetch , async ( ) => {
238+ const models = await discoverKilocodeModels ( ) ;
239+
240+ expect ( requireModelById ( models , "kilo-auto/balanced" ) . cost ) . toEqual ( {
241+ input : KILOCODE_DEFAULT_COST . input ,
242+ output : KILOCODE_DEFAULT_COST . output ,
243+ cacheRead,
244+ cacheWrite,
245+ } ) ;
246+ for ( const id of [ "kilo-auto/frontier" , "kilo-auto/free" ] ) {
247+ expect ( requireModelById ( models , id ) . cost ) . toEqual ( {
248+ input : 0 ,
249+ output : 0 ,
250+ cacheRead : 0 ,
251+ cacheWrite : 0 ,
252+ } ) ;
253+ }
254+ } ) ;
255+ } ,
256+ ) ;
257+
191258 it ( "falls back to static catalog on network error" , async ( ) => {
192259 const mockFetch = vi . fn ( ) . mockRejectedValue ( new Error ( "network error" ) ) ;
193260 await withFetchPathTest ( mockFetch , async ( ) => {
0 commit comments