diff --git a/agent/assistant/load_test.go b/agent/assistant/load_test.go index 48deaee2..08ec735e 100644 --- a/agent/assistant/load_test.go +++ b/agent/assistant/load_test.go @@ -73,7 +73,8 @@ func TestLoadPath(t *testing.T) { // ConnectorOptions assert.NotNil(t, assistant.ConnectorOptions) - assert.True(t, assistant.ConnectorOptions.Optional) + assert.NotNil(t, assistant.ConnectorOptions.Optional) + assert.True(t, *assistant.ConnectorOptions.Optional) assert.NotNil(t, assistant.ConnectorOptions.Connectors) assert.Contains(t, assistant.ConnectorOptions.Connectors, "gpt-4o") assert.Contains(t, assistant.ConnectorOptions.Connectors, "gpt-4o-mini") @@ -370,7 +371,8 @@ func TestUpdate(t *testing.T) { require.NoError(t, err) assert.NotNil(t, assistant.ConnectorOptions) - assert.False(t, assistant.ConnectorOptions.Optional) + assert.NotNil(t, assistant.ConnectorOptions.Optional) + assert.False(t, *assistant.ConnectorOptions.Optional) assert.Contains(t, assistant.ConnectorOptions.Connectors, "new-connector") }) diff --git a/agent/store/types/convert_test.go b/agent/store/types/convert_test.go index b0b8b347..2ba0c752 100644 --- a/agent/store/types/convert_test.go +++ b/agent/store/types/convert_test.go @@ -609,7 +609,7 @@ func TestToAssistantModel(t *testing.T) { if result.ConnectorOptions == nil { t.Error("Expected ConnectorOptions to be set") } else { - if !result.ConnectorOptions.Optional { + if result.ConnectorOptions.Optional == nil || !*result.ConnectorOptions.Optional { t.Error("Expected ConnectorOptions.Optional to be true") } if len(result.ConnectorOptions.Connectors) != 2 { @@ -849,7 +849,7 @@ func TestToAssistantModelNewFields(t *testing.T) { t.Fatal("Expected ConnectorOptions to be set") } - if !result.ConnectorOptions.Optional { + if result.ConnectorOptions.Optional == nil || !*result.ConnectorOptions.Optional { t.Error("Expected Optional to be true") } @@ -1349,8 +1349,9 @@ func TestToConnectorOptions(t *testing.T) { }) t.Run("ConnectorOptionsPointer", func(t *testing.T) { + optionalTrue := true opts := &ConnectorOptions{ - Optional: true, + Optional: &optionalTrue, Connectors: []string{"openai", "anthropic"}, Filters: []ModelCapability{CapVision, CapToolCalls}, } @@ -1364,8 +1365,9 @@ func TestToConnectorOptions(t *testing.T) { }) t.Run("ConnectorOptionsValue", func(t *testing.T) { + optionalTrue := true opts := ConnectorOptions{ - Optional: true, + Optional: &optionalTrue, Connectors: []string{"openai", "anthropic"}, Filters: []ModelCapability{CapVision, CapToolCalls}, } @@ -1373,7 +1375,7 @@ func TestToConnectorOptions(t *testing.T) { if err != nil { t.Errorf("Expected no error, got: %v", err) } - if !result.Optional { + if result.Optional == nil || !*result.Optional { t.Error("Expected Optional to be true") } if len(result.Connectors) != 2 { @@ -1394,7 +1396,7 @@ func TestToConnectorOptions(t *testing.T) { if err != nil { t.Errorf("Expected no error, got: %v", err) } - if !result.Optional { + if result.Optional == nil || !*result.Optional { t.Error("Expected Optional to be true") } if len(result.Connectors) != 3 { @@ -1413,7 +1415,7 @@ func TestToConnectorOptions(t *testing.T) { if err != nil { t.Errorf("Expected no error, got: %v", err) } - if !result.Optional { + if result.Optional == nil || !*result.Optional { t.Error("Expected Optional to be true") } if result.Connectors != nil { @@ -1424,6 +1426,42 @@ func TestToConnectorOptions(t *testing.T) { } }) + t.Run("MapInputOptionalFalse", func(t *testing.T) { + data := map[string]interface{}{ + "optional": false, + "connectors": []string{"openai"}, + "filters": []string{"vision"}, + } + result, err := ToConnectorOptions(data) + if err != nil { + t.Errorf("Expected no error, got: %v", err) + } + if result.Optional == nil { + t.Error("Expected Optional to be set") + } else if *result.Optional { + t.Error("Expected Optional to be false") + } + if len(result.Connectors) != 1 { + t.Errorf("Expected 1 connector, got %d", len(result.Connectors)) + } + }) + + t.Run("MapInputOptionalNil", func(t *testing.T) { + data := map[string]interface{}{ + "connectors": []string{"openai"}, + } + result, err := ToConnectorOptions(data) + if err != nil { + t.Errorf("Expected no error, got: %v", err) + } + if result.Optional != nil { + t.Errorf("Expected Optional to be nil (not set), got: %v", *result.Optional) + } + if len(result.Connectors) != 1 { + t.Errorf("Expected 1 connector, got %d", len(result.Connectors)) + } + }) + t.Run("InvalidInput", func(t *testing.T) { // Test with data that can't be marshaled invalidData := make(chan int) diff --git a/agent/store/types/types.go b/agent/store/types/types.go index c398219d..85f4dbf8 100644 --- a/agent/store/types/types.go +++ b/agent/store/types/types.go @@ -245,7 +245,7 @@ const ( // ConnectorOptions the connector selection options // Allows defining optional connector selection with filtering capabilities type ConnectorOptions struct { - Optional bool `json:"optional,omitempty"` // Whether connector is optional for user selection + Optional *bool `json:"optional"` // Whether connector is optional for user selection (nil=default, false=hidden, true=shown) Connectors []string `json:"connectors,omitempty"` // List of available connectors, empty means all connectors are available Filters []ModelCapability `json:"filters,omitempty"` // Filter by model capabilities, conditions can be stacked } diff --git a/agent/store/xun/assistant_test.go b/agent/store/xun/assistant_test.go index dc3350c6..042785c5 100644 --- a/agent/store/xun/assistant_test.go +++ b/agent/store/xun/assistant_test.go @@ -454,13 +454,14 @@ func TestSaveAssistant(t *testing.T) { t.Run("ConnectorOptions", func(t *testing.T) { // Test assistant with connector options + optionalTrue := true assistant := &types.AssistantModel{ Name: "Connector Options Test", Type: "assistant", Connector: "openai", Share: "private", ConnectorOptions: &types.ConnectorOptions{ - Optional: true, + Optional: &optionalTrue, Connectors: []string{"openai", "anthropic"}, Filters: []types.ModelCapability{types.CapVision, types.CapToolCalls}, }, @@ -481,7 +482,7 @@ func TestSaveAssistant(t *testing.T) { t.Fatal("Expected connector options to be set") } - if !retrieved.ConnectorOptions.Optional { + if retrieved.ConnectorOptions.Optional == nil || !*retrieved.ConnectorOptions.Optional { t.Error("Expected optional to be true") } @@ -596,13 +597,14 @@ func TestSaveAssistant(t *testing.T) { t.Run("AllNewFieldsTogether", func(t *testing.T) { // Test assistant with all new fields together + optionalFalse := false assistant := &types.AssistantModel{ Name: "All New Fields Test", Type: "assistant", Connector: "openai", Share: "private", ConnectorOptions: &types.ConnectorOptions{ - Optional: false, + Optional: &optionalFalse, Connectors: []string{"openai"}, Filters: []types.ModelCapability{types.CapVision}, },