forked from router-for-me/CLIProxyAPI
-
-
Notifications
You must be signed in to change notification settings - Fork 305
v6.8.49 #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+203
−10
Merged
v6.8.49 #422
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
338321e
fix: use camelCase systemInstruction in OpenAI-to-Gemini translators
thebtf d0cc0cd
docs: add All API Hub to related projects list
qixing-jk 90afb9c
fix(auth): new OAuth accounts invisible to scheduler after dynamic re…
DragonFSKY 2e9907c
Merge pull request #1959 from thebtf/fix/system-instruction-camelcase
luispater d9c6627
Merge pull request #1963 from qixing-jk/docs/add-all-api-hub-showcase
luispater ba672bb
Merge PR #1969 into dev
luispater f5941a4
test(auth): cover scheduler refresh regression paths
luispater 7739738
Merge branch 'main' into plus
luispater File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| package auth | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/router-for-me/CLIProxyAPI/v6/internal/registry" | ||
| cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor" | ||
| ) | ||
|
|
||
| type schedulerProviderTestExecutor struct { | ||
| provider string | ||
| } | ||
|
|
||
| func (e schedulerProviderTestExecutor) Identifier() string { return e.provider } | ||
|
|
||
| func (e schedulerProviderTestExecutor) Execute(ctx context.Context, auth *Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) { | ||
| return cliproxyexecutor.Response{}, nil | ||
| } | ||
|
|
||
| func (e schedulerProviderTestExecutor) ExecuteStream(ctx context.Context, auth *Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (*cliproxyexecutor.StreamResult, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (e schedulerProviderTestExecutor) Refresh(ctx context.Context, auth *Auth) (*Auth, error) { | ||
| return auth, nil | ||
| } | ||
|
|
||
| func (e schedulerProviderTestExecutor) CountTokens(ctx context.Context, auth *Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) { | ||
| return cliproxyexecutor.Response{}, nil | ||
| } | ||
|
|
||
| func (e schedulerProviderTestExecutor) HttpRequest(ctx context.Context, auth *Auth, req *http.Request) (*http.Response, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func TestManager_RefreshSchedulerEntry_RebuildsSupportedModelSetAfterModelRegistration(t *testing.T) { | ||
| ctx := context.Background() | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| prime func(*Manager, *Auth) error | ||
| }{ | ||
| { | ||
| name: "register", | ||
| prime: func(manager *Manager, auth *Auth) error { | ||
| _, errRegister := manager.Register(ctx, auth) | ||
| return errRegister | ||
| }, | ||
| }, | ||
| { | ||
| name: "update", | ||
| prime: func(manager *Manager, auth *Auth) error { | ||
| _, errRegister := manager.Register(ctx, auth) | ||
| if errRegister != nil { | ||
| return errRegister | ||
| } | ||
| updated := auth.Clone() | ||
| updated.Metadata = map[string]any{"updated": true} | ||
| _, errUpdate := manager.Update(ctx, updated) | ||
| return errUpdate | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, testCase := range testCases { | ||
| testCase := testCase | ||
| t.Run(testCase.name, func(t *testing.T) { | ||
| manager := NewManager(nil, &RoundRobinSelector{}, nil) | ||
| auth := &Auth{ | ||
| ID: "refresh-entry-" + testCase.name, | ||
| Provider: "gemini", | ||
| } | ||
| if errPrime := testCase.prime(manager, auth); errPrime != nil { | ||
| t.Fatalf("prime auth %s: %v", testCase.name, errPrime) | ||
| } | ||
|
|
||
| registerSchedulerModels(t, "gemini", "scheduler-refresh-model", auth.ID) | ||
|
|
||
| got, errPick := manager.scheduler.pickSingle(ctx, "gemini", "scheduler-refresh-model", cliproxyexecutor.Options{}, nil) | ||
| var authErr *Error | ||
| if !errors.As(errPick, &authErr) || authErr == nil { | ||
| t.Fatalf("pickSingle() before refresh error = %v, want auth_not_found", errPick) | ||
| } | ||
| if authErr.Code != "auth_not_found" { | ||
| t.Fatalf("pickSingle() before refresh code = %q, want %q", authErr.Code, "auth_not_found") | ||
| } | ||
| if got != nil { | ||
| t.Fatalf("pickSingle() before refresh auth = %v, want nil", got) | ||
| } | ||
|
|
||
| manager.RefreshSchedulerEntry(auth.ID) | ||
|
|
||
| got, errPick = manager.scheduler.pickSingle(ctx, "gemini", "scheduler-refresh-model", cliproxyexecutor.Options{}, nil) | ||
| if errPick != nil { | ||
| t.Fatalf("pickSingle() after refresh error = %v", errPick) | ||
| } | ||
| if got == nil || got.ID != auth.ID { | ||
| t.Fatalf("pickSingle() after refresh auth = %v, want %q", got, auth.ID) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestManager_PickNext_RebuildsSchedulerAfterModelCooldownError(t *testing.T) { | ||
| ctx := context.Background() | ||
| manager := NewManager(nil, &RoundRobinSelector{}, nil) | ||
| manager.RegisterExecutor(schedulerProviderTestExecutor{provider: "gemini"}) | ||
|
|
||
| registerSchedulerModels(t, "gemini", "scheduler-cooldown-rebuild-model", "cooldown-stale-old") | ||
|
|
||
| oldAuth := &Auth{ | ||
| ID: "cooldown-stale-old", | ||
| Provider: "gemini", | ||
| } | ||
| if _, errRegister := manager.Register(ctx, oldAuth); errRegister != nil { | ||
| t.Fatalf("register old auth: %v", errRegister) | ||
| } | ||
|
|
||
| manager.MarkResult(ctx, Result{ | ||
| AuthID: oldAuth.ID, | ||
| Provider: "gemini", | ||
| Model: "scheduler-cooldown-rebuild-model", | ||
| Success: false, | ||
| Error: &Error{HTTPStatus: http.StatusTooManyRequests, Message: "quota"}, | ||
| }) | ||
|
|
||
| newAuth := &Auth{ | ||
| ID: "cooldown-stale-new", | ||
| Provider: "gemini", | ||
| } | ||
| if _, errRegister := manager.Register(ctx, newAuth); errRegister != nil { | ||
| t.Fatalf("register new auth: %v", errRegister) | ||
| } | ||
|
|
||
| reg := registry.GetGlobalRegistry() | ||
| reg.RegisterClient(newAuth.ID, "gemini", []*registry.ModelInfo{{ID: "scheduler-cooldown-rebuild-model"}}) | ||
| t.Cleanup(func() { | ||
| reg.UnregisterClient(newAuth.ID) | ||
| }) | ||
|
|
||
| got, errPick := manager.scheduler.pickSingle(ctx, "gemini", "scheduler-cooldown-rebuild-model", cliproxyexecutor.Options{}, nil) | ||
| var cooldownErr *modelCooldownError | ||
| if !errors.As(errPick, &cooldownErr) { | ||
| t.Fatalf("pickSingle() before sync error = %v, want modelCooldownError", errPick) | ||
| } | ||
| if got != nil { | ||
| t.Fatalf("pickSingle() before sync auth = %v, want nil", got) | ||
| } | ||
|
|
||
| got, executor, errPick := manager.pickNext(ctx, "gemini", "scheduler-cooldown-rebuild-model", cliproxyexecutor.Options{}, nil) | ||
| if errPick != nil { | ||
| t.Fatalf("pickNext() error = %v", errPick) | ||
| } | ||
| if executor == nil { | ||
| t.Fatal("pickNext() executor = nil") | ||
| } | ||
| if got == nil || got.ID != newAuth.ID { | ||
| t.Fatalf("pickNext() auth = %v, want %q", got, newAuth.ID) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For improved readability and to avoid multiple
RUnlockcalls, you can restructure this section. The goal is to fetch and clone the auth within a single locked block, then perform the scheduler update outside the lock. This makes the lock's scope clearer and the code flow more linear, improving maintainability.