Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

companion: wait for install workers in tests

Barack Sokullue987c4d1e6f3
diff --git a/webbrain-systray/internal/d1/manager_files_test.go b/webbrain-systray/internal/d1/manager_files_test.go
index af8abe7e3..7875665cd 100644
--- a/webbrain-systray/internal/d1/manager_files_test.go
+++ b/webbrain-systray/internal/d1/manager_files_test.go
@@ -24,7 +24,19 @@ func TestInstallClaimsPhaseBeforeWorkerStarts(t *testing.T) {
if err := m.Install(); err != nil {
t.Fatal(err)
}
- defer m.Cancel()
+ t.Cleanup(func() {
+ m.Cancel()
+ m.mu.Lock()
+ done := m.installDone
+ m.mu.Unlock()
+ if done != nil {
+ select {
+ case <-done:
+ case <-time.After(10 * time.Second):
+ t.Error("install did not stop after cancellation")
+ }
+ }
+ })
if err := m.Install(); err == nil {
t.Fatal("overlapping install was accepted")
}
diff --git a/webbrain-systray/internal/localmodel/manager.go b/webbrain-systray/internal/localmodel/manager.go
index f4a23df42..75ef88600 100644
--- a/webbrain-systray/internal/localmodel/manager.go
+++ b/webbrain-systray/internal/localmodel/manager.go
@@ -65,19 +65,20 @@ type Manager struct {
register func([]core.LocalUpstream) error
onChange func()
- phase string
- step string
- progress *download.Progress
- err string
- port int
- startedAt *time.Time
- plan Plan
- cancel context.CancelFunc
- cmd *exec.Cmd
- starting chan struct{} // closed after Start either publishes cmd or fails
- exited chan struct{}
- stopping bool
- stopErr error // why the server was stopped, when it was not the user
+ phase string
+ step string
+ progress *download.Progress
+ err string
+ port int
+ startedAt *time.Time
+ plan Plan
+ cancel context.CancelFunc
+ installDone chan struct{}
+ cmd *exec.Cmd
+ starting chan struct{} // closed after Start either publishes cmd or fails
+ exited chan struct{}
+ stopping bool
+ stopErr error // why the server was stopped, when it was not the user
}
func NewManager(store *settings.Store, register func([]core.LocalUpstream) error, onChange func()) *Manager {
@@ -307,12 +308,15 @@ func (m *Manager) Install(format string) error {
}
ctx, cancel := context.WithCancel(context.Background())
m.cancel = cancel
+ done := make(chan struct{})
+ m.installDone = done
m.phase, m.step, m.err, m.progress = PhaseDownloading, "Preparing the local model", "", nil
m.mu.Unlock()
m.changed()
go func() {
defer cancel()
+ defer close(done)
var err error
if format == "mlx" {
err = m.installMLX(ctx, info)
diff --git a/webbrain-systray/internal/localmodel/manager_test.go b/webbrain-systray/internal/localmodel/manager_test.go
index 8343d4289..0757be99e 100644
--- a/webbrain-systray/internal/localmodel/manager_test.go
+++ b/webbrain-systray/internal/localmodel/manager_test.go
@@ -94,7 +94,19 @@ func TestInstallClaimsPhaseBeforeWorkerStarts(t *testing.T) {
if err := m.Install("gguf"); err != nil {
t.Fatal(err)
}
- defer m.Cancel()
+ t.Cleanup(func() {
+ m.Cancel()
+ m.mu.Lock()
+ done := m.installDone
+ m.mu.Unlock()
+ if done != nil {
+ select {
+ case <-done:
+ case <-time.After(10 * time.Second):
+ t.Error("install did not stop after cancellation")
+ }
+ }
+ })
if err := m.Install("gguf"); err == nil {
t.Fatal("overlapping install was accepted")
}