ai-chatbot/tests/routes/tvstar-session.test.ts

31 lines
1.8 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { mergeTVstarSessions, publicTVstarSnapshot, tvstarSessionSchema } from "@/lib/video-canvas/tvstar-session";
const session = tvstarSessionSchema.parse({
id: "11111111-1111-4111-8111-111111111111", title: "毛笔广告", goal: "做 15 秒毛笔广告",
mode: "full", createdAt: 1000, updatedAt: 2000,
messages: [{ id: "m1", role: "user", content: "暖光书房", createdAt: 1001 }],
references: [{ id: "r1", title: "私有素材", url: "https://private.example/video.mp4", type: "video" }],
shots: [{ shot: "01", duration: "5s", scene: "书房", sceneDescription: "毛笔入画", shotSize: "特写", lighting: "暖光", dialogue: "", backgroundMusic: "", voiceAndSfx: "", cameraMovement: "缓推", imagePrompt: "墨汁", motionPrompt: "缓推", keyframeUrl: "https://private.example/key.png" }],
});
test("TVstar merges server and browser history by revision without losing a newer local turn", () => {
const older = { ...session, updatedAt: 1500, messages: [] };
expect(mergeTVstarSessions([session], [older])).toEqual([session]);
const newer = { ...session, updatedAt: 3000, title: "云端续聊" };
expect(mergeTVstarSessions([session], [newer])).toEqual([newer]);
});
test("TVstar public snapshot excludes private media references and generation prompts", () => {
const publicSnapshot = publicTVstarSnapshot(session);
const text = JSON.stringify(publicSnapshot);
expect(text).toContain("暖光书房");
expect(text).toContain("毛笔入画");
expect(text).not.toContain("private.example");
expect(text).not.toContain("imagePrompt");
});
test("TVstar rejects oversized session payloads", () => {
expect(tvstarSessionSchema.safeParse({ ...session, goal: "a".repeat(12_001) }).success).toBe(false);
});