mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 12:02:27 +08:00
fix(opencode): apply account model mapping in connection tests
Responses probes used the requested model as-is, so aliases like opencode/muse-spark-* were sent upstream instead of the mapped ID.
This commit is contained in:
@@ -400,6 +400,7 @@ func (s *AccountTestService) testOpenCodeGoAccountConnection(c *gin.Context, acc
|
||||
if testModelID == "" {
|
||||
testModelID = DefaultOpenCodeGoTestModel
|
||||
}
|
||||
testModelID = account.GetMappedModel(testModelID)
|
||||
proto := account.GetAPIProtocol()
|
||||
switch proto {
|
||||
case APIProtocolChatCompletions, APIProtocolAnthropic, APIProtocolResponses:
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func openCodeGoTestAccount(id int64) *Account {
|
||||
@@ -91,6 +92,24 @@ func TestAccountTestService_OpenCodeGoPinnedChatProtocolIgnoresCatalog(t *testin
|
||||
require.Equal(t, "https://opencode.ai/zen/go/v1/chat/completions", upstream.requests[0].URL.String())
|
||||
}
|
||||
|
||||
func TestAccountTestService_OpenCodeGoAppliesModelMappingOnResponses(t *testing.T) {
|
||||
account := openCodeGoTestAccount(406)
|
||||
account.Credentials["model_mapping"] = map[string]any{
|
||||
"opencode/muse-spark-1.3-contributior-free": "muse-spark-1.3-contributior-free",
|
||||
}
|
||||
svc, upstream := adaptiveCNAccountTestService(account, adaptiveCNResponsesTestResponse())
|
||||
c, recorder := newTestContext()
|
||||
|
||||
err := svc.TestAccountConnection(c, account.ID, "opencode/muse-spark-1.3-contributior-free", "hi", AccountTestModeDefault)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Len(t, upstream.requests, 1)
|
||||
require.Equal(t, "https://opencode.ai/zen/go/v1/responses", upstream.requests[0].URL.String())
|
||||
require.Equal(t, "muse-spark-1.3-contributior-free", gjson.GetBytes(upstream.lastBody, "model").String())
|
||||
require.Contains(t, recorder.Body.String(), `"model":"muse-spark-1.3-contributior-free"`)
|
||||
require.NotContains(t, string(upstream.lastBody), "opencode/muse-spark-1.3-contributior-free")
|
||||
}
|
||||
|
||||
func TestAccountTestService_OpenCodeGoEmptyModelDefaultsToChatCatalogID(t *testing.T) {
|
||||
account := openCodeGoTestAccount(405)
|
||||
svc, upstream := adaptiveCNAccountTestService(account, adaptiveCNChatTestResponse())
|
||||
|
||||
Reference in New Issue
Block a user