Production state
This commit is contained in:
@@ -3,9 +3,11 @@ package comicanimator
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -40,7 +42,7 @@ func TestValidateWebP(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTemplatesExecute(t *testing.T) {
|
||||
if err := template.Must(template.New("tool").Parse(toolPage)).Execute(&bytes.Buffer{}, map[string]any{"CSRF": "x", "Duration": 6, "AspectRatio": "16:9"}); err != nil {
|
||||
if err := template.Must(template.New("tool").Parse(toolPage)).Execute(&bytes.Buffer{}, map[string]any{"CSRF": "x", "Duration": 6}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := template.Must(template.New("instructor").Parse(instructorPage)).Execute(&bytes.Buffer{}, map[string]any{"Outputs": []outputFile{{Name: "safe.mp4", Size: 10, Modified: time.Now()}}}); err != nil {
|
||||
@@ -48,6 +50,47 @@ func TestTemplatesExecute(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSystemPromptReloadsFromFile(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "system-prompt.txt")
|
||||
if err := os.WriteFile(path, []byte("first prompt\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tool := &Tool{cfg: Config{PromptFile: path}}
|
||||
prompt, err := tool.systemPrompt()
|
||||
if err != nil || prompt != "first prompt" {
|
||||
t.Fatalf("first load = %q, %v", prompt, err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte("second prompt\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prompt, err = tool.systemPrompt()
|
||||
if err != nil || prompt != "second prompt" {
|
||||
t.Fatalf("reloaded prompt = %q, %v", prompt, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSystemPromptRejectsEmptyFile(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "system-prompt.txt")
|
||||
if err := os.WriteFile(path, []byte(" \n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := (&Tool{cfg: Config{PromptFile: path}}).systemPrompt(); err == nil {
|
||||
t.Fatal("empty system prompt accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStudentCompletedCardUsesGenerationMediaRoutes(t *testing.T) {
|
||||
tool := &Tool{}
|
||||
response := httptest.NewRecorder()
|
||||
tool.renderCard(response, Generation{ID: "gen_test", Status: Completed}, false)
|
||||
body := response.Body.String()
|
||||
for _, route := range []string{`src="generations/gen_test/video"`, `href="generations/gen_test/download"`} {
|
||||
if !strings.Contains(body, route) {
|
||||
t.Errorf("student generation card missing %q", route)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVideoSignatures(t *testing.T) {
|
||||
mp4 := append([]byte{0, 0, 0, 16}, []byte("ftypisom")...)
|
||||
if !validVideoHeader("video/mp4", mp4) {
|
||||
|
||||
Reference in New Issue
Block a user