Complete batch import v2 runtime and host capability recovery
This commit is contained in:
36
internal/host/sub2api/account_capability_repair.go
Normal file
36
internal/host/sub2api/account_capability_repair.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package sub2api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (c *Client) DisableOpenAIResponsesAPI(ctx context.Context, accountIDs []string) error {
|
||||
seen := map[string]struct{}{}
|
||||
for _, rawID := range accountIDs {
|
||||
accountID := strings.TrimSpace(rawID)
|
||||
if accountID == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[accountID]; ok {
|
||||
continue
|
||||
}
|
||||
seen[accountID] = struct{}{}
|
||||
|
||||
path := "/api/v1/admin/accounts/" + accountID
|
||||
payload := map[string]any{
|
||||
"extra": map[string]any{
|
||||
"openai_responses_supported": false,
|
||||
},
|
||||
}
|
||||
statusCode, _, body, err := c.perform(ctx, http.MethodPut, path, payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if statusCode < http.StatusOK || statusCode >= http.StatusMultipleChoices {
|
||||
return newHTTPError(http.MethodPut, path, statusCode, body)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -31,6 +31,7 @@ type HostAdapter interface {
|
||||
AssignSubscription(ctx context.Context, req AssignSubscriptionRequest) (SubscriptionRef, error)
|
||||
CheckGatewayAccess(ctx context.Context, req GatewayAccessCheckRequest) (GatewayAccessResult, error)
|
||||
CheckGatewayCompletion(ctx context.Context, req GatewayCompletionCheckRequest) (GatewayCompletionResult, error)
|
||||
DisableOpenAIResponsesAPI(ctx context.Context, accountIDs []string) error
|
||||
ListManagedResources(ctx context.Context, req ListManagedResourcesRequest) (ManagedResourceSnapshot, error)
|
||||
}
|
||||
|
||||
|
||||
@@ -979,6 +979,41 @@ func TestCheckGatewayCompletionWithMock(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisableOpenAIResponsesAPIWithMock(t *testing.T) {
|
||||
var calls []string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
calls = append(calls, r.Method+" "+r.URL.Path)
|
||||
if r.Method != http.MethodPut {
|
||||
t.Fatalf("method = %q, want PUT", r.Method)
|
||||
}
|
||||
var payload struct {
|
||||
Extra map[string]any `json:"extra"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
if got, ok := payload.Extra["openai_responses_supported"].(bool); !ok || got {
|
||||
t.Fatalf("openai_responses_supported = %+v, want false", payload.Extra["openai_responses_supported"])
|
||||
}
|
||||
w.Write([]byte(`{"data":{"id":1}}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
client, _ := NewClient(srv.URL, WithAPIKey("k"))
|
||||
if err := client.DisableOpenAIResponsesAPI(context.Background(), []string{"101", "101", " ", "102"}); err != nil {
|
||||
t.Fatalf("DisableOpenAIResponsesAPI() error = %v", err)
|
||||
}
|
||||
if len(calls) != 2 {
|
||||
t.Fatalf("calls = %v, want 2 unique account updates", calls)
|
||||
}
|
||||
if calls[0] != "PUT /api/v1/admin/accounts/101" {
|
||||
t.Fatalf("first call = %q, want PUT /api/v1/admin/accounts/101", calls[0])
|
||||
}
|
||||
if calls[1] != "PUT /api/v1/admin/accounts/102" {
|
||||
t.Fatalf("second call = %q, want PUT /api/v1/admin/accounts/102", calls[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestBatchCreateAccountsWithMock(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
|
||||
Reference in New Issue
Block a user