Skip to content

Commit 76dbb12

Browse files
committed
Small improvements and fix tests
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 27a358f commit 76dbb12

File tree

8 files changed

+27
-29
lines changed

8 files changed

+27
-29
lines changed

core/launcher/launcher.go renamed to cli/launcher/internal/launcher.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@ type Launcher struct {
6060
}
6161

6262
// NewLauncher creates a new launcher instance
63-
func NewLauncher() *Launcher {
63+
func NewLauncher(ui *LauncherUI, window fyne.Window, app fyne.App) *Launcher {
6464
return &Launcher{
6565
releaseManager: NewReleaseManager(),
6666
config: &Config{},
6767
logBuffer: &strings.Builder{},
6868
statusChannel: make(chan string, 100),
6969
ctx: context.Background(),
70+
ui: ui,
71+
window: window,
72+
app: app,
7073
}
7174
}
7275

@@ -94,6 +97,9 @@ func (l *Launcher) setupLogging() error {
9497

9598
// Initialize sets up the launcher
9699
func (l *Launcher) Initialize() error {
100+
if l.app == nil {
101+
return fmt.Errorf("app is nil")
102+
}
97103
log.Printf("Initializing launcher...")
98104

99105
// Setup logging
@@ -359,22 +365,10 @@ func (l *Launcher) SetConfig(config *Config) error {
359365
return l.saveConfig()
360366
}
361367

362-
func (l *Launcher) SetUI(ui *LauncherUI) {
363-
l.ui = ui
364-
}
365-
366368
func (l *Launcher) GetUI() *LauncherUI {
367369
return l.ui
368370
}
369371

370-
func (l *Launcher) SetWindow(window fyne.Window) {
371-
l.window = window
372-
}
373-
374-
func (l *Launcher) SetApp(app fyne.App) {
375-
l.app = app
376-
}
377-
378372
func (l *Launcher) SetSystray(systray *SystrayManager) {
379373
l.systray = systray
380374
}
File renamed without changes.

core/launcher/launcher_test.go renamed to cli/launcher/internal/launcher_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
. "github.com/onsi/ginkgo/v2"
99
. "github.com/onsi/gomega"
1010

11-
"github.com/mudler/LocalAI/core/launcher"
11+
"fyne.io/fyne/v2/app"
12+
13+
launcher "github.com/mudler/LocalAI/cli/launcher/internal"
1214
)
1315

1416
var _ = Describe("Launcher", func() {
@@ -22,7 +24,10 @@ var _ = Describe("Launcher", func() {
2224
tempDir, err = os.MkdirTemp("", "launcher-test-*")
2325
Expect(err).ToNot(HaveOccurred())
2426

25-
launcherInstance = launcher.NewLauncher()
27+
ui := launcher.NewLauncherUI()
28+
app := app.NewWithID("com.localai.launcher")
29+
30+
launcherInstance = launcher.NewLauncher(ui, nil, app)
2631
})
2732

2833
AfterEach(func() {
@@ -31,9 +36,7 @@ var _ = Describe("Launcher", func() {
3136

3237
Describe("NewLauncher", func() {
3338
It("should create a launcher with default configuration", func() {
34-
launcher := launcher.NewLauncher()
35-
Expect(launcher).ToNot(BeNil())
36-
Expect(launcher.GetConfig()).ToNot(BeNil())
39+
Expect(launcherInstance.GetConfig()).ToNot(BeNil())
3740
})
3841
})
3942

@@ -45,7 +48,7 @@ var _ = Describe("Launcher", func() {
4548
config := launcherInstance.GetConfig()
4649
Expect(config.ModelsPath).ToNot(BeEmpty())
4750
Expect(config.BackendsPath).ToNot(BeEmpty())
48-
Expect(config.Address).To(Equal(":8080"))
51+
Expect(config.Address).To(Equal("127.0.0.1:8080"))
4952
Expect(config.LogLevel).To(Equal("info"))
5053
})
5154

@@ -126,7 +129,7 @@ var _ = Describe("Launcher", func() {
126129
Expect(err).To(HaveOccurred())
127130
// Could be either "not found" or "permission denied" depending on test environment
128131
errMsg := err.Error()
129-
hasExpectedError := strings.Contains(errMsg, "LocalAI binary not found") ||
132+
hasExpectedError := strings.Contains(errMsg, "LocalAI binary") ||
130133
strings.Contains(errMsg, "permission denied")
131134
Expect(hasExpectedError).To(BeTrue(), "Expected error about binary not found or permission denied, got: %s", errMsg)
132135
})
@@ -187,7 +190,11 @@ var _ = Describe("Config", func() {
187190
config := &launcher.Config{}
188191
Expect(config.EnvironmentVars).To(BeNil())
189192

190-
launcher := launcher.NewLauncher()
193+
ui := launcher.NewLauncherUI()
194+
app := app.NewWithID("com.localai.launcher")
195+
196+
launcher := launcher.NewLauncher(ui, nil, app)
197+
191198
err := launcher.Initialize()
192199
Expect(err).ToNot(HaveOccurred())
193200

File renamed without changes.

core/launcher/release_manager_test.go renamed to cli/launcher/internal/release_manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
. "github.com/onsi/ginkgo/v2"
99
. "github.com/onsi/gomega"
1010

11-
"github.com/mudler/LocalAI/core/launcher"
11+
launcher "github.com/mudler/LocalAI/cli/launcher/internal"
1212
)
1313

1414
var _ = Describe("ReleaseManager", func() {
@@ -73,7 +73,7 @@ var _ = Describe("ReleaseManager", func() {
7373
Expect(version).To(BeEmpty()) // No binary installed in test
7474
})
7575

76-
It("should return version when binary exists", func() {
76+
It("should return empty version when binary exists but no metadata", func() {
7777
// Create a fake binary for testing
7878
err := os.MkdirAll(rm.BinaryPath, 0755)
7979
Expect(err).ToNot(HaveOccurred())
@@ -83,7 +83,7 @@ var _ = Describe("ReleaseManager", func() {
8383
Expect(err).ToNot(HaveOccurred())
8484

8585
version := rm.GetInstalledVersion()
86-
Expect(version).ToNot(BeEmpty()) // Should return fallback version
86+
Expect(version).To(BeEmpty())
8787
})
8888
})
8989

File renamed without changes.
File renamed without changes.

cli/launcher/main.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"fyne.io/fyne/v2"
1010
"fyne.io/fyne/v2/app"
1111
"fyne.io/fyne/v2/driver/desktop"
12-
coreLauncher "github.com/mudler/LocalAI/core/launcher"
12+
coreLauncher "github.com/mudler/LocalAI/cli/launcher/internal"
1313
)
1414

1515
func main() {
@@ -23,10 +23,7 @@ func main() {
2323
ui := coreLauncher.NewLauncherUI()
2424

2525
// Initialize the launcher with UI context
26-
launcher := coreLauncher.NewLauncher()
27-
launcher.SetUI(ui)
28-
launcher.SetWindow(myWindow)
29-
launcher.SetApp(myApp)
26+
launcher := coreLauncher.NewLauncher(ui, myWindow, myApp)
3027

3128
// Setup the UI
3229
content := ui.CreateMainUI(launcher)

0 commit comments

Comments
 (0)