Expose gateway billing flows from the synced server baseline
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
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenerateMusicRefsUsesMusicGenerationsEndpoint(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", "application/json")
|
||||
_, _ = w.Write([]byte(`{
|
||||
"audio_url": "https://example.com/music-output.mp3",
|
||||
"status": 2,
|
||||
"extra_info": {
|
||||
"music_duration": 34,
|
||||
"music_sample_rate": 44100,
|
||||
"music_channel": 2,
|
||||
"bitrate": 256000,
|
||||
"music_size": 1098543
|
||||
}
|
||||
}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
client := &newAPIClient{
|
||||
baseURL: strings.TrimRight(srv.URL, "/"),
|
||||
httpClient: srv.Client(),
|
||||
}
|
||||
|
||||
refs, usage, err := client.generateMusicRefs(context.Background(), "sk-test", "music-2.6", map[string]any{
|
||||
"prompt": "lofi rainy night piano",
|
||||
"is_instrumental": true,
|
||||
"output_format": "url",
|
||||
"audio_setting": map[string]any{
|
||||
"format": "mp3",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("generateMusicRefs: %v", err)
|
||||
}
|
||||
if gotPath != "/v1/music/generations" {
|
||||
t.Fatalf("unexpected path: %s", gotPath)
|
||||
}
|
||||
if gotBody["model"] != "music-2.6" {
|
||||
t.Fatalf("unexpected model: %#v", gotBody["model"])
|
||||
}
|
||||
if gotBody["is_instrumental"] != true {
|
||||
t.Fatalf("unexpected is_instrumental: %#v", gotBody["is_instrumental"])
|
||||
}
|
||||
if len(refs) != 1 || refs[0].URL != "https://example.com/music-output.mp3" || refs[0].ContentType != "audio/mpeg" {
|
||||
t.Fatalf("unexpected refs: %#v", refs)
|
||||
}
|
||||
if usage["music_duration"] != float64(34) {
|
||||
t.Fatalf("unexpected usage: %#v", usage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeMusicGenerationResponseAcceptsNumericErrorCode(t *testing.T) {
|
||||
_, _, err := decodeMusicGenerationResponse(http.StatusBadRequest, "application/json", []byte(`{
|
||||
"error": {
|
||||
"message": "minimax music error: 1004 - auth failed",
|
||||
"type": "bad_response",
|
||||
"param": "",
|
||||
"code": 1004
|
||||
}
|
||||
}`), "music-2.6")
|
||||
if err == nil || !strings.Contains(err.Error(), "auth failed") {
|
||||
t.Fatalf("expected decoded upstream error, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user