Restructure backend and frontend modules; add story, library, and editor schema migrations. Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews. Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
151 lines
16 KiB
JavaScript
151 lines
16 KiB
JavaScript
/*
|
|
* Browser regression for the editable story studio, without a backend or models.
|
|
* Run against an already running Vite server:
|
|
* node tests/browser/story-editor-scroll.cjs [--expect-red] [--desktop-only|--mobile-only]
|
|
* SCROLL_QA_BASE selects the server (default http://127.0.0.1:5173).
|
|
* PLAYWRIGHT_MODULE may point to an existing Playwright installation.
|
|
* Set PLAYWRIGHT_CHANNEL to select a browser channel (default chrome).
|
|
* All /api requests are mocked. Every non-read request fails closed.
|
|
* Screenshots live in an automatically removed OS temporary directory.
|
|
*/
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
let playwright;
|
|
for (const candidate of [process.env.PLAYWRIGHT_MODULE, 'playwright', path.join(os.homedir(),'.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright')].filter(Boolean)) {
|
|
try { playwright = require(candidate); break; } catch { /* Try the next installed runtime. */ }
|
|
}
|
|
if (!playwright) throw new Error('Install Playwright or set PLAYWRIGHT_MODULE to its module path.');
|
|
const base = process.env.SCROLL_QA_BASE || 'http://127.0.0.1:5173';
|
|
const expectRed = process.argv.includes('--expect-red');
|
|
const desktopOnly = process.argv.includes('--desktop-only');
|
|
const mobileOnly = process.argv.includes('--mobile-only');
|
|
const id = 'qa-story-scroll';
|
|
const stamp = '2026-11-13T03:00:00Z';
|
|
const shots = Array.from({length:12}, (_, i) => ({id:`shot-${i+1}`,name:`分镜 ${i+1}`,scene_id:null,cast:[],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:[],entities:[],shots,render:{fps:24,total_frames:1440,fit:'contain',audio:null,subtitles:[],template_version:'plain-v1'}};
|
|
const editingCapabilities = {mode_switch:true,manual:true,auto:true};
|
|
const manifest = {schema_version:1,source_kind:'story',editing_mode:'auto',spec,shot_ids:shots.map(s=>s.id),bindings:{},audio:{mode:'generated_narration',voice:'default',speed:1,track:null,segments:Array.from({length:3},(_,i)=>({id:`segment-${i+1}`,shot_id:shots[0].id,text:`旁白段 ${i+1}:最后一段的删除、导入及重配操作必须能滚动到达。`}))},captions:{mode:'none',cues:[]}};
|
|
const story = {id,name:'分镜滚动回归',kind:'story',editing_mode:'auto',capabilities:editingCapabilities,spec,revision:1,version:1,created_at:stamp,updated_at:stamp,selections:[],readiness:{ready:false,issues:[]},editor_manifest:manifest};
|
|
const editor = {draft_id:id,name:story.name,editing_mode:'auto',capabilities:editingCapabilities,version:1,revision:1,manifest,issues:[],assets:[]};
|
|
const runs = Array.from({length:25},(_,i)=>({id:`qa-run-${String(i+1).padStart(3,'0')}`,draft_id:id,draft_revision:i+1,state:'succeeded',desired_state:'run',execution_mode:'interactive',version:1,created_at:stamp,output_goal:'media',result_assets:[],completed_steps:1,total_steps:1}));
|
|
const scheduler = {available:true,state:'ready',reason:null,gpus:[],updated_at:stamp};
|
|
const 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};
|
|
const capabilities = {items:[],scheduler,execution_policy:policy,workflow_limits:{max_shots:120,source_frames:120,max_clip_frames:120,fps:24}};
|
|
const page = items => ({items,total:items.length,page:1,page_size:100,cursor:1});
|
|
const report = {baseUrl:base,mutations:[],unknown:[],errors:[],scenarios:[]};
|
|
async function mock(route) {
|
|
const request=route.request(), u=new URL(request.url()), p=u.pathname;
|
|
if (!p.startsWith('/api/')) return route.continue();
|
|
if (!['GET','HEAD'].includes(request.method())) {report.mutations.push({method:request.method(),path:p});return route.fulfill({status:405,json:{detail:'Read-only browser regression: mutation blocked'}});}
|
|
const key=p.slice(4); let value;
|
|
if(key==='/auth/me') value={user:{id:'qa-user',username:'qa_user',display_name:'滚动回归',role:'admin'},csrf_token:'qa-only'};
|
|
else if(key==='/capabilities') value=capabilities;
|
|
else if(key==='/system/status') value={...capabilities,models:[],inference_online:false,environment:'test',database_backend:'sqlite'};
|
|
else if(key==='/folders') value={items:[]};
|
|
else if(key==='/stories/capabilities') value={enabled:true,reference_generation:{available:false,task_type:'image.generate',max_reference_images:4,model:'qa',reason:'mock'},frame_text_generation:{available:true},max_shots:120};
|
|
else if(key===`/stories/${id}`) value=story;
|
|
else if(key===`/editors/${id}`) value=editor;
|
|
else if(key===`/stories/${id}/preview`) value={shots:[],errors:[]};
|
|
else if(key===`/stories/${id}/runs`||key==='/workflow-runs') value=page(runs);
|
|
else if(key.startsWith('/workflow-runs/')) value={draft:story,run:runs.find(r=>r.id===key.split('/')[2])||runs[0],steps:[],jobs:[],cursor:1};
|
|
else if(key===`/stories/${id}/candidates`) value=page([]);
|
|
else if(['/jobs','/workflows','/batches','/assets','/shared-assets','/stories'].includes(key)) value=page([]);
|
|
else {report.unknown.push(key);value=page([]);}
|
|
return route.fulfill({status:200,json:value});
|
|
}
|
|
async function geometry(p) {
|
|
return p.evaluate(()=>{
|
|
const measure=e=>{if(!e)return null;const r=e.getBoundingClientRect(),s=getComputedStyle(e);return {display:s.display,clientHeight:e.clientHeight,scrollHeight:e.scrollHeight,clientWidth:e.clientWidth,scrollWidth:e.scrollWidth,scrollTop:e.scrollTop,overflow:s.overflow,overflowY:s.overflowY,flex:s.flex,minHeight:s.minHeight,maxHeight:s.maxHeight,gridColumn:s.gridColumn,overscroll:s.overscrollBehavior,scrollbarColor:s.scrollbarColor,scrollbarWidth:s.scrollbarWidth,scrollbarGutter:s.scrollbarGutter,focusVisible:e.matches(':focus-visible'),tabIndex:e.tabIndex,rect:{x:r.x,y:r.y,right:r.right,bottom:r.bottom,width:r.width,height:r.height}};};
|
|
return {viewport:{width:innerWidth,height:innerHeight},document:measure(document.documentElement),body:measure(document.body),header:measure(document.querySelector('.app-header')),studio:measure(document.querySelector('.story-studio')),editor:measure(document.querySelector('.editable-production')),shotBody:measure(document.querySelector('.editor-shot-body')),shotEditor:measure(document.querySelector('.editor-shot-body .story-shot-editor')),videoBinding:measure(document.querySelectorAll('.editor-binding')[1]),history:measure(document.querySelector('.editable-production > details:last-of-type')),timelines:document.querySelectorAll('.editor-timeline,.story-timeline').length};
|
|
});
|
|
}
|
|
const transparent = color => /^(transparent|rgba\(0, 0, 0, 0\)) (transparent|rgba\(0, 0, 0, 0\))$/.test(color);
|
|
function unchangedPage(a,b){return a.document.scrollTop===b.document.scrollTop&&a.body.scrollTop===b.body.scrollTop&&a.header.rect.y===b.header.rect.y&&a.studio.scrollTop===b.studio.scrollTop;}
|
|
async function bringIntoEditor(p,selector,last=false){
|
|
const loc=last?p.locator(selector).last():p.locator(selector).first();
|
|
await loc.evaluate(e=>{const panel=document.querySelector('.editable-production');panel.scrollTop+=e.getBoundingClientRect().top-panel.getBoundingClientRect().top-22;});
|
|
return loc.evaluate(e=>{const r=e.getBoundingClientRect(),panel=document.querySelector('.editable-production'),b=panel.getBoundingClientRect();return {visible:r.y>=b.y-1&&r.bottom<=b.bottom+1,top:r.y,bottom:r.bottom,panelTop:b.y,panelBottom:b.bottom,scrollTop:panel.scrollTop};});
|
|
}
|
|
async function greenChecks(p,scenario,touch){
|
|
const check=(ok,text)=>{if(!ok)scenario.failures.push(text);};
|
|
const original=scenario.before, panel=p.locator('.editable-production');
|
|
// Only inspect the auto/manual switch; exercising it would require a mutation.
|
|
const returnButton=p.locator('.story-navigation').getByRole('button',{name:'返回逐步骤人工确认',exact:true});
|
|
scenario.returnButton={visible:await returnButton.isVisible(),rect:await returnButton.boundingBox()};
|
|
check(scenario.returnButton.visible,'Auto mode return button is missing from the capability-aware fixture');
|
|
scenario.navigation=await p.locator('nav.side-nav a').evaluateAll(links=>links.map(a=>new URL(a.href).pathname));
|
|
check(scenario.navigation.length>0,'Sidebar navigation is missing');
|
|
check(!scenario.navigation.some(href=>['/workflow','/batch','/compose'].includes(href)),'Sidebar still links to a retired production page');
|
|
check(original.editor.overscroll==='contain','Editable production does not contain edge scrolling');
|
|
check(original.shotEditor.display==='grid','Shot form must retain its semantic grid layout');
|
|
check(Math.abs(original.shotBody.rect.width-original.shotEditor.rect.width)<=4,'Shot form leaves an unintended empty grid column');
|
|
check(original.shotEditor.overflowY==='visible'&&original.shotEditor.maxHeight==='none','Shot form retains a nested scroll trap');
|
|
await p.mouse.move(1,1);await panel.evaluate(e=>e.blur());
|
|
const off=await geometry(p);
|
|
const r=off.editor.rect;await p.mouse.move(r.right-8,r.y+Math.min(80,r.height/2));
|
|
const hover=await geometry(p);
|
|
check(touch?!transparent(off.editor.scrollbarColor):transparent(off.editor.scrollbarColor),'Scrollbar visibility outside hover/focus is wrong');
|
|
check(!transparent(hover.editor.scrollbarColor),'Hovered scrollbar is invisible');
|
|
check(off.editor.clientWidth===hover.editor.clientWidth&&off.editor.clientHeight===hover.editor.clientHeight,'Hover changes scrollbar geometry');
|
|
check(off.editor.scrollbarWidth==='thin'&&off.editor.scrollbarGutter.includes('stable'),'Thin scrollbar geometry is not stable');
|
|
scenario.scrollbar={off:off.editor.scrollbarColor,hover:hover.editor.scrollbarColor,stable:off.editor.clientWidth===hover.editor.clientWidth};
|
|
scenario.video=await bringIntoEditor(p,'.editor-binding',true);check(scenario.video.visible,'Final video material controls are unreachable');
|
|
scenario.narration=await bringIntoEditor(p,'.editor-shot-body > label:last-of-type .editor-toolbar > button:last-child');check(scenario.narration.visible,'Final narration controls are unreachable');
|
|
scenario.lastShot=await bringIntoEditor(p,'.editor-shot-layout > aside > button',true);check(scenario.lastShot.visible,'Last shot selection is unreachable');
|
|
await p.locator('.editable-production > details:last-of-type').evaluate(e=>e.open=true);
|
|
scenario.lastHistory=await bringIntoEditor(p,'.editor-history',true);check(scenario.lastHistory.visible,'Expanded final history entry is unreachable');
|
|
await panel.evaluate(e=>e.scrollTop=0);await p.mouse.move(1,1);await p.keyboard.press('Tab');await panel.evaluate(e=>e.focus({preventScroll:true}));
|
|
const focus=await geometry(p);check(focus.editor.tabIndex===0&&focus.editor.focusVisible,'Editor is not keyboard focusable');check(!transparent(focus.editor.scrollbarColor),'Focused scrollbar is invisible');
|
|
await p.keyboard.press('End');
|
|
await p.waitForFunction(()=>{const e=document.querySelector('.editable-production');return e.scrollTop>=e.scrollHeight-e.clientHeight-2;},{},{timeout:2000}).catch(()=>undefined);
|
|
const keyboard=await geometry(p);scenario.keyboard={scrollTop:keyboard.editor.scrollTop,maxScrollTop:keyboard.editor.scrollHeight-keyboard.editor.clientHeight,focusColor:focus.editor.scrollbarColor};
|
|
check(keyboard.editor.scrollTop>=keyboard.editor.scrollHeight-keyboard.editor.clientHeight-2,'Keyboard End does not reach the panel bottom');
|
|
await p.mouse.move(r.right-8,r.y+Math.min(80,r.height/2));await panel.evaluate(e=>e.scrollTop=e.scrollHeight);const edgeBefore=await geometry(p);await p.mouse.wheel(0,800);await p.waitForTimeout(100);const edge=await geometry(p);
|
|
check(unchangedPage(edgeBefore,edge),'Edge scrolling leaks into the document, header, or story shell');
|
|
await panel.evaluate(e=>e.blur());await p.mouse.move(1,1);const left=await geometry(p);check(touch?!transparent(left.editor.scrollbarColor):transparent(left.editor.scrollbarColor),'Scrollbar does not return to its non-hover state');
|
|
check(original.timelines===0,'02 shots unexpectedly contains a timeline');
|
|
await p.locator('.story-mode-tabs button').filter({hasText:'03 成片'}).click();await p.locator('.editor-timeline').waitFor();
|
|
scenario.render=await geometry(p);check(scenario.render.timelines===1,'03 film must contain exactly one timeline');check(scenario.render.document.scrollHeight<=scenario.viewport.height+2,'03 film overflows the document');
|
|
await p.locator('.story-mode-tabs button').filter({hasText:'02 分镜'}).click();await p.locator('.editor-shot-body').waitFor();
|
|
scenario.returned=await geometry(p);check(scenario.returned.editor.overflowY==='auto'&&scenario.returned.editor.rect.bottom<=scenario.viewport.height+2,'Returning from 03 loses the 02 scroll container');
|
|
}
|
|
async function main() {
|
|
const tempRoot=fs.realpathSync(os.tmpdir());
|
|
const dir=fs.mkdtempSync(path.join(tempRoot,'cmvr-story-scroll-'));
|
|
let browser;
|
|
try {
|
|
browser=await playwright.chromium.launch({headless:true,channel:process.env.PLAYWRIGHT_CHANNEL||'chrome'});
|
|
for(const config of mobileOnly?[{width:390,height:844}]:desktopOnly?[{width:1920,height:957}]:[{width:1920,height:957},{width:1366,height:768},{width:1024,height:768},{width:390,height:844},{width:390,height:844,touch:true}]) {
|
|
const {touch=false,...viewport}=config;
|
|
const context=await browser.newContext({viewport,hasTouch:touch});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.errors.push(e.message));
|
|
await p.goto(`${base}/studio/${id}`,{waitUntil:'networkidle'});
|
|
await p.locator('.editor-binding').last().waitFor();
|
|
const before=await geometry(p);
|
|
const scenario={viewport,touch,before,failures:[]};report.scenarios.push(scenario);
|
|
if(!['auto','scroll'].includes(before.editor.overflowY))scenario.failures.push('Editable production is not a scroll container');
|
|
if(before.editor.rect.bottom>viewport.height+2)scenario.failures.push('Editable production extends below the viewport');
|
|
if(before.document.scrollHeight>viewport.height+2)scenario.failures.push('Document overflows');
|
|
const r=before.editor.rect;await p.mouse.move(Math.min(viewport.width-5,r.right-8),Math.min(viewport.height-10,r.y+100));await p.mouse.wheel(0,600);await p.waitForTimeout(100);
|
|
scenario.afterWheel=await geometry(p);
|
|
if(scenario.afterWheel.editor.scrollTop===0)scenario.failures.push('Wheel cannot scroll the editable production');
|
|
if(!unchangedPage(before,scenario.afterWheel))scenario.failures.push('Wheel moves the document, header, or story shell');
|
|
if(!expectRed)await greenChecks(p,scenario,touch);
|
|
await p.screenshot({path:path.join(dir,`shots-${viewport.width}.png`)});
|
|
console.log(JSON.stringify({viewport,touch,panel:{h:before.editor.clientHeight,sh:before.editor.scrollHeight,overflow:before.editor.overflowY,bottom:before.editor.rect.bottom},returnButton:scenario.returnButton,shotDisplay:before.shotEditor.display,navigation:scenario.navigation,wheelTop:scenario.afterWheel.editor.scrollTop,video:scenario.video,narration:scenario.narration,lastShot:scenario.lastShot,lastHistory:scenario.lastHistory,keyboard:scenario.keyboard,scrollbar:scenario.scrollbar,timelines:scenario.render?.timelines,failures:scenario.failures,...(expectRed?{before}: {})}));
|
|
await context.close();
|
|
}
|
|
} finally {
|
|
await browser?.close();
|
|
const relative=path.relative(tempRoot,fs.realpathSync(dir));
|
|
if(path.isAbsolute(relative)||relative.startsWith('..')||!relative.startsWith('cmvr-story-scroll-'))throw new Error('Unexpected browser artifact directory');
|
|
fs.rmSync(dir,{recursive:true,force:true});
|
|
}
|
|
const failures=report.scenarios.flatMap(s=>s.failures);
|
|
console.log(JSON.stringify({baseUrl:base,scenarios:report.scenarios.length,failures:failures.length,mutations:report.mutations,unknown:report.unknown,pageErrors:report.errors}));
|
|
if(report.mutations.length||report.errors.length||report.unknown.length||(expectRed?failures.length===0:failures.length>0))process.exitCode=1;
|
|
}
|
|
main().catch(e=>{console.error(e);process.exitCode=1});
|