| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | "net/http/httptest" |
| 9 | "testing" |
| 10 | |
| 11 | "reasonix/internal/config" |
| 12 | "reasonix/internal/netclient" |
| 13 | ) |
| 14 | |
| 15 | func TestProbeProviderConnectionUsesRequestLocalCredentialAndNoTools(t *testing.T) { |
| 16 | requests := 0 |
| 17 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 18 | requests++ |
| 19 | if got := r.Header.Get("Authorization"); got != "Bearer draft-secret" { |
| 20 | t.Errorf("authorization = %q", got) |
| 21 | } |
| 22 | var body map[string]any |
| 23 | if err := json.NewDecoder(r.Body).Decode(&body); err != nil { |
| 24 | t.Error(err) |
| 25 | } |
| 26 | if _, ok := body["tools"]; ok { |
| 27 | t.Errorf("probe request exposed tools: %+v", body["tools"]) |
| 28 | } |
| 29 | w.Header().Set("Content-Type", "text/event-stream") |
| 30 | _, _ = fmt.Fprint(w, "data: {\"choices\":[{\"delta\":{\"content\":\"OK\"},\"finish_reason\":\"stop\"}]}\n\ndata: [DONE]\n\n") |
| 31 | })) |
| 32 | t.Cleanup(server.Close) |
| 33 | entry := config.ProviderEntry{Name: "draft", Kind: "openai", BaseURL: server.URL + "/v1", Model: "chat", APIKeyEnv: "DRAFT_KEY"} |
| 34 | if err := ProbeProviderConnection(context.Background(), entry, "draft-secret", netclient.ProxySpec{Mode: netclient.ModeOff}); err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | if requests != 1 { |
| 38 | t.Fatalf("requests = %d, want 1", requests) |
| 39 | } |
| 40 | } |
| 41 |