* feat: add DimAgent subscription support Add OAuth PKCE login with automatic and pasted callbacks, account management, model discovery, quota reporting and gateway integration. Safely rotate credentials during concurrent requests and preserve fresh tokens when updating model caches. Cover protocol, provider, GUI and callback behavior with regression tests. * dimagent: a refresh hiccup inside the day's lead keeps the token that still runs The fallback checked !dimagentNearExpiry, which is false whenever a refresh runs at all, so a 5xx/timeout on /oauth/token failed every request for the last 24h of a still-valid token. A 401/403 still lapses the account. * dimagent: review tests (sign forwarding, parallel refresh once, hiccup in lead, LoginUsage) * dimagent: signing in again takes the callback port from the sign-in it replaces StartSignIn begins the new flow before it cancels the old one, so the new flow's listen on 54321 failed (ignored) and the old listener then shut down a second later: the browser's callback was refused and only pasting could finish. The older DimAgent flow is now ended and its server closed first, and the listen retried briefly while the port is let go. * dimagent: the fake-upstream tests get a name of their own --------- Co-authored-by: yetone <yetoneful@gmail.com>
33 lines
1023 B
Go
33 lines
1023 B
Go
package dimagent
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
// The upstream answering well with an empty list is what an account whose
|
|
// subscription has ended gets; that is its state, not a broken reply, so the
|
|
// two say apart (the vendor's dim envelope wraps an OpenAI list).
|
|
func TestModelInfosEmptyIsErrNoModels(t *testing.T) {
|
|
for _, body := range []string{
|
|
`{"data":[],"success":true}`,
|
|
`{"object":"list","data":[]}`,
|
|
} {
|
|
_, err := ModelInfos([]byte(body))
|
|
if !errors.Is(err, ErrNoModels) {
|
|
t.Fatalf("%s: err = %v, want ErrNoModels", body, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A list whose every entry is a placeholder the upstream keeps for its own
|
|
// pickers ("auto", "default", an empty id) says how many it held, rather
|
|
// than as if the account had listed nothing.
|
|
func TestModelInfosUnroutableSaysCount(t *testing.T) {
|
|
_, err := ModelInfos([]byte(`{"data":[{"id":"auto"},{"id":"default"},{"id":""}]}`))
|
|
if err == nil || errors.Is(err, ErrNoModels) {
|
|
t.Fatalf("err = %v, want the unroutable count", err)
|
|
}
|
|
t.Log(err)
|
|
}
|