-
Notifications
You must be signed in to change notification settings - Fork 11.3k
feat: support qiniu ai provider #4251
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/QuantumNous/new-api/common" | ||
| "github.com/QuantumNous/new-api/constant" | ||
| "github.com/QuantumNous/new-api/model" | ||
| ) | ||
|
|
||
| func TestFetchChannelUpstreamModelIDs_Qiniu(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodGet { | ||
| t.Fatalf("unexpected method: %s", r.Method) | ||
| } | ||
| if r.URL.Path != "/v1/models" { | ||
| t.Fatalf("unexpected path: %s", r.URL.Path) | ||
| } | ||
| if got := r.Header.Get("Authorization"); got != "Bearer test-key" { | ||
| t.Fatalf("unexpected Authorization header: %q", got) | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| _, _ = w.Write([]byte(`{"object":"list","data":[{"id":"deepseek/deepseek-v3.1-terminus-thinking"},{"id":"gpt-4"}]}`)) | ||
| })) | ||
| defer srv.Close() | ||
|
|
||
| ch := &model.Channel{ | ||
| Id: 123, | ||
| Type: constant.ChannelTypeQiniu, | ||
| Key: "test-key", | ||
| Status: common.ChannelStatusEnabled, | ||
| BaseURL: common.GetPointer[string](srv.URL), | ||
| } | ||
|
|
||
| got, err := fetchChannelUpstreamModelIDs(ch) | ||
| if err != nil { | ||
| t.Fatalf("fetchChannelUpstreamModelIDs returned error: %v", err) | ||
| } | ||
| if len(got) != 2 || got[0] != "deepseek/deepseek-v3.1-terminus-thinking" || got[1] != "gpt-4" { | ||
| t.Fatalf("unexpected models: %#v", got) | ||
| } | ||
| } | ||
|
|
||
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
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
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.
🧩 Analysis chain
🌐 Web query:
Go testing package docs: can t.Fatalf (or t.FailNow) be called from a goroutine created by the test, such as an httptest server handler goroutine?💡 Result:
No. In Go tests, t.Fatalf/t.FailNow (and t.Fatal/t.FailNow/t.SkipNow variants) must be called only from the goroutine running the test function; calling them from other goroutines created by the test (for example, an httptest server handler goroutine) is explicitly disallowed and can lead to race conditions and incorrect behavior. What the docs say: FailNow “stops its execution by calling runtime.Goexit” in the current goroutine, and “FailNow must be called from the goroutine running the test or benchmark function, not from other goroutines created during the test. Calling FailNow does not stop those other goroutines.” The general “test ends when … calls any of … T.FailNow, T.Fatal, T.Fatalf …” plus “must be called only from the goroutine running the Test function” language likewise applies. Safe patterns: - From goroutine(s) spawned during the test, use t.Errorf/t.Fail (non-fatal) or otherwise report via channels/WaitGroups and have the main test goroutine call Fatalf/FailNow. - For httptest handlers, avoid calling t.Fatal/Fatalf directly in the handler; instead signal failure back to the test goroutine (e.g., send an error on a channel), then fail in the test goroutine. If you need, I can show a small channel-based example for httptest handlers.
Citations:
Replace
t.Fatalfcalls in the handler goroutine with HTTP error responses.Calling
t.Fatalffrom within thehttptesthandler goroutine violates Go testing semantics. Per thetestingpackage documentation,t.Fatalfandt.FailNowmust only be called from the test goroutine itself; calling them from spawned goroutines (including handlers) can cause race conditions and unreliable test failures. Return an HTTP error status from the handler and perform assertions in the main test goroutine instead.Suggested adjustment
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { - t.Fatalf("unexpected method: %s", r.Method) + http.Error(w, "unexpected method", http.StatusBadRequest) + return } if r.URL.Path != "/v1/models" { - t.Fatalf("unexpected path: %s", r.URL.Path) + http.Error(w, "unexpected path", http.StatusBadRequest) + return } if got := r.Header.Get("Authorization"); got != "Bearer test-key" { - t.Fatalf("unexpected Authorization header: %q", got) + http.Error(w, "unexpected Authorization header", http.StatusUnauthorized) + return }🤖 Prompt for AI Agents