fix(codex): isolate API-key catalog cache and DeepSeek Codex defaults

Copy cached API-key manifests before group-specific mutation, use DeepSeek
model IDs for Codex fallbacks, omit unsupported config.toml effort, and
drop wildcard mapping keys from generated catalogs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Long Li
2026-08-26 10:56:17 +09:00
co-authored by Cursor
parent 77b6c5bb0c
commit 195b219707
9 changed files with 491 additions and 28 deletions
@@ -774,6 +774,89 @@ func TestDefaultModelIDsForPlatform_CNProvidersKeepClaudeDefaults(t *testing.T)
}
}
func TestDefaultCodexModelIDsForPlatform_DeepSeekUsesDeepSeekModels(t *testing.T) {
require.Equal(t, []string{"deepseek-v4-pro", "deepseek-v4-flash"}, defaultCodexModelIDsForPlatform(service.PlatformDeepseek))
require.Equal(t, defaultModelIDsForPlatform(service.PlatformAnthropic), defaultCodexModelIDsForPlatform(service.PlatformAnthropic))
}
func TestGatewayCodexModels_DeepSeekWithoutMappingUsesDeepSeekDefaults(t *testing.T) {
gin.SetMode(gin.TestMode)
const groupID int64 = 130
h := newGatewayModelsHandlerForTest(&gatewayModelsAccountRepoStub{
byGroup: map[int64][]service.Account{
groupID: {
{
ID: 1,
Platform: service.PlatformDeepseek,
Status: service.StatusActive,
Schedulable: true,
Credentials: map[string]any{},
},
},
},
})
rec := httptest.NewRecorder()
c, _ := gin.CreateTestContext(rec)
c.Request = httptest.NewRequest(http.MethodGet, "/models?client_version=0.150.0", nil)
c.Set(string(middleware2.ContextKeyAPIKey), &service.APIKey{
Group: &service.Group{ID: groupID, Platform: service.PlatformDeepseek},
})
h.CodexModels(c)
require.Equal(t, http.StatusOK, rec.Code)
var got codexModelsResponseForTest
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &got))
slugs := make([]string, 0, len(got.Models))
for _, model := range got.Models {
slugs = append(slugs, model.Slug)
}
require.Contains(t, slugs, "deepseek-v4-pro")
require.Contains(t, slugs, "deepseek-v4-flash")
require.NotContains(t, slugs, "claude-sonnet-4-6")
require.NotContains(t, slugs, "claude-opus-4-6")
}
func TestGatewayCodexModels_OmitsWildcardMappingKeys(t *testing.T) {
gin.SetMode(gin.TestMode)
const groupID int64 = 131
h := newGatewayModelsHandlerForTest(&gatewayModelsAccountRepoStub{
byGroup: map[int64][]service.Account{
groupID: {
{
ID: 1,
Platform: service.PlatformDeepseek,
Credentials: map[string]any{
"model_mapping": map[string]any{
"foo-*": "deepseek-v4-pro",
"deepseek-v4-pro": "deepseek-v4-pro",
},
},
},
},
},
})
rec := httptest.NewRecorder()
c, _ := gin.CreateTestContext(rec)
c.Request = httptest.NewRequest(http.MethodGet, "/models?client_version=0.150.0", nil)
c.Set(string(middleware2.ContextKeyAPIKey), &service.APIKey{
Group: &service.Group{ID: groupID, Platform: service.PlatformDeepseek},
})
h.CodexModels(c)
require.Equal(t, http.StatusOK, rec.Code)
var got codexModelsResponseForTest
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &got))
slugs := make([]string, 0, len(got.Models))
for _, model := range got.Models {
slugs = append(slugs, model.Slug)
}
require.Equal(t, []string{"deepseek-v4-pro"}, slugs)
}
func TestGatewayModels_CustomModelsListKeepsConcreteModelAllowedByWildcardMapping(t *testing.T) {
gin.SetMode(gin.TestMode)