tui: a first run with no model catalog says "… syncing model catalog" while it syncs, and S doesn't start a second sync meanwhile

Init set m.syncing on its value receiver, a copy Bubble Tea never sees
(staticcheck SA4005), so the sync ran with nothing on the status line and
S could start another on top of it. newModel now sets syncing when there
is no catalog, and Init starts the sync from it.

TestFirstRunShowsCatalogSync is new and fails without the change. go vet
(darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui
./internal/tui under a temp HOME pass.
This commit is contained in:
yetone committed 2026-10-06 04:31:29 +08:00
1 parent 6b975ea9fd
commit 6e623d1651
2 files changed
+21 -2

No files matched your search

+4 -2
View File
@@ -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
+17
View File
@@ -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")
}
}