|
| 1 | +package config_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + |
| 6 | + "github.com/mudler/LocalAI/core/config" |
| 7 | + |
| 8 | + . "github.com/onsi/ginkgo/v2" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | +) |
| 11 | + |
| 12 | +var _ = Describe("default galleries", func() { |
| 13 | + It("serves the model gallery from index.localai.io with GitHub as a mirror", func() { |
| 14 | + var galleries []config.Gallery |
| 15 | + Expect(json.Unmarshal([]byte(config.DefaultGalleriesJSON), &galleries)).To(Succeed()) |
| 16 | + Expect(galleries).To(HaveLen(1)) |
| 17 | + Expect(galleries[0].Name).To(Equal("localai")) |
| 18 | + Expect(galleries[0].URL).To(Equal("https://index.localai.io/models")) |
| 19 | + Expect(galleries[0].Mirrors).To(Equal([]string{"github:mudler/LocalAI/gallery/index.yaml@master"})) |
| 20 | + }) |
| 21 | + |
| 22 | + It("serves the backend gallery from index.localai.io with GitHub as a mirror", func() { |
| 23 | + var galleries []config.Gallery |
| 24 | + Expect(json.Unmarshal([]byte(config.DefaultBackendGalleriesJSON), &galleries)).To(Succeed()) |
| 25 | + Expect(galleries).To(HaveLen(1)) |
| 26 | + Expect(galleries[0].Name).To(Equal("localai")) |
| 27 | + Expect(galleries[0].URL).To(Equal("https://index.localai.io/backends")) |
| 28 | + Expect(galleries[0].Mirrors).To(Equal([]string{"github:mudler/LocalAI/backend/index.yaml@master"})) |
| 29 | + }) |
| 30 | + |
| 31 | + // The mirror is the whole reason this default is safe to ship: if |
| 32 | + // index.localai.io is unreachable, an install must still resolve its |
| 33 | + // gallery from GitHub exactly as it did before. |
| 34 | + It("always leaves a reachable fallback behind the primary", func() { |
| 35 | + for _, raw := range []string{config.DefaultGalleriesJSON, config.DefaultBackendGalleriesJSON} { |
| 36 | + var galleries []config.Gallery |
| 37 | + Expect(json.Unmarshal([]byte(raw), &galleries)).To(Succeed()) |
| 38 | + for _, g := range galleries { |
| 39 | + Expect(g.Mirrors).ToNot(BeEmpty(), "default %q has no mirror", g.Name) |
| 40 | + } |
| 41 | + } |
| 42 | + }) |
| 43 | + |
| 44 | + // mustGalleries panics on malformed JSON, and these constants are also |
| 45 | + // fed to kong as defaults, so a typo would be a startup crash rather |
| 46 | + // than a config error. |
| 47 | + It("parses through the same path startup uses", func() { |
| 48 | + baseline := config.DefaultRuntimeBaseline() |
| 49 | + Expect(baseline.Galleries).To(HaveLen(1)) |
| 50 | + Expect(baseline.BackendGalleries).To(HaveLen(1)) |
| 51 | + Expect(baseline.Galleries[0].URL).To(Equal("https://index.localai.io/models")) |
| 52 | + Expect(baseline.BackendGalleries[0].URL).To(Equal("https://index.localai.io/backends")) |
| 53 | + }) |
| 54 | + |
| 55 | + // The baseline decides "kong default" vs "user-configured", and since |
| 56 | + // the defaults grew a Mirrors slice that comparison runs through |
| 57 | + // GalleriesEqual rather than ==. A default install must still let the |
| 58 | + // persisted file apply, and any override - including one that differs |
| 59 | + // from the default only by its mirrors - must still be seen as env-set. |
| 60 | + Context("as the option-less startup baseline", func() { |
| 61 | + It("treats an untouched default list as not env-set, so the file applies", func() { |
| 62 | + o := config.DefaultRuntimeBaseline() |
| 63 | + saved := []config.Gallery{{Name: "mine", URL: "https://example.com/index.yaml"}} |
| 64 | + savedBackends := []config.Gallery{{Name: "mine-backends", URL: "https://example.com/backends.yaml"}} |
| 65 | + o.ApplyRuntimeSettingsAtStartup(&config.RuntimeSettings{ |
| 66 | + Galleries: &saved, |
| 67 | + BackendGalleries: &savedBackends, |
| 68 | + }) |
| 69 | + Expect(o.Galleries).To(Equal(saved)) |
| 70 | + Expect(o.BackendGalleries).To(Equal(savedBackends)) |
| 71 | + }) |
| 72 | + |
| 73 | + It("treats LOCALAI_GALLERIES as env-set even when it only drops the mirror", func() { |
| 74 | + o := config.DefaultRuntimeBaseline() |
| 75 | + // Same primary as the default, mirror removed: env-set. |
| 76 | + o.Galleries = []config.Gallery{{Name: "localai", URL: "https://index.localai.io/models"}} |
| 77 | + saved := []config.Gallery{{Name: "file", URL: "https://file.example/index.yaml"}} |
| 78 | + o.ApplyRuntimeSettingsAtStartup(&config.RuntimeSettings{Galleries: &saved}) |
| 79 | + Expect(o.Galleries[0].Name).To(Equal("localai"), |
| 80 | + "an env list differing only by mirrors must still win over the file") |
| 81 | + }) |
| 82 | + }) |
| 83 | +}) |
0 commit comments