mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-04-26 14:55:16 +00:00
fix(antigravity): deep copy cached model metadata
This commit is contained in:
@@ -71,8 +71,7 @@ func cloneAntigravityModels(models []*registry.ModelInfo) []*registry.ModelInfo
|
|||||||
if model == nil || strings.TrimSpace(model.ID) == "" {
|
if model == nil || strings.TrimSpace(model.ID) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
clone := *model
|
out = append(out, cloneAntigravityModelInfo(model))
|
||||||
out = append(out, &clone)
|
|
||||||
}
|
}
|
||||||
if len(out) == 0 {
|
if len(out) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@@ -80,6 +79,27 @@ func cloneAntigravityModels(models []*registry.ModelInfo) []*registry.ModelInfo
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cloneAntigravityModelInfo(model *registry.ModelInfo) *registry.ModelInfo {
|
||||||
|
if model == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
clone := *model
|
||||||
|
if len(model.SupportedGenerationMethods) > 0 {
|
||||||
|
clone.SupportedGenerationMethods = append([]string(nil), model.SupportedGenerationMethods...)
|
||||||
|
}
|
||||||
|
if len(model.SupportedParameters) > 0 {
|
||||||
|
clone.SupportedParameters = append([]string(nil), model.SupportedParameters...)
|
||||||
|
}
|
||||||
|
if model.Thinking != nil {
|
||||||
|
thinkingClone := *model.Thinking
|
||||||
|
if len(model.Thinking.Levels) > 0 {
|
||||||
|
thinkingClone.Levels = append([]string(nil), model.Thinking.Levels...)
|
||||||
|
}
|
||||||
|
clone.Thinking = &thinkingClone
|
||||||
|
}
|
||||||
|
return &clone
|
||||||
|
}
|
||||||
|
|
||||||
func storeAntigravityPrimaryModels(models []*registry.ModelInfo) bool {
|
func storeAntigravityPrimaryModels(models []*registry.ModelInfo) bool {
|
||||||
cloned := cloneAntigravityModels(models)
|
cloned := cloneAntigravityModels(models)
|
||||||
if len(cloned) == 0 {
|
if len(cloned) == 0 {
|
||||||
|
|||||||
@@ -44,7 +44,15 @@ func TestLoadAntigravityPrimaryModels_ReturnsClone(t *testing.T) {
|
|||||||
resetAntigravityPrimaryModelsCacheForTest()
|
resetAntigravityPrimaryModelsCacheForTest()
|
||||||
t.Cleanup(resetAntigravityPrimaryModelsCacheForTest)
|
t.Cleanup(resetAntigravityPrimaryModelsCacheForTest)
|
||||||
|
|
||||||
if updated := storeAntigravityPrimaryModels([]*registry.ModelInfo{{ID: "gpt-5", DisplayName: "GPT-5"}}); !updated {
|
if updated := storeAntigravityPrimaryModels([]*registry.ModelInfo{{
|
||||||
|
ID: "gpt-5",
|
||||||
|
DisplayName: "GPT-5",
|
||||||
|
SupportedGenerationMethods: []string{"generateContent"},
|
||||||
|
SupportedParameters: []string{"temperature"},
|
||||||
|
Thinking: ®istry.ThinkingSupport{
|
||||||
|
Levels: []string{"high"},
|
||||||
|
},
|
||||||
|
}}); !updated {
|
||||||
t.Fatal("expected model cache update")
|
t.Fatal("expected model cache update")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +61,15 @@ func TestLoadAntigravityPrimaryModels_ReturnsClone(t *testing.T) {
|
|||||||
t.Fatalf("expected one cached model, got %d", len(got))
|
t.Fatalf("expected one cached model, got %d", len(got))
|
||||||
}
|
}
|
||||||
got[0].ID = "mutated-id"
|
got[0].ID = "mutated-id"
|
||||||
|
if len(got[0].SupportedGenerationMethods) > 0 {
|
||||||
|
got[0].SupportedGenerationMethods[0] = "mutated-method"
|
||||||
|
}
|
||||||
|
if len(got[0].SupportedParameters) > 0 {
|
||||||
|
got[0].SupportedParameters[0] = "mutated-parameter"
|
||||||
|
}
|
||||||
|
if got[0].Thinking != nil && len(got[0].Thinking.Levels) > 0 {
|
||||||
|
got[0].Thinking.Levels[0] = "mutated-level"
|
||||||
|
}
|
||||||
|
|
||||||
again := loadAntigravityPrimaryModels()
|
again := loadAntigravityPrimaryModels()
|
||||||
if len(again) != 1 {
|
if len(again) != 1 {
|
||||||
@@ -61,4 +78,13 @@ func TestLoadAntigravityPrimaryModels_ReturnsClone(t *testing.T) {
|
|||||||
if again[0].ID != "gpt-5" {
|
if again[0].ID != "gpt-5" {
|
||||||
t.Fatalf("expected cached model id to remain %q, got %q", "gpt-5", again[0].ID)
|
t.Fatalf("expected cached model id to remain %q, got %q", "gpt-5", again[0].ID)
|
||||||
}
|
}
|
||||||
|
if len(again[0].SupportedGenerationMethods) == 0 || again[0].SupportedGenerationMethods[0] != "generateContent" {
|
||||||
|
t.Fatalf("expected cached generation methods to be unmutated, got %v", again[0].SupportedGenerationMethods)
|
||||||
|
}
|
||||||
|
if len(again[0].SupportedParameters) == 0 || again[0].SupportedParameters[0] != "temperature" {
|
||||||
|
t.Fatalf("expected cached supported parameters to be unmutated, got %v", again[0].SupportedParameters)
|
||||||
|
}
|
||||||
|
if again[0].Thinking == nil || len(again[0].Thinking.Levels) == 0 || again[0].Thinking.Levels[0] != "high" {
|
||||||
|
t.Fatalf("expected cached model thinking levels to be unmutated, got %v", again[0].Thinking)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user