feat(server): dispatch /v1/videos/sync by model #1

Merged
steve merged 2 commits from feat/video-routes into main 2026-07-12 14:13:05 +00:00
2 changed files with 48 additions and 0 deletions
Showing only changes of commit cecb89880e - Show all commits
+5
View File
@@ -80,6 +80,11 @@ var modelPostJSONRoutes = []string{
var modelPostFormRoutes = []string{
"/v1/audio/transcriptions",
"/v1/images/edits",
// video generation (vLLM-Omni / OpenAI videos shape); extraction is
// content-type driven, so JSON bodies dispatch on these paths too
"/v1/videos",
"/v1/videos/sync",
}
// modelGetRoutes are model-dispatched GET endpoints (the model arrives as a
+43
View File
@@ -1,9 +1,11 @@
package server
import (
"bytes"
"context"
"encoding/json"
"io"
"mime/multipart"
"net/http"
"net/http/httptest"
"strings"
@@ -339,3 +341,44 @@ func TestServer_LogStream_UnknownID_Returns400(t *testing.T) {
t.Errorf("status=%d want 400", w.Code)
}
}
func TestServer_VideoRoutesDispatch(t *testing.T) {
s := newTestServer(
newStubRouter([]string{"videogen-model"}, "video response"),
newStubRouter(nil, ""),
)
// JSON body on /v1/videos.
body := strings.NewReader(`{"model":"videogen-model","prompt":"a cat"}`)
req := httptest.NewRequest(http.MethodPost, "/v1/videos", body)
req.Header.Set("Content-Type", "application/json")
w := httptest.NewRecorder()
s.ServeHTTP(w, req)
if w.Code != http.StatusOK || w.Body.String() != "video response" {
t.Fatalf("/v1/videos: status=%d body=%q", w.Code, w.Body.String())
}
// Multipart form on /v1/videos/sync.
var buf bytes.Buffer
mw := multipart.NewWriter(&buf)
mw.WriteField("model", "videogen-model")
mw.WriteField("prompt", "a cat")
mw.Close()
req = httptest.NewRequest(http.MethodPost, "/v1/videos/sync", &buf)
req.Header.Set("Content-Type", mw.FormDataContentType())
w = httptest.NewRecorder()
s.ServeHTTP(w, req)
if w.Code != http.StatusOK || w.Body.String() != "video response" {
t.Fatalf("/v1/videos/sync: status=%d body=%q", w.Code, w.Body.String())
}
// Unknown model on a video route still 404s.
body = strings.NewReader(`{"model":"nope","prompt":"a cat"}`)
req = httptest.NewRequest(http.MethodPost, "/v1/videos", body)
req.Header.Set("Content-Type", "application/json")
w = httptest.NewRecorder()
s.ServeHTTP(w, req)
if w.Code != http.StatusNotFound {
t.Fatalf("/v1/videos unknown model: status=%d want 404", w.Code)
}
}