cmvr-visual/frontend/tests/browser/story-render-layout.cjs

933 lines
32 KiB
JavaScript

/* Story render regression: long runs/captions stay local to accessible scroll regions.
* Run from repo root: node frontend/tests/browser/story-render-layout.cjs
* Add --native or --native-unavailable for H3 native dialogue authoring coverage.
* --native-recordings checks explicit legacy recording and narration release actions.
* --native-portrait verifies that an available native profile cannot authorize an uncertified canvas.
* All API calls use fixtures; mutations are rejected. No database or model work.
*/
const assert = require('node:assert/strict')
const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')
let pw
for (const mod of [
process.env.PLAYWRIGHT_MODULE,
'playwright',
path.join(
os.homedir(),
'.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright',
),
].filter(Boolean)) {
try {
pw = require(mod)
break
} catch {}
}
if (!pw) throw new Error('Set PLAYWRIGHT_MODULE to an installed Playwright module.')
const base = process.env.FORM_QA_BASE || 'http://127.0.0.1:5173'
const review = process.argv.includes('--review')
const rhythm = process.argv.includes('--rhythm')
const recordings = process.argv.includes('--native-recordings')
const nativePortrait = process.argv.includes('--native-portrait')
const native =
rhythm || nativePortrait ||
recordings ||
process.argv.includes('--native') ||
process.argv.includes('--native-unavailable')
const nativeAvailable = !process.argv.includes('--native-unavailable')
const id = (n) => n.toString(16).padStart(32, '0')
const stamp = '2026-11-27T02:00:00Z'
const shots = [1, 2, 3].map((n) => ({
id: id(n),
name: `镜头${n}`,
scene_id: id(100),
cast: [],
visual_prompt: '雨夜柜台近景',
motion_prompt: '轻轻抬眼',
overrides: {},
frame_parameters: { seed: 42 },
video_parameters: { seed: 42, source_seconds: 5 },
edit: { start_frame: 0, duration_frames: 120 },
}))
const spec = {
schema_version: 3,
profile: 'landscape_1080_v1',
context: { era: '现代', style: '写实', palette: '暖色', lighting: '台灯', negative_prompt: '' },
scenes: [
{
id: id(100),
name: '修鞋铺',
description: '雨夜',
reference_asset_ids: [],
location: '柜台',
time: '夜晚',
weather: '细雨',
lighting: '暖光',
},
],
entities: [],
shots,
render: {
fps: 24,
total_frames: 360,
fit: 'contain',
audio: null,
subtitles: [],
template_version: 'plain-v1',
},
}
const manifest = {
schema_version: 1,
source_kind: 'story',
editing_mode: 'auto',
spec,
shot_ids: shots.map((s) => s.id),
bindings: {},
audio: { mode: 'silent', voice: '', speed: 1, track: null, segments: [] },
captions: {
mode: 'manual',
cues: Array.from({ length: 30 }, (_, n) => ({
id: id(1000 + n),
anchor: 'shot',
shot_id: shots[n % 3].id,
start_frame: 0,
end_frame: 80,
text: `字幕${n + 1},内容和锚点应在同一个滚动区内。`,
text_override: true,
timing_override: false,
})),
},
}
if (native) {
spec.schema_version = 5
spec.entities = [
{
id: id(300),
kind: 'person',
name: '林晚',
description: '短发青年女性',
reference_asset_ids: [],
forms: [],
appearances: [],
},
]
const speaker = {
id: id(301),
name: '林晚',
entity_id: id(300),
native_voice: '青年女声,清亮平静',
voice: {
provider: 'kokoro',
model: 'kokoro-82m',
voice: 'zf_xiaobei',
speed: 1,
seed: 42,
revision: 1,
style: '',
reference_asset_id: null,
reference_text: '',
},
}
spec.dialogue = {
enabled: true,
generation: 'native_av',
language: 'Chinese',
speakers: [speaker],
sequences: [],
utterances: [],
}
for (const [index, shot] of shots.entries()) {
const lineIds = Array.from({ length: 10 }, (_, i) => id(400 + index * 10 + i))
const sequence = {
id: id(600 + index),
scene_id: shot.scene_id,
shot_ids: [shot.id],
utterance_ids: lineIds,
timing_mode: 'auto',
}
spec.dialogue.sequences.push(sequence)
spec.dialogue.utterances.push(
...lineIds.map((lineId, i) => ({
id: lineId,
speaker_id: speaker.id,
text: `原生台词${index * 10 + i + 1},雨快停了,我们一起回家。`,
spoken_text: null,
source: 'tts',
asset_id: null,
source_start_sample: 0,
source_end_sample: null,
gap_after_sample: 9600,
delivery: '平静自然',
locked: false,
})),
)
shot.cast = [
{
id: id(700 + index),
entity_id: speaker.entity_id,
form_id: null,
appearance_id: null,
position: '中央',
action: '轻轻抬眼',
},
]
shot.performance = {
sequence_id: sequence.id,
visible_speaker_ids: [speaker.id],
native_utterance_ids: lineIds,
lip_sync: 'auto',
duration_mode: 'fixed',
structure_locked: false,
original_audio: 'discard',
}
}
manifest.schema_version = 3
manifest.audio.mix_mode = 'composed'
manifest.audio.layers = [
{
id: id(805),
role: 'bgm',
asset_id: id(804),
anchor: 'absolute',
offset_sample: 0,
gain_db: -12,
},
]
manifest.captions.mode = 'script'
manifest.captions.cues.forEach((cue, index) => {
cue.anchor = 'utterance'
cue.utterance_id = spec.dialogue.utterances[index].id
delete cue.shot_id
})
manifest.bindings['video:' + shots[0].id] = {
asset_id: 'native-video',
kind: 'video',
source: 'generated',
}
manifest.bindings['native_audio:' + shots[0].id] = {
asset_id: 'native-audio',
kind: 'audio',
source: 'generated',
}
}
if (recordings) {
const speaker = spec.dialogue.speakers[0]
speaker.voice.reference_asset_id = id(800)
speaker.voice.reference_text = '旧参考录音,仅保留历史约束'
manifest.audio.mode = 'generated_narration'
manifest.audio.mix_mode = 'manual_mix'
manifest.audio.segments = [
{ id: id(802), text: '保留的历史旁白,仅可只读查看。', anchor: 'absolute' },
]
manifest.bindings['audio:' + id(802)] = { asset_id: id(803), kind: 'audio', source: 'generated' }
const line = spec.dialogue.utterances[0]
line.source = 'asset'
line.asset_id = id(801)
line.source_start_sample = 48000
line.source_end_sample = 96000
manifest.bindings['speech:' + line.id] = {
asset_id: line.asset_id,
kind: 'audio',
source: 'manual',
locked: true,
}
}
const previewUrl =
'data:image/svg+xml,' +
encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" width="400" height="260"><rect width="400" height="260" fill="#294950"/></svg>',
)
const output = {
id: 'layout-output',
name: '滚动区成果预览',
kind: 'image',
mime_type: 'image/svg+xml',
size_bytes: 1000,
width: 400,
height: 260,
duration_seconds: null,
preview_url: previewUrl,
thumbnail_url: previewUrl,
download_url: previewUrl,
source_job_id: null,
source_output_index: 0,
origin: 'generated',
tags: [],
favorite: false,
folder_ids: [],
created_at: stamp,
}
const story = {
id: 'layout-story',
name: '长内容布局夹具',
kind: 'story',
editing_mode: 'auto',
editor_manifest: manifest,
spec,
version: 1,
revision: 1,
folder_id: null,
selections: [],
readiness: { ready: false, issues: [] },
capabilities: { mode_switch: true, manual: true, auto: true, name_edit: true },
created_at: stamp,
updated_at: stamp,
}
const run = {
id: 'layout-run',
draft_id: story.id,
draft_revision: 1,
state: 'succeeded',
desired_state: 'run',
execution_mode: 'batch',
version: 1,
apply_state: 'pending',
output_goal: 'film',
result_assets: [],
completed_steps: 149,
total_steps: 149,
run_kind: 'story_auto',
quality: { accepted_shots: 3, total_shots: 3, total_repairs: 0, variants: [] },
created_at: stamp,
}
const snapshot = {
draft: story,
run,
steps: Array.from({ length: 149 }, (_, n) => ({
id: id(2000 + n),
run_id: run.id,
step_key: n === 148 ? 'compose' : `frame_${String(n + 1).padStart(4, '0')}`,
kind: n === 148 ? 'video.compose' : 'image.generate',
state: 'succeeded',
selected_job_id: null,
explicit_attempt: 0,
dependencies: [],
version: 1,
})),
jobs: [],
cursor: 1,
}
if (native) {
snapshot.steps = shots.flatMap((shot, index) =>
[
{ role: 'frame', kind: 'image.generate' },
{ role: 'nv', kind: 'video.generate' },
{ role: 'na', kind: 'audio.dialogue.extract' },
{ role: 'nq', kind: 'audio.dialogue.inspect' },
{ role: 'nr', kind: 'video.dialogue.review' },
{ role: 'ng', kind: 'dialogue.accepted' },
].map(({ role, kind }, n) => ({
id: id(3000 + index * 6 + n),
run_id: run.id,
step_key: `${role}_${String(index + 1).padStart(4, '0')}`,
kind,
state: 'succeeded',
selected_job_id: null,
explicit_attempt: 0,
dependencies: [],
version: 1,
})),
)
snapshot.steps.push(
...[
{ step_key: 'dialogue_mix', kind: 'audio.mix' },
{ step_key: 'dialogue_captions', kind: 'captions.compile' },
{ step_key: 'compose', kind: 'video.compose' },
].map((stage, index) => ({
id: id(3100 + index),
run_id: run.id,
...stage,
state: 'succeeded',
selected_job_id: null,
explicit_attempt: 0,
dependencies: [],
version: 1,
})),
)
run.completed_steps = snapshot.steps.length
run.total_steps = snapshot.steps.length
}
run.result_assets.push(output)
snapshot.steps[0].result = { asset_id: output.id }
const pageOf = (items) => ({ items, total: items.length, page: 1, page_size: 100, cursor: 1 })
const caps = {
items: [],
editable_production: { schema_version: 1 },
workflow_limits: { max_shots: 120, fps: 24 },
execution_policy: { timezone: 'Asia/Shanghai', batch_window_enabled: false, batch_open: true },
}
if (native) {
caps.dialogue = {
available: true,
authoring_available: true,
production_available: true,
native_av: {
available: nativeAvailable,
reason: nativeAvailable ? null : '上游H3原生音频尚未升级',
max_visible_speakers: 1,
languages: ['Chinese'],
profiles: ['minimax-h3-fl2va-bf16-v1'],
},
}
caps.items.push({
task_type: 'video.generate',
available: true,
defaults: {},
constraints: {},
video_profiles: ['minimax-h3-fl2va-native-av-v1', 'minimax-h3-fl2va-native-av-tp2-v1'].map(
(profile) => ({
profile,
available: nativeAvailable,
defaults: {},
constraints: {},
canvases: [[1344, 768]],
}),
),
})
if (nativePortrait) spec.profile = 'portrait_1080_v1'
caps.editable_production.schema_version = 3
caps.editable_production.supported_schema_versions=rhythm?[1,2,3,4]:[1,2,3]
}
const unknown = [],
writes = [],
errors = [],
issues = []
async function mock(route) {
const request = route.request(),
pathname = new URL(request.url()).pathname
if (!pathname.startsWith('/api/')) return route.continue()
const key = pathname.slice(4)
if (rhythm && key === '/editors/layout-story/captions/preview' && request.method() === 'POST') {
const input = request.postDataJSON()
const line = spec.dialogue.utterances[0]
const text = input.manifest?.captions.presentation.punctuation === 'hide' ? line.text.replace(/[,。]/g, '') : line.text
return route.fulfill({json:{rows:[{id:id(990),shot_id:shots[0].id,utterance_id:line.id,
source_text:line.text,source_start:0,source_end:Array.from(line.text).length,text,
start_frame:3,end_frame:57,local_start_frame:3,local_end_frame:57,status:'automatic',text_override:false,timing_override:false}],issues:[]}})
}
if (!['GET', 'HEAD'].includes(request.method())) {
writes.push(key)
return route.fulfill({ status: 405, json: { detail: 'Fixture rejects mutations' } })
}
let value
if (key === '/auth/me')
value = {
user: {
id: 'layout-admin',
username: 'layout-admin',
display_name: '布局夹具',
role: 'admin',
disabled: false,
},
csrf_token: 'fixture-only',
}
else if (key === '/capabilities' || key === '/system/status') value = caps
else if (key === '/folders') value = { items: [] }
else if (key === '/stories/capabilities')
value = {
enabled: true,
reference_generation: { available: false },
frame_text_generation: { available: false },
}
else if (key === '/stories/layout-story') value = story
else if (key === '/editors/layout-story')
value = {
draft_id: story.id,
name: story.name,
version: 1,
revision: 1,
manifest,
issues: [],
assets: native
? [
{ ...output, id: 'native-video', kind: 'video', mime_type: 'video/mp4' },
{ ...output, id: 'native-audio', kind: 'audio', mime_type: 'audio/wav' },
{ ...output, id: id(804), name: '背景音乐', kind: 'audio', mime_type: 'audio/wav' },
...(recordings
? [
{
...output,
id: id(803),
name: '历史旁白录音',
kind: 'audio',
mime_type: 'audio/wav',
},
{
...output,
id: id(800),
name: '旧参考录音',
kind: 'audio',
mime_type: 'audio/wav',
},
{
...output,
id: id(801),
name: '旧台词录音',
kind: 'audio',
mime_type: 'audio/wav',
},
]
: []),
]
: [],
editing_mode: 'auto',
capabilities: story.capabilities,
}
else if (key === '/workflow-runs/layout-run') value = snapshot
else if (key === '/assets/layout-output') value = output
else if (key === '/shared-assets') value = pageOf([])
else if (key === '/workflow-runs' || key === '/stories/layout-story/runs') value = pageOf([run])
else if (key.endsWith('/preview'))
value = {
shots: shots.map((s) => ({
shot_id: s.id,
context_hash: 'fixture',
frame_prompt: s.visual_prompt,
motion_prompt: s.motion_prompt,
references: [],
effective_settings: {},
errors: [],
})),
errors: [],
}
else if (key.endsWith('/readiness')) value = { ready: false, issues: [] }
else if (
key.endsWith('/candidates') ||
key === '/assets' ||
key === '/jobs' ||
key === '/stories' ||
key === '/workflows' ||
key === '/batches'
)
value = pageOf([])
else if (key === '/stories/layout-story/film') value = null
else {
unknown.push(key)
return route.fulfill({ status: 404, json: { detail: key } })
}
return route.fulfill({ status: 200, json: value })
}
const check = (ok, message) => {
if (!ok) issues.push(message)
}
async function regionCheck(page, name, height, viewport, dir) {
const region = page.getByRole('region', { name, exact: true })
if ((await region.count()) !== 1) {
issues.push(`${viewport}: missing ${name} scroll region`)
return
}
const measured = await region.evaluate((el) => ({
height: el.getBoundingClientRect().height,
client: el.clientHeight,
scroll: el.scrollHeight,
overflow: getComputedStyle(el).overflowY,
tabindex: el.tabIndex,
}))
check(
Math.abs(measured.height - height) <= 1,
`${viewport}: ${name} height ${measured.height}, expected ${height}`,
)
check(
measured.scroll > measured.client + 50 && ['auto', 'scroll'].includes(measured.overflow),
`${viewport}: ${name} cannot scroll overflow`,
)
check(measured.tabindex === 0, `${viewport}: ${name} is not keyboard reachable`)
await page.locator('.story-mode-tabs button').last().focus()
await region.scrollIntoViewIfNeeded()
await page.mouse.move(2, 2)
const idleScrollbar = await region.evaluate((el) => getComputedStyle(el).scrollbarColor)
await region.hover()
const hoveredScrollbar = await region.evaluate((el) => getComputedStyle(el).scrollbarColor)
check(
idleScrollbar !== hoveredScrollbar,
`${viewport}: ${name} scrollbar does not appear on hover`,
)
await page.mouse.move(2, 2)
check(
(await region.evaluate((el) => getComputedStyle(el).scrollbarColor)) === idleScrollbar,
`${viewport}: ${name} scrollbar stays visible after mouse leaves`,
)
const ancestors = () =>
region.evaluate((el) => {
const positions = []
for (let node = el.parentElement; node; node = node.parentElement)
positions.push([node.scrollTop, node.scrollLeft])
return positions
})
const outerBefore = JSON.stringify(await ancestors())
const box = await region.boundingBox()
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
await page.mouse.wheel(0, 500)
await page.waitForFunction(
(label) => document.querySelector(`[role="region"][aria-label="${label}"]`).scrollTop > 50,
name,
)
check(
JSON.stringify(await ancestors()) === outerBefore,
`${viewport}: ${name} wheel scrolled an outer container`,
)
await region.focus()
await page.keyboard.press('End')
await page.waitForFunction((label) => {
const el = document.querySelector(`[role="region"][aria-label="${label}"]`)
return el.scrollTop >= el.scrollHeight - el.clientHeight - 2
}, name)
await page.mouse.wheel(0, 500)
await page.evaluate(
() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))),
)
check(
JSON.stringify(await ancestors()) === outerBefore,
`${viewport}: ${name} boundary scroll leaked to an outer container`,
)
await region.evaluate((el) => {
el.scrollTop = 0
})
if (review) await page.screenshot({ path: path.join(dir, `${viewport}-${name}.png`) })
}
async function main() {
const temp = fs.realpathSync(os.tmpdir()),
dir = fs.mkdtempSync(path.join(temp, 'cmvr-story-render-'))
let browser
try {
browser = await pw.chromium.launch({
headless: true,
channel: process.env.PLAYWRIGHT_CHANNEL || 'chrome',
})
for (const viewport of [
{ width: 1440, height: 900 },
{ width: 1920, height: 1080 },
{ width: 1440, height: 500 },
]) {
const { width, height } = viewport,
label = `${width}x${height}`
const context = await browser.newContext({ viewport })
await context.route('**/api/**', mock)
await context.addInitScript(() => {
window.EventSource = class extends EventTarget {
constructor() {
super()
setTimeout(() => this.onopen?.(new Event('open')), 0)
}
close() {}
}
})
const page = await context.newPage()
page.on('pageerror', (e) => errors.push(e.message))
const loaded = page.waitForResponse(
(response) => new URL(response.url()).pathname === '/api/workflow-runs/layout-run',
)
await page.goto(base + '/studio/layout-story', { waitUntil: 'networkidle' })
await loaded
await page
.locator('.editable-production')
.waitFor()
.catch(async (error) => {
console.log(
JSON.stringify({
unknown,
writes,
errors,
body: (await page.locator('body').innerText()).slice(0, 1600),
}),
)
throw error
})
await page.evaluate(
() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))),
)
for (const stage of ['01', '02']) {
await page.locator('.story-mode-tabs button').filter({ hasText: stage }).click()
if (native && stage === '01') {
check(
await page.getByText('声线描述', { exact: true }).isVisible(),
`${label}: native voice description is missing`,
)
check(
await page.getByText('对白语言', { exact: true }).isVisible(),
`${label}: native language field is missing`,
)
}
if (recordings && stage === '01') {
const workshop = page.locator('.dialogue-workshop')
check(
(await workshop.innerText()).includes('原生FL2VA不使用旧参考录音克隆'),
`${label}: legacy reference constraint is hidden`,
)
const release = workshop.getByRole('button', { name: '解除旧参考录音约束', exact: true })
await release.click()
check(
(await release.count()) === 0,
`${label}: explicit reference release did not clear its constraint`,
)
}
if (native && stage === '02') {
const workshop = page.locator('.dialogue-workshop')
check(
!(await page.locator('.editor-shot-body').innerText()).includes('输出静音视频'),
`${label}: native shot editor still promises silent output`,
)
if (recordings) {
const convert = workshop.getByRole('button', {
name: '改为H3根据台词生成',
exact: true,
})
check(
(await convert.count()) === 1,
`${label}: historical recording has no explicit native conversion`,
)
check(
(await workshop.innerText()).includes('声音会重新生成'),
`${label}: conversion omits its voice regeneration consequence`,
)
await convert.click()
check(
(await convert.count()) === 0,
`${label}: explicit recording conversion did not apply`,
)
check(
(await workshop
.getByRole('button', { name: '试听历史配音', exact: true })
.count()) === 1,
`${label}: conversion lost historical audio binding preview`,
)
}
const text = await workshop.innerText()
check(
!/语音提供方|参考录音|仅重做口型|口型对时|生成试听|重做此句配音/.test(text),
`${label}: retired speech or Muse controls are visible`,
)
check(
(await workshop
.getByRole('button', { name: '预览原生音视频', exact: true })
.count()) === 1,
`${label}: actual native video preview is missing`,
)
check(
(await workshop
.getByRole('button', { name: '试听实际原生音轨', exact: true })
.count()) === 1,
`${label}: actual native audio preview is missing`,
)
const generate = workshop.getByRole('button', {
name: '重新生成本镜头原生对白',
exact: true,
})
check(
(await generate.isDisabled()) === (!nativeAvailable || nativePortrait),
`${label}: native capability does not gate generation`,
)
if (nativePortrait)
check(
(await page.locator('.editable-production').innerText()).includes(
'当前仅横屏原生对白通过验收,竖屏原生暂不可生成',
),
`${label}: portrait native certification restriction is missing`,
)
const bounds = await page.locator('.editable-production').evaluate((el) => ({
bottom: el.getBoundingClientRect().bottom,
overflow: getComputedStyle(el).overflowY,
documentHeight: document.documentElement.scrollHeight,
}))
check(
bounds.bottom <= height + 2 &&
bounds.documentHeight <= height + 2 &&
bounds.overflow === 'auto',
`${label}: native shot editor lost its fixed-height scroll panel`,
)
const field = page.locator('.editor-shot-body .story-shot-editor')
const aligned = await field.evaluate((el) => {
const body = el.parentElement.getBoundingClientRect()
const box = el.getBoundingClientRect()
return Math.abs(body.width - box.width) <= 4
})
check(aligned, `${label}: native shot form leaves an unused column`)
}
check(
(await page.locator('.v2-step').count()) === 0,
`${width}: workflow rendered in ${stage}`,
)
}
await page.locator('.story-mode-tabs button').filter({ hasText: '03' }).click()
await page.locator('.editor-cue').last().waitFor()
const filmRegion = page.getByRole('region', { name: '成片预览', exact: true })
await filmRegion.getByText('还没有已完成的成片。').waitFor()
check(
await filmRegion.evaluate(
(el) =>
el.compareDocumentPosition(document.querySelector('.editor-timeline')) &
Node.DOCUMENT_POSITION_FOLLOWING,
),
`${label}: latest film should appear above the render editor`,
)
if (native) {
const render = page.locator('.editor-timeline')
const body = await render.innerText()
check(
!/添加跨镜头旁白|生成旁白|全局声音|全局语速|重做此段配音|AI补齐文案/.test(body),
`${label}: unsupported independent narration controls are visible`,
)
check(
(await render.getByRole('button', { name: '添加背景音乐', exact: true }).count()) === 1,
`${label}: native mode lost background music authoring`,
)
const remix = render.getByRole('button', { name: '重新混音并成片', exact: true })
check(
(await remix.count()) === 1,
`${label}: native mode lost background music remix action`,
)
if (recordings) {
const legacy = render.locator('.native-legacy-narration')
check(
(await legacy.innerText()).includes('保留的历史旁白,仅可只读查看。'),
`${label}: historical narration text disappeared`,
)
check(
(await legacy.locator('textarea,input,select').count()) === 0,
`${label}: historical narration remains editable`,
)
const disable = legacy.getByRole('button', {
name: '关闭历史独立旁白及成品音轨',
exact: true,
})
check(
await remix.isDisabled(),
`${label}: active legacy narration did not block native film`,
)
await disable.click()
check(
(await disable.count()) === 0,
`${label}: legacy narration was not explicitly disabled`,
)
check(
(await legacy.innerText()).includes('保留的历史旁白,仅可只读查看。'),
`${label}: disabling narration deleted its text`,
)
check(
(await legacy.getByRole('button', { name: '试听历史旁白', exact: true }).count()) === 1,
`${label}: disabling narration lost its historical audio preview`,
)
}
check(
(await remix.isDisabled()) === (!nativeAvailable || nativePortrait),
`${label}: native background music remix cannot follow capability state`,
)
}
check(
(await page.locator('.v2-step').count()) === snapshot.steps.length,
`${width}: workflow stages disappeared in 03`,
)
if (native) {
const allStages = (await page.locator('.v2-step').allTextContents()).join(' ')
for (const label of [
'H3原生音画',
'提取原生音轨',
'原生对白识别',
'原生画面质检',
'原生对白验收',
])
check(allStages.includes(label), `${label}: native workflow label is missing`)
check(
!/MuseTalk|VoxCPM2|Kokoro|独立配音|口型生成/.test(allStages),
`${label}: workflow shows a retired TTS or Muse stage`,
)
}
await regionCheck(page, '成片工作流', Math.min(420, height * 0.6), label, dir)
await regionCheck(page, '字幕文案与锚点', Math.min(480, height * 0.65), label, dir)
if (height >= 900) {
await page
.getByRole('region', { name: '成片工作流', exact: true })
.getByRole('button', { name: '预览成果', exact: true })
.click()
const dialog = page.locator('.preview-dialog:visible')
await dialog.waitFor().catch(async (error) => {
console.log(
JSON.stringify({
unknown,
errors,
dialogs: await page.locator('.el-dialog').evaluateAll((nodes) =>
nodes.map((el) => ({
text: el.textContent.slice(0, 180),
display: getComputedStyle(el).display,
rect: el.getBoundingClientRect().toJSON(),
})),
),
}),
)
throw error
})
const box = await dialog.boundingBox()
check(
box.width > 420 && box.y >= 0 && box.y + box.height <= height,
`${label}: media preview was clipped by the workflow region`,
)
check(
await dialog.getByRole('img', { name: output.name, exact: true }).isVisible(),
`${label}: media preview image disappeared`,
)
await page.keyboard.press('Escape')
await dialog.waitFor({ state: 'hidden' })
}
if(native&&!rhythm){
check(await page.getByRole('button',{name:'试用节奏字幕'}).count()===0,label+': old server exposed V4 captions')
}
if (rhythm) {
const captions = page.getByRole('region', {name:'节奏字幕草稿预览'})
await captions.getByRole('button',{name:'试用节奏字幕'}).click()
await captions.getByText('原设置 · '+spec.dialogue.utterances[0].text, {exact:false}).first().waitFor()
await captions.getByText('试用设置 · '+spec.dialogue.utterances[0].text.replace(/[,。]/g,''),{exact:false}).first().waitFor()
await captions.getByRole('button',{name:'取消试用'}).click()
check(await captions.getByRole('button',{name:'试用节奏字幕'}).isVisible(),label+': preview cancellation lost the legacy caption setting')
}
const area = page.locator('.editor-cue textarea').first()
await area.fill('本地未保存的字幕仍应保留')
await page.locator('.story-mode-tabs button').filter({ hasText: '02' }).click()
await page.locator('.story-mode-tabs button').filter({ hasText: '03' }).click()
check(
(await area.inputValue()) === '本地未保存的字幕仍应保留',
`${width}: tab switch discarded local caption`,
)
await page.screenshot({ path: path.join(dir, `${label}-render.png`) })
if (rhythm) {
await page.locator('.story-mode-tabs button').filter({hasText:'02'}).click()
await page.getByLabel('拍摄方式').selectOption('two_person_turns')
check(await page.getByRole('button',{name:'试生成本镜',exact:true}).isDisabled(),label+': two-person filming enabled without a certificate')
check(await page.getByText('双人首帧与逐轮表演',{exact:true}).isVisible(),label+': staged shot author controls missing')
}
await context.close()
}
console.log(JSON.stringify({ issues, unknown, writes, errors }))
assert.deepEqual(unknown, [], 'incomplete API fixture')
assert.deepEqual(writes, [], 'browser test must never mutate real data')
assert.deepEqual(errors, [], 'browser runtime errors')
assert.deepEqual(issues, [], 'story render layout regression')
if (review) {
console.log(`REVIEW ${dir}`)
await new Promise((resolve) => {
const timer = setInterval(() => {
if (fs.existsSync(path.join(dir, 'review.done'))) {
clearInterval(timer)
resolve()
}
}, 250)
})
}
} finally {
await browser?.close()
const resolved = fs.realpathSync(dir),
relative = path.relative(temp, resolved)
if (
path.isAbsolute(relative) ||
relative.startsWith('..') ||
!relative.startsWith('cmvr-story-render-')
)
throw new Error('Unexpected temporary screenshot directory')
fs.rmSync(resolved, { recursive: true, force: true })
}
}
main().catch((error) => {
console.error(error)
process.exitCode = 1
})