launch: remove banner and warn only when backup-relevant configs change (#15124)

This commit is contained in:
Jeffrey Morgan
2026-03-29 00:27:24 -07:00
committed by ParthSareen
parent 04e41ddcfb
commit cdd0bc48a3
5 changed files with 282 additions and 6 deletions

View File

@@ -8,18 +8,23 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/cmd/internal/fileutil"
)
type stubEditorRunner struct {
edited [][]string
ranModel string
editErr error
paths []string
editFn func(models []string) error
}
func (s *stubEditorRunner) Run(model string, args []string) error {
@@ -29,12 +34,17 @@ func (s *stubEditorRunner) Run(model string, args []string) error {
func (s *stubEditorRunner) String() string { return "StubEditor" }
func (s *stubEditorRunner) Paths() []string { return nil }
func (s *stubEditorRunner) Paths() []string { return append([]string(nil), s.paths...) }
func (s *stubEditorRunner) Edit(models []string) error {
if s.editErr != nil {
return s.editErr
}
if s.editFn != nil {
if err := s.editFn(models); err != nil {
return err
}
}
cloned := append([]string(nil), models...)
s.edited = append(s.edited, cloned)
return nil
@@ -745,6 +755,62 @@ func TestPrepareEditorIntegration_SavesOnlyAfterSuccessfulEdit(t *testing.T) {
}
}
func TestPrepareEditorIntegration_ShowsBackupWarningWhenConfigChanges(t *testing.T) {
tmpDir := t.TempDir()
setTestHome(t, tmpDir)
configPath := filepath.Join(tmpDir, "settings.json")
original := []byte(`{"model":"old"}`)
if err := os.WriteFile(configPath, original, 0o644); err != nil {
t.Fatalf("failed to seed config file: %v", err)
}
editor := &stubEditorRunner{
paths: []string{configPath},
editFn: func(models []string) error {
return fileutil.WriteWithBackup(configPath, []byte(`{"model":"new"}`))
},
}
stderr := captureStderr(t, func() {
if err := prepareEditorIntegration("opencode", editor, editor, []string{"llama3.2"}); err != nil {
t.Fatalf("prepareEditorIntegration returned error: %v", err)
}
})
if !strings.Contains(stderr, "configuration has been modified. Backups are saved in") {
t.Fatalf("expected backup warning, got stderr: %q", stderr)
}
}
func TestPrepareEditorIntegration_DoesNotShowBackupWarningWhenConfigUnchanged(t *testing.T) {
tmpDir := t.TempDir()
setTestHome(t, tmpDir)
configPath := filepath.Join(tmpDir, "settings.json")
original := []byte(`{"model":"same"}`)
if err := os.WriteFile(configPath, original, 0o644); err != nil {
t.Fatalf("failed to seed config file: %v", err)
}
editor := &stubEditorRunner{
paths: []string{configPath},
editFn: func(models []string) error {
return fileutil.WriteWithBackup(configPath, original)
},
}
stderr := captureStderr(t, func() {
if err := prepareEditorIntegration("pi", editor, editor, []string{"llama3.2"}); err != nil {
t.Fatalf("prepareEditorIntegration returned error: %v", err)
}
})
if strings.Contains(stderr, "configuration has been modified. Backups are saved in") {
t.Fatalf("did not expect backup warning when config is unchanged, got stderr: %q", stderr)
}
}
func TestShowOrPull_ModelExists(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/api/show" {