claudeSignedOut and claudeLoginVersion run for every saved Claude account
on each Providers poll (Logins, claudeStandIn), and each parsed the
sign-in whole through parseClaudeCredentials: a map[string]any, then a
Marshal and Unmarshal of claudeAiOauth. With real accounts that was
15.5 MB of what forty polls allocated. What they read of it, whether it
parses as a sign-in and its version, is now kept by the sign-in's bytes
(claudeAuthOf), at most 64; the bytes change only when the account is
signed in or refreshed, and a changed sign-in is read anew.
Run on mote at this tree: gofmt, go vet (darwin, windows, linux) of
internal/provider ok; TestClaudeSignedOutKeepsWhatItParsed alone 3/3 ok;
broken by hand (the kept read skipped) it fails "claudeSignedOut
allocated 8023 bytes, parsing the sign-in 7127"; go test ./internal/provider
ok (117.4s).
Real accounts, sandbox HOME, 40 Providers/Agents polls (abr.sh), against
the v0.1.2496 build: parseClaudeCredentials and claudeSignedOut gone from
the profile (15.5 MB before), provider.Logins 22.0 MB -> 11.0 MB, total
517 MB -> 504 MB; /api/state and the drift reply byte-identical.
Footprint peak 139 MB (was 134-141): this change doesn't move the peak.
Not run: the gui suite (no gui file changed).
Picked onto 2640ac0f0 (internal/provider changed there in allowance_renewed, key_allowance, plugins and routing, none of the files changed here); not run again there.
43 lines
1.7 KiB
Go
43 lines
1.7 KiB
Go
package provider
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestClaudeSignedOutKeepsWhatItParsed: claudeSignedOut and
|
|
// claudeLoginVersion run for every saved Claude account on each Providers
|
|
// poll, and read a sign-in they have read before without parsing it again,
|
|
// while a sign-in changed since is read anew.
|
|
func TestClaudeSignedOutKeepsWhatItParsed(t *testing.T) {
|
|
auth := []byte(`{"claudeAiOauth":{"accessToken":"sk-ant-oat01-` + strings.Repeat("a", 100) +
|
|
`","refreshToken":"sk-ant-ort01-b","expiresAt":1,"scopes":["user:inference","user:profile"],"subscriptionType":"max"},"mcpOAuth":{"x":{"accessToken":"m"}}}`)
|
|
l := savedLogin{Agent: "claude", User: "a@example.com", Auth: auth, Lapsed: claudeAuthLapse, Refused: "old"}
|
|
parsed := allocatedBy(func() {
|
|
c, _ := parseClaudeCredentials(auth)
|
|
_ = c.version()
|
|
_, _ = parseClaudeCredentials(auth)
|
|
})
|
|
read := allocatedBy(func() { _ = claudeSignedOut(l) })
|
|
if read*4 > parsed {
|
|
t.Fatalf("claudeSignedOut allocated %d bytes, parsing the sign-in %d", read, parsed)
|
|
}
|
|
if got := claudeSignedOut(l); got != "" {
|
|
t.Fatalf("a credential other than the refused one reads %q", got)
|
|
}
|
|
c, _ := parseClaudeCredentials(auth)
|
|
l.Refused = c.version()
|
|
if got := claudeSignedOut(l); got != claudeAuthLapse {
|
|
t.Fatalf("the refused credential reads %q", got)
|
|
}
|
|
// signed in again: its new credential isn't the one refused
|
|
l.Auth = []byte(strings.Replace(string(auth), "ort01-b", "ort01-c", 1))
|
|
if got := claudeSignedOut(l); got != "" {
|
|
t.Fatalf("a credential changed since reads %q", got)
|
|
}
|
|
l.Lapsed, l.Refused, l.Auth = "", "", []byte(`{"claudeAiOauth":{"accessToken":""}}`)
|
|
if got := claudeSignedOut(l); got != claudeGoneLapse {
|
|
t.Fatalf("an emptied sign-in reads %q", got)
|
|
}
|
|
}
|