feat: integrate creator hub douyin workflows

This commit is contained in:
2026-09-14 19:22:07 +08:00
parent 025fe62c37
commit 44a28954cf
42 changed files with 2850 additions and 880 deletions
+18 -25
View File
@@ -2,52 +2,45 @@ package main
import (
"context"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
)
func TestDownloadCreatorMaterialPublishesOnlyCompleteFiles(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/source" {
t.Fatalf("unexpected path: %s", r.URL.Path)
}
_, _ = w.Write([]byte("media"))
}))
defer server.Close()
func TestWriteCreatorMediaPublishesOnlyCompleteFiles(t *testing.T) {
destination := filepath.Join(t.TempDir(), "source")
if err := downloadCreatorMaterial(context.Background(), server.URL+"/source", destination); err != nil {
t.Fatalf("download material: %v", err)
if err := writeCreatorMedia(destination, []byte("media")); err != nil {
t.Fatalf("write media: %v", err)
}
content, err := os.ReadFile(destination)
if err != nil {
t.Fatalf("read material: %v", err)
t.Fatalf("read media: %v", err)
}
if string(content) != "media" {
t.Fatalf("unexpected material: %q", content)
t.Fatalf("unexpected media: %q", content)
}
if _, err := os.Stat(destination + ".tmp"); !os.IsNotExist(err) {
t.Fatalf("temporary file remains: %v", err)
matches, err := filepath.Glob(filepath.Join(filepath.Dir(destination), ".creator-media-*"))
if err != nil {
t.Fatalf("find temporary media: %v", err)
}
if len(matches) != 0 {
t.Fatalf("temporary files remain: %v", matches)
}
}
func TestDownloadCreatorMaterialRejectsInvalidResponses(t *testing.T) {
server := httptest.NewServer(http.NotFoundHandler())
defer server.Close()
if err := downloadCreatorMaterial(context.Background(), server.URL, filepath.Join(t.TempDir(), "source")); err == nil {
t.Fatal("expected HTTP failure")
func TestWriteCreatorMediaRejectsEmptyAndOversizedFiles(t *testing.T) {
destination := filepath.Join(t.TempDir(), "source")
if err := writeCreatorMedia(destination, nil); err == nil {
t.Fatal("expected empty media to be rejected")
}
if err := downloadCreatorMaterial(context.Background(), "file:///tmp/source", filepath.Join(t.TempDir(), "source")); err == nil {
t.Fatal("expected non-HTTP URL failure")
if err := writeCreatorMedia(destination, make([]byte, maxCreatorMediaBytes+1)); err == nil {
t.Fatal("expected oversized media to be rejected")
}
}
func TestTranscribeCreatorAudioRequiresExplicitProvider(t *testing.T) {
t.Setenv("CREATOR_TRANSCRIPTION_BIN", "")
if _, err := transcribeCreatorAudio(context.Background(), "/tmp/audio.wav"); err == nil {
if _, err := transcribeCreatorAudio(context.Background(), "/tmp/audio.wav", "base"); err == nil {
t.Fatal("expected missing provider error")
}
}