provider tests: TestClaudeSavedAccountDir and the other sign-in tests wait up to 90s for the sign-in to end, not 2s (#1552)

waitDone gave a sign-in 100 x 20ms (about 2s) to leave "waiting". The
sign-ins it waits on that finish through the browser callback (Claude's
SavedAccountDir, AddsAnAccount and logout tests among them) run fake CLIs:
after the callback the fake `claude auth login` polls 50ms, forks
cat/echo/rm/kill, exits, and magpie then runs the fake's `auth status`
before it records the account. Alone that is a few hundred ms; under a full
`go test ./...` on a loaded Mac (where every new executable is also checked
on its first run) it passed 2s, and the test failed with "sign-in never
finished" after 3.45s. The paste-path tests didn't fail because
claudePaste itself waits up to a minute for the end.

waitDone now polls against a 90s wall-clock deadline: above every bound
the flows keep themselves (claudePaste's minute, claudeSignedIn's 15s), so
a flow that times out reports it in its own state; it still returns the
moment the state changes, and still fails a sign-in that never ends.

Reproduced by injecting the delay, not rerunning: with `sleep 2.5` added
to the fake before "Login successful.", TestClaudeSavedAccountDir failed
on the old waitDone ("sign-in never finished", 2.53s) and passed with the
new one, as did TestClaudeSignIn*, TestClaudeSavedAccountDir and the
logout test. The injection is not committed. No fake was left running
afterwards (ps); the fake's own loop already ends once its folder is gone
(38a0f4709).

Run: gofmt -l; go vet -tags nogui (darwin, GOOS=linux, GOOS=windows)
./internal/provider; go test -tags nogui ./internal/provider;
go test -tags nogui ./... (full suite).
This commit is contained in:
yetone
2026-10-11 09:40:38 +08:00
parent 6f4fb883eb
commit c702d9cfe1
+16 -5
View File
@@ -33,16 +33,27 @@ func finishInBrowser(t *testing.T, st SignInState, code string) string {
return string(b)
}
// signInDeadline is how long waitDone waits for a sign-in to end. Most of
// these sign-ins run fake CLIs (a `claude auth login`, `devin`, ...) that
// fork a shell, its cat/echo/rm, and then magpie's own `auth status` probe:
// a few hundred ms alone, but seconds while `go test ./...` runs every
// package's binaries at once (and macOS checks each new executable on its
// first run). 2s was not enough (#1552). The deadline sits above every
// bound the flows keep themselves (claudePaste's minute, claudeSignedIn's
// 15s), so a flow that times out says so in its own state, not here.
const signInDeadline = 90 * time.Second
// waitDone waits for sign-in id to leave "waiting" and returns its state.
// It returns as soon as it does, so the deadline only costs time when a
// sign-in really never ends.
func waitDone(t *testing.T, id string) SignInState {
t.Helper()
for i := 0; i < 100; i++ {
st, _ := SignInStatus(id)
if st.State != "waiting" {
for end := time.Now().Add(signInDeadline); time.Now().Before(end); time.Sleep(20 * time.Millisecond) {
if st, _ := SignInStatus(id); st.State != "waiting" {
return st
}
time.Sleep(20 * time.Millisecond)
}
t.Fatal("sign-in never finished")
t.Fatalf("sign-in never finished in %s", signInDeadline)
return SignInState{}
}