From 7c008bd8c1fa53b0302672919d6b46726b3eaa85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=BD=B3=E6=9E=97?= Date: Fri, 11 Sep 2026 14:19:23 +0800 Subject: [PATCH] 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. --- .../internal/service/account_test_service.go | 1 + .../account_test_service_opencode_go_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/backend/internal/service/account_test_service.go b/backend/internal/service/account_test_service.go index 46dea6b7f7..ca088f01d1 100644 --- a/backend/internal/service/account_test_service.go +++ b/backend/internal/service/account_test_service.go @@ -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: diff --git a/backend/internal/service/account_test_service_opencode_go_test.go b/backend/internal/service/account_test_service_opencode_go_test.go index 837267149a..1862e223d3 100644 --- a/backend/internal/service/account_test_service_opencode_go_test.go +++ b/backend/internal/service/account_test_service_opencode_go_test.go @@ -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())