@@ -3,9 +3,10 @@ import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
33import { tmpdir } from "node:os" ;
44import { join } from "node:path" ;
55
6- import { buildBifrostSource , buildOpenAISource , buildProviderCatalog , KEYLESS_API_KEY , loadConfig , providerCatalogToSettings , runtimeSettingsWithCatalog , SOURCE_MAX_TOKENS } from "./config/index.js" ;
6+ import { buildBifrostSource , buildOpenAISource , buildProviderCatalog , catalogEntryAsProviderSettings , KEYLESS_API_KEY , loadConfig , providerCatalogToSettings , runtimeSettingsWithCatalog , SOURCE_MAX_TOKENS } from "./config/index.js" ;
77import type { Config , UnconfiguredConfig } from "./config/index.js" ;
88import { mergeProviderIntoSettings , type ResolvedProvider , type Settings } from "./config/settings.js" ;
9+ import { OPENCODE_GO_BASE_URL } from "../packages/opencode-go/src/index.js" ;
910
1011function assertConfigured ( config : Config | UnconfiguredConfig ) : asserts config is Config {
1112 if ( config . configured === false ) {
@@ -648,6 +649,74 @@ describe("buildProviderCatalog", () => {
648649 } ) ;
649650 expect ( restOut ) . toEqual ( restExisting ) ;
650651 } ) ;
652+
653+ test ( "round-trips every ProviderSettings field a catalog entry can carry through buildProviderCatalog and back" , ( ) => {
654+ // ProviderCatalogEntry is defined as Omit<ProviderSettings, "name" | "contextWindow">.
655+ // This exercises every field that relationship carries over, so a field
656+ // added to ProviderSettings and forgotten in the two conversion sites
657+ // below fails here instead of being silently dropped at runtime.
658+ // `anthropic` and `opencodeGo` are exercised separately below: both are
659+ // protocol markers that also normalize `baseURL` in buildProviderCatalog,
660+ // so a provider combining them with an arbitrary baseURL isn't a real
661+ // round trip (the healing logic rewrites baseURL by design).
662+ const provider : Settings [ "providers" ] [ string ] = {
663+ baseURL : "https://fp/v1" ,
664+ apiKey : "fp-key" ,
665+ models : [ "fp-large" ] ,
666+ defaultModel : "fp-large" ,
667+ free : true ,
668+ keyless : true ,
669+ bifrostVirtualKey : true ,
670+ } ;
671+ const settings : Settings = { providers : { fp : provider } } ;
672+ const catalog = buildProviderCatalog ( settings , {
673+ providerName : "fp" ,
674+ baseURL : provider . baseURL ,
675+ apiKey : "fp-key" ,
676+ model : "fp-large" ,
677+ } as ResolvedProvider ) ;
678+ const entry = catalog . find ( ( c ) => c . name === "fp" ) ! ;
679+ const roundTripped = { fp : catalogEntryAsProviderSettings ( entry ) } ;
680+ expect ( roundTripped ) . toEqual ( { fp : provider } ) ;
681+ } ) ;
682+
683+ test ( "round-trips the anthropic protocol marker" , ( ) => {
684+ const provider : Settings [ "providers" ] [ string ] = {
685+ baseURL : "https://api.anthropic.com/v1" ,
686+ apiKey : "an-key" ,
687+ models : [ "claude" ] ,
688+ anthropic : true ,
689+ } ;
690+ const settings : Settings = { providers : { an : provider } } ;
691+ const catalog = buildProviderCatalog ( settings , {
692+ providerName : "an" ,
693+ baseURL : provider . baseURL ,
694+ apiKey : "an-key" ,
695+ model : "claude" ,
696+ } as ResolvedProvider ) ;
697+ const entry = catalog . find ( ( c ) => c . name === "an" ) ! ;
698+ const roundTripped = { an : catalogEntryAsProviderSettings ( entry ) } ;
699+ expect ( roundTripped ) . toEqual ( { an : provider } ) ;
700+ } ) ;
701+
702+ test ( "round-trips the opencodeGo protocol marker" , ( ) => {
703+ const provider : Settings [ "providers" ] [ string ] = {
704+ baseURL : OPENCODE_GO_BASE_URL ,
705+ apiKey : "go-key" ,
706+ models : [ "go-model" ] ,
707+ opencodeGo : true ,
708+ } ;
709+ const settings : Settings = { providers : { go : provider } } ;
710+ const catalog = buildProviderCatalog ( settings , {
711+ providerName : "go" ,
712+ baseURL : provider . baseURL ,
713+ apiKey : "go-key" ,
714+ model : "go-model" ,
715+ } as ResolvedProvider ) ;
716+ const entry = catalog . find ( ( c ) => c . name === "go" ) ! ;
717+ const roundTripped = { go : catalogEntryAsProviderSettings ( entry ) } ;
718+ expect ( roundTripped ) . toEqual ( { go : provider } ) ;
719+ } ) ;
651720} ) ;
652721
653722describe ( "mergeProviderIntoSettings" , ( ) => {
0 commit comments