refactor: stabilize runtime and unify config

This commit is contained in:
lpf
2026-03-14 21:40:12 +08:00
parent 60eee65fec
commit 341e578c9f
75 changed files with 3081 additions and 1627 deletions

View File

@@ -0,0 +1,33 @@
package providers
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestHTTPProviderExecuteJSONAttemptsReturnsEnvelope(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if got := r.Header.Get("Authorization"); got != "Bearer token" {
t.Fatalf("authorization = %q", got)
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"ok":true}`))
}))
defer server.Close()
provider := NewHTTPProvider("test", "token", server.URL, "gpt-test", false, "bearer", 5*time.Second, nil)
result, err := provider.executeJSONAttempts(context.Background(), server.URL, map[string]any{"hello": "world"}, nil, classifyOAuthFailure)
if err != nil {
t.Fatalf("executeJSONAttempts error: %v", err)
}
if result.StatusCode != http.StatusOK || result.ContentType != "application/json" || result.AttemptKind != "api_key" {
t.Fatalf("unexpected envelope: %+v", result)
}
if string(result.Body) != `{"ok":true}` {
t.Fatalf("unexpected body: %s", string(result.Body))
}
}