Resolve authentication diagnostics by provider
This commit is contained in:
@@ -5,13 +5,40 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func TestSmokeAuthenticationUsesProviderDefault(t *testing.T) {
|
||||
var path string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
path = r.URL.Path
|
||||
fmt.Fprint(w, `{"data":{"label":"member","is_free_tier":false,"usage":0}}`)
|
||||
}))
|
||||
defer server.Close()
|
||||
input := configkit.Input{Destination: configkit.Keys("promptkit"), Source: configkit.Mapping("diagnostic", map[string]any{
|
||||
"backends": []any{map[string]any{"id": "renamed", "provider": "openrouter", "endpoint": server.URL + "/v1"}},
|
||||
})}
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &input}}, promptkit.WithBundledOpenRouter(false))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inspection, err := engine.InspectBackend(context.Background(), "renamed")
|
||||
if err != nil || inspection.SmokeTests != nil {
|
||||
t.Fatalf("declared metadata: %+v, %v", inspection, err)
|
||||
}
|
||||
report, err := engine.SmokeTest(context.Background(), promptkit.SmokeTestRequest{Kind: promptkit.SmokeTestAuthentication, BackendID: "renamed"})
|
||||
if err != nil || !report.Supported || !report.Completed || path != "/v1/key" || report.Facts.CredentialsAccepted == nil || !*report.Facts.CredentialsAccepted {
|
||||
t.Fatalf("report=%+v path=%q err=%v", report, path, err)
|
||||
}
|
||||
}
|
||||
|
||||
type gatedSmokeClient struct {
|
||||
started chan promptkit.GenerateRequest
|
||||
release <-chan struct{}
|
||||
|
||||
Reference in New Issue
Block a user