From 4a6bf80f48cf26781403f2825963d9fb086202a0 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Oct 2026 20:30:55 +0800 Subject: [PATCH] provider: TestFetchingNewForgottenWhileListed forgets Cursor in the page's listing only (#2390) Red on ubuntu CI at a1f7b8c13 (run 38722019804): "a CLI forgotten while the accounts were listed, and FetchingNew says none is on its way". Cause, in the test: its GrokExecutable stand-in forgot Cursor on the first call made by any goroutine in the process, and Cursor's stand-in ask answered "nobody" at once. A read another test left running (a usage refresh, fetchSubscriptionUsage, reads Cursor's identity and then Grok's account, uncounted, after its caller returned) could take that first call. Cursor was then forgotten and settled again before FetchNewBehind's listing read it: both identitiesUnsettled checks were false and nothing was due, so FetchingNew was rightly false. The code is right in that interleaving; the test assumed only its own listing reads the accounts. Fix: the forget fires only on a GrokExecutable call made under FetchNewBehind (checked on the call's stack), and Cursor's ask answers only after the test has read FetchingNew, so a foreign read after the forget can't settle it either. The cleanup releases the ask before it waits for the fetch. Broken by hand: - the old test with a goroutine doing GrokExecutable(); cursorIdentity() before FetchNewBehind: red with CI's exact message (0.03s). The fixed test with the same injection: green. - stack gate kept, ask back to answering nobody at once, and a foreign cursorIdentity() run right after the forget: red with CI's message. The fixed test with the same foreign read: green. The exact leftover goroutine on CI wasn't captured; goroutine dumps at the test's start were clean in green runs on macOS and in a Linux arm64 container, so the reader is inferred from who calls both paths. Run at a1f7b8c13, go1.26.8 darwin/arm64: - go test -count=1 -timeout 45m ./internal/provider: ok (446.8s) - go test -race -count=50 -run 'TestFetchingNewForgottenWhileListed$' ./internal/provider: ok - gofmt -l internal/provider: clean - go vet ./internal/provider/... on darwin, GOOS=linux -tags nogui and GOOS=windows: ok --- internal/provider/fetching_new_test.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/provider/fetching_new_test.go b/internal/provider/fetching_new_test.go index 32797d3ed..4869611f3 100644 --- a/internal/provider/fetching_new_test.go +++ b/internal/provider/fetching_new_test.go @@ -5,6 +5,7 @@ import ( "net/http/httptest" "path/filepath" "runtime" + "strings" "sync" "testing" "time" @@ -207,7 +208,12 @@ func TestFetchingNewOnceStarted(t *testing.T) { // A CLI forgotten while the Providers page's FetchNewBehind lists the // accounts (a sign-in finishing then) left its account out of that list: // the fetch is asked behind the page, which is told lists are on their -// way, not that none is due. +// way, not that none is due. The forget is that listing's own, and the CLI +// answers only once the page was told: a read another test left running +// (a usage refresh reads Grok's account, then Cursor's) took the first +// GrokExecutable call, forgot Cursor before the listing read it, and +// Cursor answered nobody at once, so nothing was left to wait on and +// nothing was due (#2390, red on ubuntu CI). func TestFetchingNewForgottenWhileListed(t *testing.T) { isolate(t) home := t.TempDir() @@ -220,26 +226,36 @@ func TestFetchingNewForgottenWhileListed(t *testing.T) { newFetches.Unlock() newSoonAt.Store(0) ForgetAccounts() + answer := make(chan struct{}) + answered := sync.OnceFunc(func() { close(answer) }) wasCursor, wasDevin, wasGrok := cursorStatus, devinStatus, GrokExecutable t.Cleanup(func() { + answered() waitFetchingNew(t) cursorStatus, devinStatus, GrokExecutable = wasCursor, wasDevin, wasGrok ForgetAccounts() }) nobody := func() (string, string, bool, error) { return "", "", false, nil } now := time.Now() - cursor := &cliIdentity{name: "cursor-test", exe: func() string { return "" }, read: true, at: now, ask: nobody} + // asked again once forgotten, Cursor answers after the page was told + cursor := &cliIdentity{name: "cursor-test", exe: func() string { return "" }, read: true, at: now, + ask: func() (string, string, bool, error) { <-answer; return nobody() }} cursorStatus = cursor devinStatus = &cliIdentity{name: "devin-test", exe: func() string { return "" }, read: true, at: now, ask: nobody} - // Grok's account is read after Cursor's: the sign-in lands there + // Grok's account is read after Cursor's: the sign-in lands there, in + // the page's own listing, not in anything else reading the accounts var once sync.Once GrokExecutable = func() string { - once.Do(cursor.forget) + b := make([]byte, 64<<10) + if strings.Contains(string(b[:runtime.Stack(b, false)]), "provider.FetchNewBehind(") { + once.Do(cursor.forget) + } return "" } FetchNewBehind(5 * time.Second) busy := FetchingNew() + answered() waitFetchingNew(t) if !busy { t.Fatal("a CLI forgotten while the accounts were listed, and FetchingNew says none is on its way")