Resolve authentication diagnostics by provider

This commit is contained in:
2026-11-22 18:16:13 +00:00
parent adc700f96e
commit ca8cf1b827
10 changed files with 123 additions and 38 deletions

View File

@@ -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{}