From eea44bbf0d6e3d242d5bceda8caedb9407f308d0 Mon Sep 17 00:00:00 2001 From: CSCITech Date: Mon, 10 Aug 2026 23:40:52 +0800 Subject: [PATCH] fix bugs --- controller/channel_update_test.go | 18 ++++++++++++++++++ model/channel.go | 2 +- model/channel_update_fields_test.go | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/controller/channel_update_test.go b/controller/channel_update_test.go index 40776477..c24c07bf 100644 --- a/controller/channel_update_test.go +++ b/controller/channel_update_test.go @@ -116,6 +116,24 @@ func TestUpdateChannelPartialStatusDoesNotClearConfiguration(t *testing.T) { require.Equal(t, "https://origin.example.com", *stored.BaseURL) } +func TestUpdateChannelPersistsOpenAIOrganization(t *testing.T) { + db, channel := setupChannelUpdateControllerTestDB(t) + + organization := "org-controller-update" + ctx, recorder := newAuthenticatedContext(t, http.MethodPut, "/api/channel/", map[string]any{ + "id": channel.Id, + "openai_organization": organization, + }, 1) + UpdateChannel(ctx) + response := decodeAPIResponse(t, recorder) + require.True(t, response.Success, response.Message) + + var stored model.Channel + require.NoError(t, db.First(&stored, channel.Id).Error) + require.NotNil(t, stored.OpenAIOrganization) + require.Equal(t, organization, *stored.OpenAIOrganization) +} + func TestUpdateChannelRejectsUnknownStatus(t *testing.T) { db, channel := setupChannelUpdateControllerTestDB(t) diff --git a/model/channel.go b/model/channel.go index fb2c834f..e81958fc 100644 --- a/model/channel.go +++ b/model/channel.go @@ -719,7 +719,7 @@ func (channel *Channel) editableUpdateMap(fields []string) map[string]any { updates["key"] = channel.Key case "openai_organization": if channel.OpenAIOrganization != nil { - updates["openai_organization"] = channel.OpenAIOrganization + updates["open_ai_organization"] = channel.OpenAIOrganization } case "test_model": if channel.TestModel != nil { diff --git a/model/channel_update_fields_test.go b/model/channel_update_fields_test.go index 36465cb6..df54753d 100644 --- a/model/channel_update_fields_test.go +++ b/model/channel_update_fields_test.go @@ -92,6 +92,20 @@ func TestUpdateFieldsSkipsAbilityRebuildForChannelInfoOnly(t *testing.T) { require.EqualValues(t, 1, abilityCount) } +func TestUpdateFieldsPersistsOpenAIOrganizationUsingSchemaColumn(t *testing.T) { + db, channel := setupChannelUpdateFieldsTestDB(t) + + organization := "org-update-fields" + channel.OpenAIOrganization = &organization + + require.NoError(t, channel.UpdateFields("openai_organization")) + + var stored Channel + require.NoError(t, db.First(&stored, channel.Id).Error) + require.NotNil(t, stored.OpenAIOrganization) + require.Equal(t, organization, *stored.OpenAIOrganization) +} + func TestUpdateFieldsRollsBackChannelWhenAbilityRebuildFails(t *testing.T) { db, channel := setupChannelUpdateFieldsTestDB(t) installFailingAbilityDeleteTrigger(t, db)