chore: something changed, commit before reorg

This commit is contained in:
Daniil
2026-04-27 23:28:28 +03:00
parent 46f34bdcac
commit 20928e9a60
16 changed files with 1967 additions and 1262 deletions
+166 -118
View File
@@ -2,12 +2,14 @@ import { expect, test } from "@playwright/test"
const USER_ID = "00000000-0000-0000-0000-000000000001"
const PROJECT_ID = "65df675b-013b-4b1f-ab2d-075dadbcd0d9"
const SOURCE_FILE_ID = "00000000-0000-0000-0000-000000000011"
const CAPTION_PRESET_ID = "00000000-0000-0000-0000-000000000010"
const TRANSCRIPTION_ARTIFACT_ID =
"00000000-0000-0000-0000-000000000020"
const TRANSCRIPTION_ID = "00000000-0000-0000-0000-000000000030"
const CAPTION_JOB_ID = "00000000-0000-0000-0000-000000000040"
const PRIMARY_FILE_KEY = "projects/test/video.mp4"
const PRIMARY_FILE_URL = "http://localhost:4444/files/video.mp4"
const DEFAULT_USER = {
id: USER_ID,
@@ -26,53 +28,49 @@ const DEFAULT_USER = {
}
test.describe("Caption Settings Step", () => {
test("should recover a missing transcription artifact from project data", async ({
test("should render from typed workspace and start caption render via workflow action", async ({
page,
}) => {
let project: Record<string, unknown> = {
id: PROJECT_ID,
owner_id: USER_ID,
name: "Тестовый проект",
description: null,
language: "auto",
folder: null,
status: "DRAFT",
workspace_state: {
wizard: {
current_step: "caption-settings",
completed_steps: [
"upload",
"verify",
"silence-settings",
"processing",
"fragments",
"transcription-settings",
"transcription-processing",
"subtitle-revision",
],
primary_file_key: PRIMARY_FILE_KEY,
video_url: "http://localhost:9000/projects/test/video.mp4",
silence_settings: {
min_silence_duration_ms: 200,
silence_threshold_db: 16,
padding_ms: 100,
},
active_job_id: null,
active_job_type: null,
silence_job_id: null,
transcription_artifact_id: null,
caption_preset_id: CAPTION_PRESET_ID,
caption_style_config: null,
captioned_video_path: null,
},
let workflowActions: Array<Record<string, unknown>> = []
let workspace: Record<string, any> = {
revision: 1,
phase: "CAPTIONS",
current_screen: "caption-settings",
active_job: null,
source_file_id: SOURCE_FILE_ID,
workspace_view: {
used_file_ids: [],
selected_file_id: null,
},
silence: {
status: "SKIPPED",
settings: {
min_silence_duration_ms: 200,
silence_threshold_db: 16,
padding_ms: 100,
},
detect_job_id: null,
detected_segments: [],
reviewed_cuts: [],
duration_ms: null,
applied_output_file_id: null,
},
transcription: {
status: "REVIEW_READY",
job_id: null,
request: null,
artifact_id: TRANSCRIPTION_ARTIFACT_ID,
transcription_id: TRANSCRIPTION_ID,
reviewed: true,
},
captions: {
status: "CONFIG_READY",
preset_id: CAPTION_PRESET_ID,
style_config: null,
render_job_id: null,
output_file_id: null,
},
is_active: true,
created_at: "2025-06-01T00:00:00Z",
updated_at: "2025-06-01T00:00:00Z",
}
let savedWizardState: Record<string, unknown> | null = null
let generateRequestBody: Record<string, unknown> | null = null
let generateRequestCount = 0
await page.context().addCookies([
{
@@ -98,37 +96,128 @@ test.describe("Caption Settings Step", () => {
})
await page.route(`**/api/projects/${PROJECT_ID}/`, async (route) => {
if (route.request().method() === "GET") {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(project),
})
return
}
if (route.request().method() === "PATCH") {
const body = route.request().postDataJSON() as {
workspace_state?: { wizard?: Record<string, unknown> }
}
savedWizardState = body.workspace_state?.wizard ?? null
project = {
...project,
workspace_state: body.workspace_state ?? project.workspace_state,
}
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(project),
})
return
}
await route.fallback()
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
id: PROJECT_ID,
owner_id: USER_ID,
name: "Тестовый проект",
description: null,
language: "auto",
folder: null,
status: "DRAFT",
workspace_state: null,
is_active: true,
created_at: "2025-06-01T00:00:00Z",
updated_at: "2025-06-01T00:00:00Z",
}),
})
})
await page.route(`**/api/projects/${PROJECT_ID}/workspace*`, async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(workspace),
})
})
await page.route(
`**/api/projects/${PROJECT_ID}/workflow/actions*`,
async (route) => {
const action = route.request().postDataJSON() as Record<string, unknown>
workflowActions.push(action)
if (action.type === "START_CAPTION_RENDER") {
workspace = {
...workspace,
revision: 2,
current_screen: "caption-processing",
active_job: {
job_id: CAPTION_JOB_ID,
job_type: "CAPTIONS_GENERATE",
},
captions: {
...workspace.captions,
status: "RUNNING",
render_job_id: CAPTION_JOB_ID,
},
}
}
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(workspace),
})
},
)
await page.route("**/api/files/files/", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify([
{
id: SOURCE_FILE_ID,
project_id: PROJECT_ID,
owner_id: USER_ID,
original_filename: "video.mp4",
path: PRIMARY_FILE_KEY,
storage_backend: "S3",
mime_type: "video/mp4",
size_bytes: 1024,
checksum: null,
file_format: "mp4",
is_uploaded: true,
is_deleted: false,
is_active: true,
created_at: "2025-06-01T00:00:00Z",
},
]),
})
})
await page.route(`**/api/files/files/${SOURCE_FILE_ID}/`, async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
id: SOURCE_FILE_ID,
project_id: PROJECT_ID,
owner_id: USER_ID,
original_filename: "video.mp4",
path: PRIMARY_FILE_KEY,
storage_backend: "S3",
mime_type: "video/mp4",
size_bytes: 1024,
checksum: null,
file_format: "mp4",
is_uploaded: true,
is_deleted: false,
is_active: true,
created_at: "2025-06-01T00:00:00Z",
}),
})
})
await page.route(
`**/api/files/files/${SOURCE_FILE_ID}/resolve/`,
async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
file_id: SOURCE_FILE_ID,
file_url: PRIMARY_FILE_URL,
file_path: PRIMARY_FILE_KEY,
filename: "video.mp4",
}),
})
},
)
await page.route("**/api/media/artifacts/", async (route) => {
await route.fulfill({
status: 200,
@@ -149,20 +238,6 @@ test.describe("Caption Settings Step", () => {
})
})
await page.route(
`**/api/transcribe/transcriptions/by-artifact/${TRANSCRIPTION_ARTIFACT_ID}/`,
async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
id: TRANSCRIPTION_ID,
artifact_id: TRANSCRIPTION_ARTIFACT_ID,
}),
})
},
)
await page.route("**/api/captions/presets/", async (route) => {
await route.fulfill({
status: 200,
@@ -183,27 +258,13 @@ test.describe("Caption Settings Step", () => {
})
})
await page.route("**/api/tasks/captions-generate/", async (route) => {
generateRequestCount += 1
generateRequestBody = route.request().postDataJSON() as Record<
string,
unknown
>
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ job_id: CAPTION_JOB_ID }),
})
})
await page.route("**/api/tasks/status/**", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
status: "RUNNING",
progress_pct: 0,
progress_pct: 25,
output_data: null,
}),
})
@@ -220,26 +281,13 @@ test.describe("Caption Settings Step", () => {
await expect(captionStep.getByText("Системный пресет")).toBeVisible()
await expect(generateButton).toBeEnabled()
await expect
.poll(() => savedWizardState?.transcription_artifact_id ?? null)
.toBe(TRANSCRIPTION_ARTIFACT_ID)
await generateButton.click()
expect(generateRequestBody).toMatchObject({
video_s3_path: PRIMARY_FILE_KEY,
transcription_id: TRANSCRIPTION_ID,
project_id: PROJECT_ID,
preset_id: CAPTION_PRESET_ID,
expect(workflowActions).toHaveLength(1)
expect(workflowActions[0]).toMatchObject({
type: "START_CAPTION_RENDER",
revision: 1,
})
expect(generateRequestCount).toBe(1)
await expect
.poll(() => savedWizardState?.current_step ?? null)
.toBe("caption-processing")
await expect
.poll(() => savedWizardState?.active_job_id ?? null)
.toBe(CAPTION_JOB_ID)
await expect(page.locator("[data-testid='ProcessingStep']")).toBeVisible()
})