merge_test.go RawHistoryFolder
1package provider
2
3import "testing"
4
5func TestMergeCatalogForProvidersPrunesUnavailableStaticModels(t *testing.T) {
6 const (
7 providerID = "openai-codex"
8 liveID = "gpt-5.6-luna"
9 absentID = "gpt-5.6-sol"
10 )
11
12 staticPresent := false
13 for _, model := range Catalog {
14 if model.Provider == providerID && model.ID == absentID {
15 staticPresent = true
16 break
17 }
18 }
19 if !staticPresent {
20 t.Fatalf("fixture drift: static model %s/%s is no longer in Catalog", providerID, absentID)
21 }
22
23 merged := MergeCatalogForProviders([]Model{{
24 Provider: providerID,
25 ID: liveID,
26 Source: "live",
27 }}, []string{providerID})
28
29 foundLive := false
30 for _, model := range merged {
31 if model.Provider != providerID {
32 continue
33 }
34 if model.ID == absentID {
35 t.Fatalf("unavailable static model %s/%s remains in authoritative catalog", providerID, absentID)
36 }
37 if model.ID == liveID {
38 foundLive = true
39 }
40 }
41 if !foundLive {
42 t.Fatalf("live model %s/%s missing from authoritative catalog", providerID, liveID)
43 }
44}
45
46func TestMergeCatalogForProvidersPreservesStaticMetadata(t *testing.T) {
47 merged := MergeCatalogForProviders([]Model{{
48 Provider: "openai-codex",
49 ID: "gpt-5.6-luna",
50 Source: "live",
51 }}, []string{"openai-codex"})
52 for _, model := range merged {
53 if model.Provider == "openai-codex" && model.ID == "gpt-5.6-luna" {
54 if model.ContextWindow == 0 || model.MaxOutput == 0 || model.PriceInput == 0 || model.PriceOutput == 0 {
55 t.Fatalf("live model did not retain static metadata: %+v", model)
56 }
57 return
58 }
59 }
60 t.Fatal("live Codex model missing from merged catalog")
61}
62
63func TestSetLiveModelsForProvidersPrunesEmptyAuthoritativeCatalog(t *testing.T) {
64 if _, err := FindModel("openai-codex", "gpt-5.6-luna"); err != nil {
65 t.Fatalf("fixture drift: static Codex model missing: %v", err)
66 }
67 preserveActiveCatalog(t)
68
69 SetLiveModelsForProviders(nil, []string{"openai-codex"})
70 if _, err := FindModel("openai-codex", "gpt-5.6-luna"); err == nil {
71 t.Fatal("empty authoritative catalog retained a static Codex model")
72 }
73}
74
75func TestAcceptsUnlistedModelsStopsAfterAuthoritativeDiscovery(t *testing.T) {
76 preserveActiveCatalog(t)
77
78 SetLiveModels([]Model{{Provider: ProviderOpenCodeGo, ID: "bootstrap"}})
79 if !AcceptsUnlistedModels(ProviderOpenCodeGo) {
80 t.Fatal("non-authoritative OpenCode Go overlay rejected unlisted models")
81 }
82 SetLiveModelsForProviders([]Model{{Provider: ProviderOpenCodeGo, ID: "served"}}, []string{ProviderOpenCodeGo})
83 if AcceptsUnlistedModels(ProviderOpenCodeGo) {
84 t.Fatal("authoritative OpenCode Go catalog accepted an unlisted model")
85 }
86}