diff --git a/internal/tui/main_test.go b/internal/tui/main_test.go index b9fb7afc..6fc9cfd6 100644 --- a/internal/tui/main_test.go +++ b/internal/tui/main_test.go @@ -2,9 +2,16 @@ package tui import ( "testing" + "time" "github.com/yetone/magpie/internal/testenv" ) -// The tests run in a home of their own, never the user's real files. -func TestMain(m *testing.M) { testenv.Main(m) } +// The tests run in a home of their own, never the user's real files, and in +// UTC, the zone the sessions fixtures' days are counted in. The zone is set +// here, before any test starts a goroutine: a test that swapped it would race +// the gateway's loops an earlier test left running, which read time.Local. +func TestMain(m *testing.M) { + time.Local = time.UTC + testenv.Main(m) +} diff --git a/internal/tui/sessions_test.go b/internal/tui/sessions_test.go index abef2113..3761bcaf 100644 --- a/internal/tui/sessions_test.go +++ b/internal/tui/sessions_test.go @@ -14,7 +14,8 @@ import ( ) // sessionsHome puts the sessions package's fixtures where Claude Code and -// Codex keep their sessions, in a sandbox HOME, their models priced. +// Codex keep their sessions, in a sandbox HOME, their models priced. Their +// days are counted in UTC, which TestMain sets for the package. func sessionsHome(t *testing.T) { t.Helper() h := home(t) @@ -26,8 +27,7 @@ func sessionsHome(t *testing.T) { } t.Setenv(env, dir) } - oldZone, oldPrice := time.Local, sessions.PriceOf - time.Local = time.UTC + oldPrice := sessions.PriceOf sessions.PriceOf = func(_ settings.Settings, m string) (catalog.Price, bool) { switch m { case "claude-opus-5-5": @@ -39,9 +39,9 @@ func sessionsHome(t *testing.T) { } t.Cleanup(func() { // the page's index is written behind it: let that write finish before - // the zone it reads (a stat of the file it writes) goes back + // the prices it reads go back sessions.Reset() - time.Local, sessions.PriceOf = oldZone, oldPrice + sessions.PriceOf = oldPrice }) sessions.Reset() }