From af8cac5768a9b80c6004375300315be15bdd4247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20L=C3=B3pez=20Luna?= Date: Fri, 28 Nov 2025 17:12:34 +0100 Subject: [PATCH] just warn user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ignacio López Luna --- pkg/compose/model.go | 10 ++-- pkg/compose/model_test.go | 110 -------------------------------------- 2 files changed, 4 insertions(+), 116 deletions(-) delete mode 100644 pkg/compose/model_test.go diff --git a/pkg/compose/model.go b/pkg/compose/model.go index 49665edfd..d892d9194 100644 --- a/pkg/compose/model.go +++ b/pkg/compose/model.go @@ -30,6 +30,7 @@ import ( "github.com/containerd/errdefs" "github.com/docker/cli/cli-plugins/manager" "github.com/docker/compose/v5/pkg/api" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" ) @@ -153,23 +154,20 @@ func (m *modelAPI) PullModel(ctx context.Context, model types.ModelConfig, quiet func (m *modelAPI) ConfigureModel(ctx context.Context, config types.ModelConfig, events api.EventProcessor) error { if len(config.RuntimeFlags) != 0 { - return fmt.Errorf("runtime flags are not supported for model configuration") + logrus.Warnf("Runtime flags are not supported and will be ignored for model %s", config.Model) + config.RuntimeFlags = nil } events.On(api.Resource{ ID: config.Name, Status: api.Working, Text: "Configuring", }) - // configure [--context-size=] MODEL [-- ] + // configure [--context-size=] MODEL args := []string{"configure"} if config.ContextSize > 0 { args = append(args, "--context-size", strconv.Itoa(config.ContextSize)) } args = append(args, config.Model) - if len(config.RuntimeFlags) != 0 { - args = append(args, "--") - args = append(args, config.RuntimeFlags...) - } cmd := exec.CommandContext(ctx, m.path, args...) err := m.prepare(ctx, cmd) if err != nil { diff --git a/pkg/compose/model_test.go b/pkg/compose/model_test.go deleted file mode 100644 index 05012c814..000000000 --- a/pkg/compose/model_test.go +++ /dev/null @@ -1,110 +0,0 @@ -/* - Copyright 2020 Docker Compose CLI authors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package compose - -import ( - "context" - "os/exec" - "strings" - "testing" - - "github.com/compose-spec/compose-go/v2/types" - "github.com/docker/compose/v5/pkg/api" - "gotest.tools/v3/assert" -) - -// mockEventProcessor is a simple mock implementation of api.EventProcessor for testing -type mockEventProcessor struct{} - -func (m *mockEventProcessor) Start(ctx context.Context, operation string) {} -func (m *mockEventProcessor) On(events ...api.Resource) {} -func (m *mockEventProcessor) Done(operation string, success bool) {} - -func TestConfigureModel_RejectsRuntimeFlags(t *testing.T) { - tests := []struct { - name string - config types.ModelConfig - expectError bool - errorMessage string - }{ - { - name: "rejects config with runtime flags", - config: types.ModelConfig{ - Name: "test-model", - Model: "llama3:latest", - RuntimeFlags: []string{"--flag1", "value1"}, - }, - expectError: true, - errorMessage: "runtime flags are not supported for model configuration", - }, - { - name: "rejects config with single runtime flag", - config: types.ModelConfig{ - Name: "test-model", - Model: "llama3:latest", - RuntimeFlags: []string{"--verbose"}, - }, - expectError: true, - errorMessage: "runtime flags are not supported for model configuration", - }, - { - name: "accepts config without runtime flags", - config: types.ModelConfig{ - Name: "test-model", - Model: "llama3:latest", - RuntimeFlags: nil, - }, - expectError: false, - }, - { - name: "accepts config with empty runtime flags", - config: types.ModelConfig{ - Name: "test-model", - Model: "llama3:latest", - RuntimeFlags: []string{}, - }, - expectError: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - // Create a minimal modelAPI instance - modelApi := &modelAPI{ - path: "/usr/local/bin/docker-model", - prepare: func(ctx context.Context, cmd *exec.Cmd) error { return nil }, - cleanup: func() {}, - } - - // Create a mock event processor - events := &mockEventProcessor{} - - // Call ConfigureModel - err := modelApi.ConfigureModel(context.Background(), tt.config, events) - - if tt.expectError { - assert.ErrorContains(t, err, tt.errorMessage) - } else if err != nil { - // For success cases, verify we did NOT get the RuntimeFlags validation error - // The function may still fail due to exec.Command not being mocked, but it - // should not fail with the RuntimeFlags validation error - assert.Assert(t, !strings.Contains(err.Error(), "runtime flags are not supported"), - "should not fail with RuntimeFlags validation error when RuntimeFlags is empty/nil, got: %v", err) - } - }) - } -}