diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 2433e996c..638f76da6 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -175,6 +175,9 @@ func newModel() model { } shown, hidden := settings.Arrange(settings.Load(), set, func(a *agent.Agent) string { return a.ID }) m := model{agents: append(shown, hidden...), hidden: len(shown), period: usage.Week, srange: 1} + // no model catalog yet: Init syncs it. Set here, as Init's receiver is + // a copy the program never sees. + m.syncing = catalog.Source() == "" m.reload() return m } @@ -220,8 +223,7 @@ func (m *model) goTo(p page) tea.Cmd { } func (m model) Init() tea.Cmd { - if catalog.Source() == "" { - m.syncing = true + if m.syncing { return syncCmd } return nil diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index 9756800c5..f2e50b62b 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -316,3 +316,20 @@ func TestLibraryPage(t *testing.T) { t.Fatalf("servers %+v", s) } } + +// A first run has no model catalog: Init syncs it, the status line says so +// until it is done, and S doesn't start a second sync meanwhile. +func TestFirstRunShowsCatalogSync(t *testing.T) { + home(t) + m := newModel() + m.w, m.h = 120, 40 + if m.Init() == nil { + t.Fatal("no catalog, and Init didn't sync it") + } + if !m.syncing || !strings.Contains(m.View(), "syncing model catalog") { + t.Fatalf("syncing %v:\n%s", m.syncing, m.View()) + } + if _, cmd := m.Update(keyMsg("S")); cmd != nil { + t.Fatal("S started a second sync while the first runs") + } +}