The preserved local work adds PopiNewAPI billing checkout, gateway account binding, and matching web console/pricing surfaces on top of the current test-server baseline. During the merge, the start-end video helpers from the deployed baseline were kept alongside the actionGenerate prompt handling from the WIP.
Constraint: Current usable baseline is 7054436, already deployed on the test server.
Rejected: Commit the WIP before syncing the baseline | would have hidden conflicts with the deployed start-end-frame changes.
Confidence: medium
Scope-risk: broad
Directive: Do not deploy this commit to the test server without rechecking gateway credentials and billing checkout behavior in that environment.
Tested: go test ./...
Tested: make build
Tested: cd web && npm run build
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGenerateSpeechRefsUsesAudioSpeechEndpoint(t *testing.T) {
|
|
var gotPath string
|
|
var gotBody map[string]any
|
|
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gotPath = r.URL.Path
|
|
if err := json.NewDecoder(r.Body).Decode(&gotBody); err != nil {
|
|
t.Fatalf("decode request body: %v", err)
|
|
}
|
|
w.Header().Set("Content-Type", "audio/mpeg")
|
|
_, _ = w.Write([]byte("fake-mp3"))
|
|
}))
|
|
defer srv.Close()
|
|
|
|
client := &newAPIClient{
|
|
baseURL: strings.TrimRight(srv.URL, "/"),
|
|
httpClient: srv.Client(),
|
|
}
|
|
|
|
refs, _, err := client.generateSpeechRefs(context.Background(), "sk-test", "speech-2.8-hd", map[string]any{
|
|
"prompt": "今天想去上海走一走。",
|
|
"format": "mp3",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("generateSpeechRefs: %v", err)
|
|
}
|
|
if gotPath != "/v1/audio/speech" {
|
|
t.Fatalf("unexpected path: %s", gotPath)
|
|
}
|
|
if gotBody["model"] != "speech-2.8-hd" || gotBody["input"] != "今天想去上海走一走。" || gotBody["response_format"] != "mp3" {
|
|
t.Fatalf("unexpected body: %#v", gotBody)
|
|
}
|
|
if len(refs) != 1 || refs[0].Kind != "data_url" || refs[0].ContentType != "audio/mpeg" {
|
|
t.Fatalf("unexpected refs: %#v", refs)
|
|
}
|
|
}
|
|
|
|
func TestDecodeSpeechGenerationResponseAcceptsNumericErrorCode(t *testing.T) {
|
|
_, _, err := decodeSpeechGenerationResponse(http.StatusBadRequest, "application/json", "mp3", []byte(`{
|
|
"error": {
|
|
"message": "minimax TTS error: 1004 - auth failed",
|
|
"type": "bad_response",
|
|
"param": "",
|
|
"code": 1004
|
|
}
|
|
}`), "speech-2.8-hd")
|
|
if err == nil || !strings.Contains(err.Error(), "auth failed") {
|
|
t.Fatalf("expected decoded upstream error, got %v", err)
|
|
}
|
|
}
|