0d207c1d95
CI/CD Pipeline / Staging E2E Tests (push) Failing after 74h48m20s
CI/CD Pipeline / Deploy Staging (push) Failing after 74h50m20s
CI/CD Pipeline / Frontend Lint (push) Failing after 74h51m50s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 74h53m4s
CI/CD Pipeline / Production Browser E2E (push) Failing after 1733h19m19s
CI/CD Pipeline / Deploy Production (push) Failing after 1733h19m21s
CI/CD Pipeline / Build Production Runtime Images (push) Failing after 1733h24m28s
263 lines
8.6 KiB
TypeScript
Executable File
263 lines
8.6 KiB
TypeScript
Executable File
import { expect, test } from "@playwright/test";
|
|
|
|
const PASSWORD = "SmokePass123!";
|
|
const apiBase = process.env.E2E_API_BASE || "/api/v1";
|
|
const apiOrigin = apiBase.endsWith("/api/v1")
|
|
? apiBase.slice(0, -"/api/v1".length)
|
|
: "";
|
|
|
|
const routeBrowserApiToTestApi = async (
|
|
page: import("@playwright/test").Page,
|
|
) => {
|
|
if (!apiOrigin) return;
|
|
await page.route("**/api/v1/**", async (route) => {
|
|
const sourceUrl = new URL(route.request().url());
|
|
const response = await route.fetch({
|
|
url: `${apiOrigin}${sourceUrl.pathname}${sourceUrl.search}`,
|
|
});
|
|
await route.fulfill({ response });
|
|
});
|
|
};
|
|
|
|
async function loginWithRetry(
|
|
request: any,
|
|
email: string,
|
|
password: string,
|
|
maxRetries = 2,
|
|
) {
|
|
for (let i = 0; i <= maxRetries; i++) {
|
|
const response = await request.post(`${apiBase}/auth/login`, {
|
|
data: { email, password },
|
|
});
|
|
if (response.status() !== 429) return response;
|
|
console.log(`[login] rate limited, waiting 65s (${i + 1}/${maxRetries})`);
|
|
await new Promise((r) => setTimeout(r, 65000));
|
|
}
|
|
return request.post(`${apiBase}/auth/login`, {
|
|
data: { email, password },
|
|
});
|
|
}
|
|
|
|
type ProjectResponse = { id: string };
|
|
type LibraryResponse = { id: string };
|
|
type AssetListResponse = {
|
|
items: Array<{
|
|
id: string;
|
|
name: string;
|
|
status: string;
|
|
}>;
|
|
};
|
|
type GenerationTaskResponse = {
|
|
id: string;
|
|
status: string;
|
|
progress: number;
|
|
result_count: number;
|
|
error_message?: string | null;
|
|
};
|
|
|
|
test.describe("Core generation flow", () => {
|
|
test.describe.configure({ timeout: 180_000 });
|
|
test("generates a video and shows result in product library", async ({
|
|
page,
|
|
request,
|
|
}) => {
|
|
test.setTimeout(180_000);
|
|
|
|
await routeBrowserApiToTestApi(page);
|
|
const suffix = Date.now().toString(36);
|
|
const email = `e2e-gen-${suffix}@example.com`;
|
|
const username = `e2e_gen_${suffix}`;
|
|
const libraryName = `E2E Gen Lib ${suffix}`;
|
|
|
|
// Register
|
|
const register = await request.post(`${apiBase}/auth/register`, {
|
|
data: { email, username, password: PASSWORD, display_name: username },
|
|
});
|
|
expect(register.status()).toBe(201);
|
|
const registerData = (await register.json()) as { user_id: string };
|
|
|
|
// Login
|
|
const login = await loginWithRetry(request, email, PASSWORD);
|
|
expect(login.status()).toBe(200);
|
|
const loginData = (await login.json()) as { access_token: string };
|
|
const headers = { Authorization: `Bearer ${loginData.access_token}` };
|
|
|
|
// Create project
|
|
const project = await request.post(`${apiBase}/projects`, {
|
|
headers,
|
|
data: { name: `E2E Gen Proj ${suffix}` },
|
|
});
|
|
expect(project.status()).toBe(200);
|
|
const projectData = (await project.json()) as ProjectResponse;
|
|
|
|
// Create asset library
|
|
const library = await request.post(`${apiBase}/asset-libraries`, {
|
|
headers,
|
|
data: { project_id: projectData.id, name: libraryName, kind: "video" },
|
|
});
|
|
expect(library.status()).toBe(200);
|
|
const libraryData = (await library.json()) as LibraryResponse;
|
|
|
|
// Upload source video
|
|
const sourceFileName = "e2e-gen-source.mp4";
|
|
const upload = await request.post(`${apiBase}/upload`, {
|
|
headers,
|
|
multipart: {
|
|
project_id: projectData.id,
|
|
library_id: libraryData.id,
|
|
file: {
|
|
name: sourceFileName,
|
|
mimeType: "video/mp4",
|
|
buffer: Buffer.from("e2e source data"),
|
|
},
|
|
},
|
|
});
|
|
expect(upload.status()).toBe(200);
|
|
|
|
// Wait for asset to be ready
|
|
let sourceAssetId = "";
|
|
await expect
|
|
.poll(
|
|
async () => {
|
|
const assets = await request.get(`${apiBase}/assets`, {
|
|
headers,
|
|
params: { library_id: libraryData.id },
|
|
});
|
|
if (!assets.ok()) return `http_${assets.status()}`;
|
|
const data = (await assets.json()) as AssetListResponse;
|
|
const asset = data.items.find((a) => a.name === sourceFileName);
|
|
if (!asset) return "missing";
|
|
sourceAssetId = asset.id;
|
|
return asset.status;
|
|
},
|
|
{ timeout: 30_000, intervals: [1_000, 2_000, 3_000] },
|
|
)
|
|
.toBe("ready");
|
|
|
|
// Set auth in localStorage
|
|
await page.addInitScript(
|
|
({ token, user }) => {
|
|
localStorage.setItem("access_token", token);
|
|
localStorage.setItem(
|
|
"auth-storage",
|
|
JSON.stringify({
|
|
state: { user, isAuthenticated: true },
|
|
version: 0,
|
|
}),
|
|
);
|
|
},
|
|
{
|
|
token: loginData.access_token,
|
|
user: {
|
|
id: registerData.user_id,
|
|
user_id: registerData.user_id,
|
|
email,
|
|
username,
|
|
display_name: username,
|
|
is_email_verified: true,
|
|
email_verified: true,
|
|
},
|
|
},
|
|
);
|
|
|
|
// Navigate to generate page
|
|
await page.goto("/app/generate");
|
|
await expect(page.getByRole("heading", { name: "一键生成" })).toBeVisible({ timeout: 20_000 });
|
|
|
|
// Step 1: template - default selected, click next
|
|
await expect(page.locator(".xx-choice-item.selected")).toBeVisible();
|
|
await page.getByRole("button", { name: "下一步" }).click();
|
|
|
|
// Step 2: select material
|
|
await expect(page.getByText("选择素材")).toBeVisible();
|
|
const librarySelect = page.locator("select").first();
|
|
await librarySelect.selectOption({ label: libraryName });
|
|
const materialLabel = page.getByText(sourceFileName).locator("..");
|
|
await expect(materialLabel.locator("input[type='checkbox']")).toBeVisible({ timeout: 10_000 });
|
|
await materialLabel.locator("input[type='checkbox']").check();
|
|
await page.getByRole("button", { name: "下一步" }).click();
|
|
|
|
// Step 3: title
|
|
await expect(page.getByText("选择标题")).toBeVisible();
|
|
const titleText = `E2E Test ${suffix}`;
|
|
await page.getByPlaceholder("输入自定义标题…").fill(titleText);
|
|
await page.getByRole("button", { name: "下一步" }).click();
|
|
|
|
// Step 4: voice
|
|
await expect(page.getByText("选择配音")).toBeVisible();
|
|
const firstVoiceCard = page.locator(".xx-voice-choice-item").first();
|
|
await firstVoiceCard.click();
|
|
await page.getByRole("button", { name: "下一步" }).click();
|
|
|
|
// Step 5: confirm and generate
|
|
await expect(page.getByText("确认生成")).toBeVisible();
|
|
|
|
const createTaskPromise = page.waitForResponse(
|
|
(response) =>
|
|
response.url().includes("/edit-plans") &&
|
|
response.request().method() === "POST" &&
|
|
!response.url().includes("/generate"),
|
|
{ timeout: 30_000 },
|
|
);
|
|
|
|
await page.getByRole("button", { name: "确认生成" }).click();
|
|
|
|
const createTaskResp = await createTaskPromise;
|
|
expect(createTaskResp.ok()).toBeTruthy();
|
|
const taskData = (await createTaskResp.json()) as { id: string; status: string };
|
|
|
|
// Wait for generation to complete
|
|
await expect
|
|
.poll(
|
|
async () => {
|
|
const resp = await request.get(
|
|
`${apiBase}/generation-tasks/${taskData.id}`,
|
|
{ headers },
|
|
);
|
|
if (!resp.ok()) return `http_${resp.status()}`;
|
|
const data = (await resp.json()) as GenerationTaskResponse;
|
|
if (data.error_message) return `error: ${data.error_message}`;
|
|
return data.status;
|
|
},
|
|
{ timeout: 120_000, intervals: [2_000, 3_000, 5_000] },
|
|
)
|
|
.toBe("completed");
|
|
|
|
// Verify result in product library
|
|
await page.goto("/app/products");
|
|
await expect(page.getByText(titleText)).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
|
|
test("generation task API creates and lists tasks", async ({ request }) => {
|
|
const suffix = Date.now().toString(36);
|
|
const email = `e2e-gen-api-${suffix}@example.com`;
|
|
const username = `e2e_gen_api_${suffix}`;
|
|
|
|
const register = await request.post(`${apiBase}/auth/register`, {
|
|
data: { email, username, password: PASSWORD, display_name: username },
|
|
});
|
|
expect(register.status()).toBe(201);
|
|
|
|
const login = await loginWithRetry(request, email, PASSWORD);
|
|
expect(login.status()).toBe(200);
|
|
const loginData = (await login.json()) as { access_token: string };
|
|
const headers = { Authorization: `Bearer ${loginData.access_token}` };
|
|
|
|
const project = await request.post(`${apiBase}/projects`, {
|
|
headers,
|
|
data: { name: `E2E API Proj ${suffix}` },
|
|
});
|
|
expect(project.status()).toBe(200);
|
|
const projectData = (await project.json()) as ProjectResponse;
|
|
|
|
const tasks = await request.get(`${apiBase}/generation-tasks`, {
|
|
headers,
|
|
params: { project_id: projectData.id },
|
|
});
|
|
expect(tasks.status()).toBe(200);
|
|
const tasksData = await tasks.json();
|
|
expect(tasksData.items).toBeDefined();
|
|
expect(Array.isArray(tasksData.items)).toBe(true);
|
|
});
|
|
});
|