2026-11-14 14:07:26 +08:00
/ * B r o w s e r f o r m r e g r e s s i o n , u s i n g A P I f i x t u r e s e x c l u s i v e l y .
* From the repository root : node frontend / tests / browser / form - layout . cjs
* -- quick : six important desktop surfaces . -- mobile : mobile overflow smoke checks .
* -- case = name1 , name2 and -- viewport = 1440 x900 select a focused rerun .
2026-11-30 09:12:58 +08:00
* -- continuity : use a V4 fixture to include the movement switch and endpoint fields .
2026-11-14 14:07:26 +08:00
* -- review : keep screenshots until a review . done file is created in their temp directory .
* FORM _QA _BASE ( default http : //127.0.0.1:5173), PLAYWRIGHT_MODULE and
* PLAYWRIGHT _CHANNEL select an existing dev server and installed browser runtime .
* No dependency installation , real API mutation , database , or model is required .
* /
const fs = require ( 'node:fs' ) , os = require ( 'node:os' ) , 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' , quick = process . argv . includes ( '--quick' ) , mobile = process . argv . includes ( '--mobile' ) , review = process . argv . includes ( '--review' ) ;
const caseFilter = process . argv . find ( a => a . startsWith ( '--case=' ) ) ? . slice ( 7 ) . split ( ',' ) ;
const viewportOption = process . argv . find ( a => a . startsWith ( '--viewport=' ) ) ? . slice ( 11 ) . split ( 'x' ) . map ( Number ) ;
const stamp = '2026-11-13T03:00:00Z' , editingCapabilities = { mode _switch : true , manual : true , auto : true , name _edit : true } ;
const savedNames = new Map ( ) , savedVersions = new Map ( ) ; let currentCase = '' ;
const stable = i => i . toString ( 16 ) . padStart ( 32 , '0' ) ;
const shot = i => ( { id : stable ( 300 + i ) , name : ` 镜头 ${ i } ` , scene _id : stable ( 101 ) , cast : [ { id : stable ( 400 + i ) , entity _id : stable ( 201 ) , form _id : null , appearance _id : null , position : '画面中央' , action : '远望' } ] , visual _prompt : '镜头描述' , motion _prompt : '镜头缓慢推进' , overrides : { } , frame _parameters : { seed : 42 } , video _parameters : { seed : 42 , source _seconds : 5 , num _inference _steps : 20 , guidance _scale : 5 , upscale : false } , 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 : stable ( 101 ) , name : '山海' , description : '清晨海面' , reference _asset _ids : [ ] , location : '海面' , time : '清晨' , weather : '晴' , lighting : '侧光' } ] , entities : [ { id : stable ( 201 ) , name : '旅人' , kind : 'person' , description : '年轻旅人' , reference _asset _ids : [ ] , forms : [ ] , appearances : [ ] } ] , shots : [ 1 , 2 , 3 ] . map ( shot ) , 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 : spec . shots . map ( s => s . id ) , bindings : { } , audio : { mode : 'generated_narration' , voice : 'qa' , speed : 1 , track : null , segments : [ { id : stable ( 501 ) , shot _id : stable ( 301 ) , text : '旁白内容' } ] } , captions : { mode : 'manual' , cues : [ { id : stable ( 601 ) , anchor : 'shot' , shot _id : stable ( 301 ) , start _frame : 0 , end _frame : 120 , text : '字幕内容' , text _override : true , timing _override : true } ] } } ;
2026-11-30 09:12:58 +08:00
if ( process . argv . includes ( '--continuity' ) ) {
spec . schema _version = 4 ; manifest . schema _version = 2 ; manifest . audio . layers = [ ] ; manifest . audio . ducking = true ;
const state = ( ) => ( { summary : '' , motion : '' , location : '' , time : '' , camera : '' , entities : { } } ) ;
for ( const s of spec . shots ) s . continuity = { transition : 'cut' , group _id : null , state _in : state ( ) , state _out : state ( ) , end _prompt : '' , expected _motion : true , endpoint _mode : 'first_frame' } ;
}
2026-11-14 14:07:26 +08:00
const story = mode => ( { id : ` qa- ${ mode } ` , name : savedNames . get ( mode ) || ` 表单回归 ${ mode } ` , kind : 'story' , editing _mode : mode , capabilities : editingCapabilities , spec , revision : savedVersions . get ( mode ) || 1 , version : savedVersions . get ( mode ) || 1 , folder _id : null , created _at : stamp , updated _at : stamp , selections : [ ] , readiness : { ready : false , issues : [ ] } , editor _manifest : mode === 'auto' ? manifest : null } ) ;
const editorDTO = mode => ( { draft _id : ` qa- ${ mode } ` , name : story ( mode ) . name , editing _mode : 'auto' , capabilities : editingCapabilities , version : story ( mode ) . version , revision : story ( mode ) . revision , manifest , issues : [ ] , assets : [ ] } ) ;
const user = { id : 'qa-admin' , username : 'qa_admin' , display _name : '表单验证' , role : 'admin' , disabled : false } ;
const users = [ user , ... Array . from ( { length : 5 } , ( _ , i ) => ( { id : ` user- ${ i } ` , username : ` qa_user_ ${ i } ` , display _name : ` 用户 ${ i } ` , role : 'user' , disabled : false } ) ) ] ;
const image = 'data:image/svg+xml,' + encodeURIComponent ( '<svg xmlns="http://www.w3.org/2000/svg" width="400" height="260"><rect width="400" height="260" fill="#294950"/><circle cx="200" cy="120" r="70" fill="#82c5af"/></svg>' ) ;
const assets = Array . from ( { length : 16 } , ( _ , i ) => ( { id : ` asset- ${ i } ` , name : ` 夹具素材 ${ i } ` , kind : i % 3 === 0 ? 'video' : i % 3 === 1 ? 'image' : 'audio' , mime _type : 'image/svg+xml' , size _bytes : 4096 , width : 400 , height : 260 , duration _seconds : 5 , preview _url : image , thumbnail _url : image , download _url : image , source _job _id : null , origin : 'upload' , tags : [ '表单回归' ] , favorite : false , created _at : stamp } ) ) ;
const folders = [ { id : 'folder-1' , name : '项目素材' , parent _id : null , created _at : stamp , updated _at : stamp } ] ;
const tasks = [ 'image.generate' , 'video.generate' , 'defect.generate' , 'image.reference.generate' , 'video.people.analyze' , 'video.replace' , 'audio.transcribe' , 'audio.speech' , 'math.solve' , 'media.structure' , 'video.compose' ] ;
const caps = tasks . map ( task _type => ( { task _type , label : task _type , model : 'Mock engine' , available : true , input _types : [ ] , defaults : { width : 1024 , height : 576 , num _inference _steps : 20 , seed : 42 , guidance _scale : 5 , num _frames : 121 , fps : 24 , language : 'zh' , voice : 'qa' , speed : 1 , max _tokens : 2048 } , constraints : { width : { min : 256 , max : 2048 , step : 16 } , height : { min : 256 , max : 2048 , step : 16 } , count : { max : 4 } , num _frames : { min : 25 , max : 361 , step : 24 } , voice : { values : [ 'qa' , 'qa2' ] } , language : { values : [ 'zh' , 'en' , 'auto' ] } } , description : '隔离API夹具' } ) ) ;
const scheduler = { available : true , state : 'ready' , reason : null , gpus : [ ] , updated _at : stamp } , capabilities = { items : caps , scheduler , editable _production : { schema _version : 1 } , execution _policy : { timezone : 'Asia/Shanghai' , start : '22:00' , end : '08:00' , batch _open : true , next _batch _at : null , close _behavior : 'finish_current_stage' , batch _window _enabled : false } , workflow _limits : { max _shots : 120 , source _frames : 121 , max _source _frames : 361 , default _source _frames : 121 , default _clip _frames : 120 , max _clip _frames : 360 , fps : 24 } } ;
const page = items => ( { items , total : items . length , page : 1 , page _size : 24 , cursor : 1 } ) ;
const report = { baseUrl : base , scenarios : [ ] , blockedMutations : [ ] , mockedMutations : [ ] , unknown : [ ] , pageErrors : [ ] } ; let anonymous = false ;
async function mock ( route ) { const r = route . request ( ) , u = new URL ( r . url ( ) ) , p = u . pathname ; if ( ! p . startsWith ( '/api/' ) ) return route . continue ( ) ; const k = p . slice ( 4 ) ; if ( ! [ 'GET' , 'HEAD' ] . includes ( r . method ( ) ) ) {
if ( r . method ( ) === 'POST' && /^\/editors\/qa-auto\/(save|plan)$/ . test ( k ) ) { const body = r . postDataJSON ( ) ; report . mockedMutations . push ( { scenario : currentCase , path : k , name : body . name } ) ; if ( k . endsWith ( '/save' ) ) { if ( typeof body . name === 'string' ) savedNames . set ( 'auto' , body . name . trim ( ) ) ; savedVersions . set ( 'auto' , ( savedVersions . get ( 'auto' ) || 1 ) + 1 ) ; return route . fulfill ( { status : 200 , json : editorDTO ( 'auto' ) } ) ; } return route . fulfill ( { status : 200 , json : { plan _hash : 'qa-plan-only' , output _goal : body . output _goal , source _version : body . expected _version , steps : [ ] , issues : [ { code : 'qa_read_only' , message : '浏览器隔离验证停在模拟计划阶段' } ] } } ) ; }
report . blockedMutations . push ( { method : r . method ( ) , path : k } ) ; return route . fulfill ( { status : 405 , json : { detail : 'Read-only form regression: mutation blocked' } } ) ; } let value ;
if ( k === '/auth/me' ) { if ( anonymous ) return route . fulfill ( { status : 401 , json : { detail : 'Mock anonymous login page' } } ) ; value = { user , csrf _token : 'qa-only' } ; }
else if ( k === '/capabilities' ) value = capabilities ; else if ( k === '/system/status' ) value = { ... capabilities , models : caps , inference _online : false , environment : 'test' , database _backend : 'sqlite' } ;
else if ( k === '/auth/users' ) value = page ( users ) ; else if ( k === '/auth/tokens' ) value = { items : [ ] } ; else if ( k === '/folders' ) value = { items : folders } ;
else if ( k === '/stories/capabilities' ) value = { enabled : true , reference _generation : { available : true , task _type : 'image.generate' , max _reference _images : 4 , model : 'Mock' , reason : null } , frame _text _generation : { available : true } , max _shots : 120 } ;
else if ( k === '/stories' ) value = page ( [ story ( 'auto' ) , story ( 'manual' ) ] ) ; else if ( /^\/stories\/qa-(auto|manual)$/ . test ( k ) ) value = story ( k . endsWith ( 'manual' ) ? 'manual' : 'auto' ) ;
else if ( k . startsWith ( '/editors/' ) ) value = editorDTO ( k . endsWith ( 'manual' ) ? 'manual' : 'auto' ) ;
else if ( /\/preview$/ . test ( k ) ) value = { shots : spec . shots . map ( s => ( { shot _id : s . id , context _hash : 'qa' , frame _prompt : s . visual _prompt , motion _prompt : s . motion _prompt , references : [ ] , effective _settings : { } , errors : [ ] } ) ) , errors : [ ] } ;
else if ( /\/readiness$/ . test ( k ) ) value = { ready : false , issues : [ ] } ; else if ( /\/candidates$|\/runs$/ . test ( k ) ) value = page ( [ ] ) ;
else if ( k === '/assets' || k === '/shared-assets' ) value = page ( assets . map ( a => k === '/shared-assets' ? { ... a , publisher _id : user . id , publisher _name : user . display _name , is _owner : true , version : 1 } : a ) ) ; else if ( k . startsWith ( '/assets/' ) ) value = assets . find ( a => a . id === k . split ( '/' ) [ 2 ] ) || assets [ 1 ] ;
else if ( [ '/jobs' , '/workflow-runs' , '/workflows' , '/batches' ] . includes ( k ) ) value = page ( [ ] ) ; else { report . unknown . push ( k ) ; value = page ( [ ] ) ; } return route . fulfill ( { status : 200 , json : value } ) ; }
async function measure ( p ) { return p . evaluate ( ( ) => {
const rect = e => { const r = e . getBoundingClientRect ( ) ; return { x : r . x , y : r . y , width : r . width , height : r . height , right : r . right , bottom : r . bottom } ; } ;
const shown = e => { const s = getComputedStyle ( e ) , r = e . getBoundingClientRect ( ) ; return r . width > 0 && r . height > 0 && s . visibility !== 'hidden' && s . display !== 'none' ; } ;
const overlay = [ ... document . querySelectorAll ( '.el-overlay' ) ] . filter ( shown ) . at ( - 1 ) ;
const inScope = e => ! overlay || overlay . contains ( e ) ;
const description = e => ( { tag : e . tagName , class : e . className , label : e . getAttribute ( 'aria-label' ) || e . querySelector ( 'input' ) ? . placeholder || e . closest ( 'label' ) ? . textContent . trim ( ) . slice ( 0 , 45 ) || e . textContent . trim ( ) . slice ( 0 , 45 ) , rect : rect ( e ) } ) ;
const controls = [ ... document . querySelectorAll ( '.el-input,.el-select,.el-input-number,input,select' ) ] . filter ( e => shown ( e ) && inScope ( e ) ) . filter ( e => ! e . parentElement . closest ( '.el-input,.el-select,.el-input-number' ) ) . filter ( e => ! e . matches ( 'input[type=checkbox],input[type=radio],input[type=file],input[type=range],input[type=color],input[type=hidden]' ) ) ;
2026-11-30 09:12:58 +08:00
const fields = controls . map ( e => { const s = getComputedStyle ( e ) , parent = e . parentElement , ps = getComputedStyle ( parent ) , full = e . matches ( '.ui-field--full' ) || parent . matches ( '.ui-field--full' ) || e . closest ( 'label' ) ? . matches ( '.ui-field--full' ) , compact = ! ! e . closest ( '.ui-actions--compact,.el-pagination,.compact,.is-compact' ) , flexible = e . matches ( '.picker-search-input' ) || ! ! e . closest ( '.library-search-query' ) ; return { ... description ( e ) , full : ! ! full , compact , flexible , parentClass : parent . className , parentContentWidth : parent . clientWidth - parseFloat ( ps . paddingLeft ) - parseFloat ( ps . paddingRight ) , cssWidth : s . width , controlWidth : parseFloat ( s . getPropertyValue ( '--ui-control-width' ) ) || 220 } ; } ) ;
2026-11-14 14:07:26 +08:00
const buttons = [ ... document . querySelectorAll ( '.el-button' ) ] . filter ( e => shown ( e ) && inScope ( e ) ) . map ( e => ( { ... description ( e ) , icon : e . matches ( '.is-circle' ) || ( ! e . textContent . trim ( ) && ! ! e . querySelector ( '.el-icon' ) ) , text : e . classList . contains ( 'is-text' ) , compactText : ! ! e . closest ( '.library-card' ) && e . matches ( '.is-text,.is-link' ) } ) ) ;
const groups = [ ... document . querySelectorAll ( '.ui-actions,.ui-form-row,.ui-form-grid,.el-dialog__footer' ) ] . filter ( e => shown ( e ) && inScope ( e ) ) . map ( e => { const s = getComputedStyle ( e ) ; return { ... description ( e ) , gap : s . gap , columnGap : parseFloat ( s . columnGap ) || 0 , rowGap : parseFloat ( s . rowGap ) || 0 , children : [ ... e . children ] . filter ( shown ) . map ( description ) } ; } ) ;
const actions = document . querySelector ( '.editor-shot-layout > aside > .editor-toolbar' ) ;
const sidebar = actions ? { ... description ( actions ) , buttons : [ ... actions . querySelectorAll ( ':scope > .el-button' ) ] . map ( description ) } : null ;
const pickerToolbar = [ ... document . querySelectorAll ( '.picker-toolbar' ) ] . filter ( e => shown ( e ) && inScope ( e ) ) . map ( e => ( { ... description ( e ) , buttons : [ ... e . querySelectorAll ( '.el-button' ) ] . filter ( shown ) . map ( description ) , fields : [ ... e . querySelectorAll ( '.el-input,.el-select' ) ] . filter ( shown ) . map ( description ) } ) ) ;
const folderAlignment = [ ... document . querySelectorAll ( '.story-navigation .folder-destination' ) ] . filter ( e => shown ( e ) && inScope ( e ) ) . map ( e => { const select = [ ... e . querySelectorAll ( '.folder-field select' ) ] . filter ( shown ) . at ( - 1 ) , button = [ ... e . querySelectorAll ( '.folder-manager > .el-button' ) ] . filter ( shown ) [ 0 ] ; return select && button ? { select : description ( select ) , button : description ( button ) , bottomDifference : Math . abs ( select . getBoundingClientRect ( ) . bottom - button . getBoundingClientRect ( ) . bottom ) } : null ; } ) . filter ( Boolean ) ;
const dialogs = [ ... document . querySelectorAll ( '.el-dialog' ) ] . filter ( shown ) . map ( description ) ;
const pickerCards = [ ... document . querySelectorAll ( '.picker-item' ) ] . filter ( e => shown ( e ) && inScope ( e ) ) . map ( e => ( { ... description ( e ) , captions : [ ... e . querySelectorAll ( ':scope > .picker-name,:scope > small,:scope > span:last-child' ) ] . filter ( shown ) . map ( description ) } ) ) ;
2026-11-30 09:12:58 +08:00
const formAlignment = [ ... document . querySelectorAll ( '.ui-form-row,.ui-form-grid' ) ] . filter ( e => shown ( e ) && inScope ( e ) ) . map ( e => {
const items = [ ... e . children ] . filter ( shown ) . filter ( item => ! item . matches ( '.ui-field--full,.ui-form-row,.ui-form-grid,.filter-tabs' ) ) . map ( item => {
const selector = '.el-switch,.el-input-number,.el-input,.el-select,.el-checkbox__inner,.el-radio__inner,input:not([type=file],[type=range],[type=color],[type=hidden]),select,button' ;
const control = item . matches ( selector ) ? item : [ ... item . querySelectorAll ( selector ) ] . find ( shown ) ;
if ( ! control || ! shown ( control ) ) return null ;
const r = item . getBoundingClientRect ( ) , c = control . getBoundingClientRect ( ) , s = getComputedStyle ( item ) ;
return { label : description ( item ) . label , kind : control . matches ( 'button' ) ? 'button' : control . matches ( 'input[type=checkbox],input[type=radio],.el-switch,.el-checkbox__inner,.el-radio__inner' ) ? 'check' : 'field' , center : c . y + c . height / 2 , height : c . height , outerTop : r . y - ( parseFloat ( s . marginTop ) || 0 ) , outerBottom : r . bottom + ( parseFloat ( s . marginBottom ) || 0 ) } ;
} ) . filter ( Boolean ) ;
const pairs = [ ] ; for ( let i = 0 ; i < items . length ; i ++ ) for ( let j = i + 1 ; j < items . length ; j ++ ) if ( Math . min ( items [ i ] . outerBottom , items [ j ] . outerBottom ) - Math . max ( items [ i ] . outerTop , items [ j ] . outerTop ) > 10 ) pairs . push ( { left : items [ i ] , right : items [ j ] , difference : Math . abs ( items [ i ] . center - items [ j ] . center ) } ) ;
return { class : e . className , items , pairs } ;
} ) ;
return { viewport : { width : innerWidth , height : innerHeight } , document : { width : document . documentElement . scrollWidth , height : document . documentElement . scrollHeight , top : document . documentElement . scrollTop } , fields , buttons , groups , sidebar , pickerToolbar , folderAlignment , dialogs , pickerCards , formAlignment } ;
2026-11-14 14:07:26 +08:00
} ) ; }
2026-11-30 09:12:58 +08:00
function validate ( m ) { const failures = [ ] ; for ( const f of m . fields ) { if ( Math . abs ( f . rect . height - 36 ) > 1.5 ) failures . push ( { kind : 'control-height' , ... f } ) ; const expected = Math . min ( f . controlWidth , f . parentContentWidth ) ; if ( ! f . full && ! f . compact && ! f . flexible && Math . abs ( f . rect . width - expected ) > 2 ) failures . push ( { kind : 'control-width' , expected , ... f } ) ; if ( f . full && Math . abs ( f . rect . width - f . parentContentWidth ) > 2 ) failures . push ( { kind : 'full-field-width' , expected : f . parentContentWidth , ... f } ) ; }
2026-11-14 14:07:26 +08:00
for ( const b of m . buttons ) if ( b . compactText ? b . rect . height < 23 : ( m . viewport . width > 760 && Math . abs ( b . rect . height - 36 ) > 1.5 ) || ( m . viewport . width <= 760 && b . rect . height < 35 ) ) failures . push ( { kind : 'button-height' , ... b } ) ;
for ( const g of m . groups ) { const children = g . children . filter ( c => c . rect . width > 0 ) ; if ( children . length > 1 && g . columnGap < 8 ) failures . push ( { kind : 'action-gap' , ... g } ) ; }
if ( m . document . width > m . viewport . width + 2 || m . document . height > m . viewport . height + 2 ) failures . push ( { kind : 'document-overflow' , document : m . document , viewport : m . viewport } ) ;
if ( m . sidebar ) { const rows = new Map ( ) ; for ( const b of m . sidebar . buttons ) { const y = Math . round ( b . rect . y ) ; rows . set ( y , ( rows . get ( y ) || 0 ) + 1 ) ; } if ( m . sidebar . buttons . length !== 4 || [ ... rows . values ( ) ] . some ( n => n < 2 ) ) failures . push ( { kind : 'shot-actions-not-two-columns' , sidebar : m . sidebar } ) ; }
if ( m . viewport . width > 760 ) for ( const bar of m . pickerToolbar ) { const search = bar . buttons . find ( b => b . label . includes ( '搜索' ) ) ; if ( search && ! bar . fields . some ( f => Math . min ( f . rect . bottom , search . rect . bottom ) > Math . max ( f . rect . y , search . rect . y ) + 5 ) ) failures . push ( { kind : 'picker-search-isolated-row' , bar } ) ; }
if ( m . viewport . width > 760 ) for ( const pair of m . folderAlignment ) if ( pair . bottomDifference > 1 ) failures . push ( { kind : 'folder-button-bottom-alignment' , ... pair } ) ;
2026-11-30 09:12:58 +08:00
if ( m . viewport . width > 760 ) for ( const row of m . formAlignment ) for ( const pair of row . pairs ) if ( pair . difference > 1.5 ) failures . push ( { kind : 'form-control-center-alignment' , class : row . class , ... pair } ) ;
2026-11-14 14:07:26 +08:00
for ( const dialog of m . dialogs ) if ( dialog . rect . y < - 1 || dialog . rect . bottom > m . viewport . height + 1 || dialog . rect . x < - 1 || dialog . rect . right > m . viewport . width + 1 ) failures . push ( { kind : 'dialog-outside-viewport' , dialog } ) ;
const clippedCards = m . pickerCards . filter ( card => card . captions . some ( c => c . rect . bottom > card . rect . bottom + 1 || c . rect . y < card . rect . y - 1 ) ) ; if ( clippedCards . length ) failures . push ( { kind : 'picker-card-caption-clipped' , count : clippedCards . length , example : clippedCards [ 0 ] } ) ;
return failures ; }
async function verifyRename ( p , result ) {
const title = p . getByRole ( 'textbox' , { name : '故事名称' , exact : true } ) ;
if ( ! await title . isEditable ( ) ) { result . failures . push ( { kind : 'story-name-not-editable' } ) ; return ; }
const start = report . mockedMutations . length , first = '浏览器保存名称' , second = '浏览器生成前名称' ;
await title . fill ( first ) ; const saving = p . waitForResponse ( r => r . request ( ) . method ( ) === 'POST' && new URL ( r . url ( ) ) . pathname === '/api/editors/qa-auto/save' ) ; await p . locator ( '.story-studio-toolbar' ) . getByRole ( 'button' , { name : '保存编辑' , exact : true } ) . click ( ) ; const saved = await ( await saving ) . json ( ) ;
if ( saved . name !== first ) result . failures . push ( { kind : 'rename-save-response' , actual : saved . name } ) ;
await p . waitForFunction ( ( ) => ! document . querySelector ( '.story-studio-toolbar' ) . textContent . includes ( '未保存' ) ) ;
await title . fill ( second ) ; const planning = p . waitForResponse ( r => r . request ( ) . method ( ) === 'POST' && new URL ( r . url ( ) ) . pathname === '/api/editors/qa-auto/plan' ) ; await p . locator ( '.editable-production > .editor-toolbar' ) . getByRole ( 'button' , { name : '自动生成初稿并成片' , exact : true } ) . click ( ) ; await planning ;
const requests = report . mockedMutations . slice ( start ) ; const sentNames = requests . filter ( r => r . path . endsWith ( '/save' ) ) . map ( r => r . name ) ;
if ( sentNames . length !== 2 || sentNames [ 0 ] !== first || sentNames [ 1 ] !== second ) result . failures . push ( { kind : 'rename-name-not-sent' , sentNames } ) ;
result . rename = { editable : true , sentNames , planMocked : requests . some ( r => r . path . endsWith ( '/plan' ) ) , realApiWrites : 0 } ;
}
async function mode ( p , text ) { await p . locator ( '.story-mode-tabs button' ) . filter ( { hasText : text } ) . click ( ) ; await p . waitForTimeout ( 80 ) ; }
2026-11-30 09:12:58 +08:00
const storyCase = ( editing , stage ) => ( { name : ` ${ editing } - ${ stage } ` , route : ` /studio/qa- ${ editing } ` , prepare : async p => { await p . locator ( editing === 'auto' ? '.editable-production' : '.story-workspace' ) . waitFor ( ) ; if ( stage === 'baseline' ) await mode ( p , '01' ) ; if ( stage === 'render' ) { await mode ( p , '03' ) ; if ( editing === 'auto' ) await p . locator ( '.editor-cue' ) . first ( ) . scrollIntoViewIfNeeded ( ) ; } } } ) ;
2026-11-14 14:07:26 +08:00
const parameterCase = ( kind , button = '参数' ) => ( { name : ` ${ kind } -parameters ` , route : ` /create/ ${ kind } ` , prepare : async p => { await p . locator ( '.parameter-chip' ) . filter ( { hasText : button } ) . first ( ) . click ( ) ; await p . locator ( '.el-popover:visible .parameter-form' ) . waitFor ( ) ; } } ) ;
const userDialog = { name : 'new-user' , route : '/account' , prepare : async p => { await p . getByRole ( 'button' , { name : '新增用户' , exact : true } ) . click ( ) ; await p . locator ( '.el-dialog:visible .user-form' ) . waitFor ( ) ; } } ;
2026-11-30 09:12:58 +08:00
const unlabelledElementCase = { name : 'unlabelled-element-item' , route : '/account' , prepare : async p => {
await p . locator ( '.avatar-button' ) . click ( ) ; await p . getByRole ( 'menuitem' , { name : '修改用户名' , exact : true } ) . click ( ) ;
const form = p . locator ( '.el-dialog:visible .ui-form-grid' ) ; await form . waitFor ( ) ;
await form . evaluate ( e => { const items = [ ... e . querySelectorAll ( ':scope >.el-form-item' ) ] . slice ( 0 , 2 ) ; for ( const item of items ) { item . classList . remove ( 'ui-field--full' ) ; item . style . setProperty ( '--ui-control-width' , '160px' ) ; } items [ 1 ] . querySelector ( ':scope >.el-form-item__label' ) ? . remove ( ) ; } ) ;
const geometry = await form . evaluate ( e => { const [ a , b ] = [ ... e . querySelectorAll ( ':scope >.el-form-item' ) ] ; const mid = x => { const r = x . querySelector ( '.el-input' ) . getBoundingClientRect ( ) ; return r . y + r . height / 2 } ; return { centerDifference : Math . abs ( mid ( a ) - mid ( b ) ) , placeholderHeight : parseFloat ( getComputedStyle ( b ) . paddingTop ) } ; } ) ;
if ( geometry . centerDifference > 1.5 || geometry . placeholderHeight < 20 ) throw new Error ( 'Unlabelled Element item lost its title slot: ' + JSON . stringify ( geometry ) ) ;
} } ;
const all = [ unlabelledElementCase , { name : 'login' , route : '/login' } , { name : 'stories' , route : '/studio' } , ... [ 'manual' , 'auto' ] . flatMap ( e => [ 'baseline' , 'shots' , 'render' ] . map ( s => storyCase ( e , s ) ) ) , ... [ 'image' , 'video' , 'defect' , 'image-edit' , 'video-edit' ] . map ( k => ( { name : ` create- ${ k } ` , route : ` /create/ ${ k } ` } ) ) , parameterCase ( 'image' ) , parameterCase ( 'video' ) , parameterCase ( 'defect' ) , { name : 'video-duration' , route : '/create/video' , prepare : async p => { await p . getByRole ( 'button' , { name : '设置镜头时长' } ) . click ( ) ; } } , ... [ 'audio' , 'math' , 'analyze' , 'assets' , 'tasks' , 'account' ] . map ( k => ( { name : k , route : ` / ${ k } ` } ) ) , { name : 'audio-speech' , route : '/audio' , prepare : async p => { await p . getByRole ( 'button' , { name : /配音生成/ } ) . click ( ) ; } } , userDialog , ... [ [ 'password' , '修改密码' ] , [ 'username' , '修改用户名' ] ] . map ( ( [ name , label ] ) => ( { name , route : '/account' , prepare : async p => { await p . locator ( '.avatar-button' ) . click ( ) ; await p . getByRole ( 'menuitem' , { name : label , exact : true } ) . click ( ) ; await p . locator ( '.el-dialog:visible' ) . waitFor ( ) ; } } ) ) , { name : 'folder-dialog' , route : '/studio' , prepare : async p => { await p . getByRole ( 'button' , { name : '新建文件夹' , exact : true } ) . first ( ) . click ( ) ; await p . locator ( '.el-dialog:visible' ) . waitFor ( ) ; } } , { name : 'asset-picker' , route : '/audio' , prepare : async p => { await p . locator ( '.from-library' ) . first ( ) . click ( ) ; await p . locator ( '.asset-picker:visible .picker-grid' ) . waitFor ( ) ; } } , { name : 'shared-picker' , route : '/audio' , prepare : async p => { await p . locator ( '.from-library' ) . first ( ) . click ( ) ; await p . locator ( '.asset-picker:visible .filter-tabs' ) . getByRole ( 'button' , { name : '共享素材' , exact : true } ) . click ( ) ; await p . locator ( '.shared-asset-picker .picker-grid' ) . waitFor ( ) ; } } ] ;
2026-11-14 14:07:26 +08:00
async function main ( ) { const tempRoot = fs . realpathSync ( os . tmpdir ( ) ) , dir = fs . mkdtempSync ( path . join ( tempRoot , 'cmvr-form-layout-' ) ) ; let browser ;
try { browser = await pw . chromium . launch ( { headless : true , channel : process . env . PLAYWRIGHT _CHANNEL || 'chrome' } ) ;
const candidates = quick ? [ storyCase ( 'auto' , 'shots' ) , storyCase ( 'manual' , 'shots' ) , parameterCase ( 'image' ) , parameterCase ( 'video' ) , userDialog , { name : 'stories' , route : '/studio' } ] : mobile ? [ storyCase ( 'auto' , 'shots' ) , parameterCase ( 'image' ) , userDialog , { name : 'assets' , route : '/assets' } ] : all ;
const cases = caseFilter ? candidates . filter ( c => caseFilter . includes ( c . name ) ) : candidates ;
if ( ! cases . length ) throw new Error ( 'No form scenarios match --case.' ) ;
const viewports = viewportOption ? [ { width : viewportOption [ 0 ] , height : viewportOption [ 1 ] } ] : mobile ? [ { width : 390 , height : 844 } ] : quick ? [ { width : 1440 , height : 900 } ] : [ { width : 1440 , height : 900 } , { width : 1920 , height : 1080 } ] ;
for ( const viewport of viewports ) {
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 p = await context . newPage ( ) ; p . on ( 'pageerror' , e => report . pageErrors . push ( e . message ) ) ; p . setDefaultTimeout ( 8000 ) ;
2026-11-30 09:12:58 +08:00
for ( const c of cases ) { anonymous = c . name === 'login' ; savedNames . clear ( ) ; savedVersions . clear ( ) ; currentCase = ` ${ viewport . width } - ${ c . name } ` ; const result = { name : c . name , viewport , failures : [ ] } ; report . scenarios . push ( result ) ; try { await p . goto ( base + c . route , { waitUntil : 'networkidle' } ) ; await p . locator ( anonymous ? '.login-form-box' : '.app-header' ) . waitFor ( ) ; if ( c . prepare ) await c . prepare ( p ) ; await p . waitForTimeout ( 350 ) ; result . measurement = await measure ( p ) ; result . failures = validate ( result . measurement ) ; result . screenshot = path . join ( dir , ` ${ viewport . width } - ${ c . name } .png ` ) ; await p . screenshot ( { path : result . screenshot } ) ; if ( c . name === 'auto-shots' ) await verifyRename ( p , result ) ; } catch ( e ) { result . failures . push ( { kind : 'scenario-error' , message : e . message } ) ; } console . log ( JSON . stringify ( { name : c . name , viewport , controls : result . measurement ? . fields . length , maxControlCenterDifference : Math . max ( 0 , ... ( result . measurement ? . formAlignment || [ ] ) . flatMap ( row => row . pairs . map ( pair => pair . difference ) ) ) , maxCheckCenterDifference : Math . max ( 0 , ... ( result . measurement ? . formAlignment || [ ] ) . flatMap ( row => row . pairs . filter ( pair => pair . left . kind === 'check' || pair . right . kind === 'check' ) . map ( pair => pair . difference ) ) ) , issues : result . failures , rename : result . rename , screenshot : result . screenshot } ) ) ; }
2026-11-14 14:07:26 +08:00
await context . close ( ) ;
}
console . log ( 'SUMMARY ' + JSON . stringify ( { scenarios : report . scenarios . length , issues : report . scenarios . reduce ( ( n , s ) => n + s . failures . length , 0 ) , realApiWrites : 0 , mockedMutations : report . mockedMutations , blockedMutations : report . blockedMutations , unknown : report . unknown , pageErrors : report . pageErrors } ) ) ;
if ( review ) { console . log ( ` REVIEW ${ dir } ; create review.done after visual inspection to clean up. ` ) ; await new Promise ( resolve => { const timer = setInterval ( ( ) => { if ( fs . existsSync ( path . join ( dir , 'review.done' ) ) ) { clearInterval ( timer ) ; resolve ( ) ; } } , 250 ) ; } ) ; }
if ( report . scenarios . some ( s => s . failures . length ) || report . blockedMutations . length || report . pageErrors . length || report . unknown . length ) process . exitCode = 1 ;
} finally { await browser ? . close ( ) ; const relative = path . relative ( tempRoot , fs . realpathSync ( dir ) ) ; if ( path . isAbsolute ( relative ) || relative . startsWith ( '..' ) || ! relative . startsWith ( 'cmvr-form-layout-' ) ) throw new Error ( 'Unexpected artifact directory' ) ; fs . rmSync ( dir , { recursive : true , force : true } ) ; }
}
main ( ) . catch ( e => { console . error ( e ) ; process . exitCode = 1 } ) ;