mirror of
https://github.com/ollama/ollama.git
synced 2026-04-17 15:53:27 +02:00
launch: skip unchanged integration rewrite configration (#15491)
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/ollama/ollama/api"
|
||||
"github.com/ollama/ollama/cmd/config"
|
||||
)
|
||||
|
||||
type stubEditorRunner struct {
|
||||
@@ -722,6 +723,59 @@ func TestLauncherClientFilterDisabledCloudModels_ChecksStatusOncePerInvocation(t
|
||||
}
|
||||
}
|
||||
|
||||
func TestSavedMatchesModels(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
saved *config.IntegrationConfig
|
||||
models []string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "nil saved",
|
||||
saved: nil,
|
||||
models: []string{"llama3.2"},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "identical order",
|
||||
saved: &config.IntegrationConfig{Models: []string{"llama3.2", "qwen3:8b"}},
|
||||
models: []string{"llama3.2", "qwen3:8b"},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "different order",
|
||||
saved: &config.IntegrationConfig{Models: []string{"llama3.2", "qwen3:8b"}},
|
||||
models: []string{"qwen3:8b", "llama3.2"},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "subset",
|
||||
saved: &config.IntegrationConfig{Models: []string{"llama3.2", "qwen3:8b"}},
|
||||
models: []string{"llama3.2"},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "nil models in saved with non-nil models",
|
||||
saved: &config.IntegrationConfig{Models: nil},
|
||||
models: []string{"llama3.2"},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "empty both",
|
||||
saved: &config.IntegrationConfig{Models: nil},
|
||||
models: nil,
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := savedMatchesModels(tt.saved, tt.models); got != tt.want {
|
||||
t.Fatalf("savedMatchesModels = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareEditorIntegration_SavesOnlyAfterSuccessfulEdit(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
setTestHome(t, tmpDir)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/ollama/ollama/api"
|
||||
@@ -500,7 +501,7 @@ func (c *launcherClient) launchEditorIntegration(ctx context.Context, name strin
|
||||
return nil
|
||||
}
|
||||
|
||||
if needsConfigure || req.ModelOverride != "" {
|
||||
if (needsConfigure || req.ModelOverride != "") && !savedMatchesModels(saved, models) {
|
||||
if err := prepareEditorIntegration(name, runner, editor, models); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -846,6 +847,13 @@ func firstModel(models []string) string {
|
||||
return models[0]
|
||||
}
|
||||
|
||||
func savedMatchesModels(saved *config.IntegrationConfig, models []string) bool {
|
||||
if saved == nil {
|
||||
return false
|
||||
}
|
||||
return slices.Equal(saved.Models, models)
|
||||
}
|
||||
|
||||
func editorPreCheckedModels(saved *config.IntegrationConfig, override string) []string {
|
||||
if override == "" {
|
||||
if saved == nil {
|
||||
|
||||
Reference in New Issue
Block a user