Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/config/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func LoadTUIConfig() TUIConfig {
cfg.Notifications = *raw.Notifications
}
cfg.Accent = raw.Accent
if raw.PollMs != nil {
// A non-positive poll interval would busy-loop or never poll; ignore it
// and keep the default (unset) value instead.
if raw.PollMs != nil && *raw.PollMs > 0 {
cfg.PollMs = *raw.PollMs
}
cfg.SetupDoneAt = raw.SetupDoneAt
Expand Down
27 changes: 27 additions & 0 deletions packages/core/config/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,33 @@ func TestLoadTUIConfigHonorsExplicitFalseNotifications(t *testing.T) {
}
}

func TestLoadTUIConfigPollMsValidation(t *testing.T) {
cases := []struct {
name string
json string
want int
}{
{"zero falls back to default", `{"pollMs":0}`, 0},
{"negative falls back to default", `{"pollMs":-1}`, 0},
{"minimum positive is kept", `{"pollMs":1}`, 1},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv("HOME", t.TempDir())
if err := os.MkdirAll(Dir(), 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(TUIConfigPath(), []byte(tc.json), 0o600); err != nil {
t.Fatal(err)
}
cfg := LoadTUIConfig()
if cfg.PollMs != tc.want {
t.Errorf("PollMs = %d, want %d", cfg.PollMs, tc.want)
}
})
}
}

func TestMarkSetupDoneWritesTimestamp(t *testing.T) {
t.Setenv("HOME", t.TempDir())
MarkSetupDone()
Expand Down