OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.
TypeScript
const { chromium } = require(require('node:path').join(process.cwd(), 'apps/studio/node_modules/@playwright/test'));
const fs = require('node:fs');
const assert = require('node:assert/strict');
const dir=process.env.OPENREEL_EVIDENCE_DIR || '/tmp/openreel-ai-evidence';
const baseURL=process.env.OPENREEL_BROWSER_URL || 'http://127.0.0.1:5174';
fs.mkdirSync(dir,{recursive:true});
(async()=>{
const browser=await chromium.launch({executablePath:process.env.OPENREEL_CHROMIUM || '/usr/bin/chromium',headless:true,args:['--no-sandbox','--disable-dev-shm-usage','--enable-unsafe-swiftshader']});
const context=await browser.newContext({viewport:{width:1440,height:960},acceptDownloads:true});
const page=await context.newPage();page.setDefaultTimeout(15000); const moduleURLs={}; page.on('request',r=>{ const u=new URL(r.url()); for(const [name,path] of Object.entries({project:'/src/stores/project-store.ts',chat:'/src/stores/chat-store.ts',timeline:'/src/stores/timeline-store.ts',ui:'/src/stores/ui-store.ts'}))if(u.pathname===path)moduleURLs[name]=r.url(); }); const errors=[];page.on('pageerror',e=>errors.push(e.message));
let plan=[],step=0,delay=0;
await context.route(/^https:\/\//,async route=>{
if(!route.request().url().startsWith('https://fixture.invalid/v1/')) return route.abort();
step++;
const first=step===1; const calls=first?plan:[];
if(!first&&delay) await new Promise(r=>setTimeout(r,delay));
try {await route.fulfill({status:200,contentType:'application/json',body:JSON.stringify({choices:[{message:{content:calls.length?'Preparing a precise edit.':'Edit complete.',...(calls.length?{tool_calls:calls.map((c,i)=>({id:`fixture-${i}`,type:'function',function:{name:c.name,arguments:JSON.stringify(c.args)}}))}:{})},finish_reason:calls.length?'tool_calls':'stop'}],usage:{prompt_tokens:5,completion_tokens:5}})});}catch{}
});
const state=()=>page.evaluate(async()=>{const {useProjectStore}=await import(window.__testModuleURLs.project);const {createPortableEdit}=await import('/@fs'+window.__testRepoRoot+'/packages/core/src/editing/portable-project.ts');return createPortableEdit(useProjectStore.getState().getFullProject());});
const poll=async(predicate,timeout=30000)=>{const until=Date.now()+timeout;while(Date.now()<until){if(await page.evaluate(predicate))return;await page.waitForTimeout(200);}throw new Error('Condition timed out: '+predicate.toString());};
const waitIdle=()=>poll(async()=>{const{useChatStore}=await import(window.__testModuleURLs.chat);return !['running','awaiting_confirm'].includes(useChatStore.getState().status);});
const send=async(calls,text='Make the requested precise edit',lag=0)=>{plan=calls;step=0;delay=lag;await page.getByRole('textbox',{name:'AI edit request'}).fill(text);await page.getByRole('button',{name:'Send',exact:true}).click();};
await page.goto(baseURL,{waitUntil:'domcontentloaded'});
await page.getByRole('button',{name:'Create Horizontal project',exact:true}).click();
await page.getByRole('button',{name:'AI editing',exact:true}).waitFor({timeout:60000});
await page.getByRole('button',{name:'Skip tour',exact:true}).first().waitFor({timeout:10000});
await page.getByRole('button',{name:'Skip tour',exact:true}).first().click();
await page.getByRole('button',{name:'AI editing',exact:true}).click();
await page.getByRole('button',{name:'AI settings',exact:true}).click();
await page.getByRole('textbox',{name:'AI base URL'}).fill('https://fixture.invalid/v1');
await page.getByRole('textbox',{name:'AI model ID'}).fill('fixture-tool-model');
await page.getByRole('textbox',{name:'Session API key'}).fill('fixture-session-key');
await page.getByRole('button',{name:'Done',exact:true}).click();
await page.evaluate(({urls,root})=>{window.__testModuleURLs=urls;window.__testRepoRoot=root;},{urls:moduleURLs,root:process.cwd()});
await page.locator('input[aria-label="Import media"]').setInputFiles([`${dir}/sample-video.mp4`,`${dir}/sample-audio.wav`,`${dir}/sample-still.png`]);
await poll(async()=>{const{useProjectStore}=await import(window.__testModuleURLs.project);return useProjectStore.getState().project.mediaLibrary.items.length===3;},90000);
const snap=await state();
const media=snap.project.media;
assert.deepEqual(media.map(m=>m.type).sort(),['audio','image','video']);
console.log('PASS imported video, audio and image using media UI');
const video=media.find(m=>m.type==='video'),audio=media.find(m=>m.type==='audio'),image=media.find(m=>m.type==='image');
const transform={position:{x:0,y:0},scale:{x:1,y:1},rotation:0,anchor:{x:.5,y:.5},opacity:1,fitMode:'contain'};
const clip=(id,mediaId,trackId,startTime,inPoint,outPoint,extras={})=>({id,mediaId,trackId,startTime,inPoint,outPoint,duration:outPoint-inPoint,transform:structuredClone(transform),volume:0,effects:[],audioEffects:[],keyframes:[],...extras});
const track=(id,type,name,clips,transitions=[])=>({id,type,name,clips,transitions,locked:false,hidden:false,muted:false,solo:false});
const doc={format:'openreel-edit',version:2,project:{id:'shared-sintel-demo',name:'Sintel AI edit demo',settings:{width:640,height:360,frameRate:24,sampleRate:48000,channels:2},media,timeline:{duration:4,subtitles:[],markers:[],tracks:[track('video-track','video','Sintel footage',[clip('opening',video.id,'video-track',0,0,2),clip('closing',video.id,'video-track',2,2,4)],[{id:'shared-dissolve',type:'crossfade',clipAId:'opening',clipBId:'closing',duration:.3,params:{}}]),track('audio-track','audio','Tone',[clip('tone',audio.id,'audio-track',0,0,4,{volume:.2,fade:{fadeIn:.2,fadeOut:.2}})]),track('image-track','image','Still overlay',[clip('still',image.id,'image-track',3.5,0,.5,{transform:{...transform,position:{x:.25,y:.25},scale:{x:.25,y:.25}}})]),track('title-track','text','Titles',[])]},textClips:[{id:'demo-title',trackId:'title-track',text:'SINTEL / AI EDIT',startTime:0,duration:4,style:{fontFamily:'Arial',fontSize:38,fontWeight:700,fontStyle:'normal',color:'#ffffff',textAlign:'center',verticalAlign:'middle',lineHeight:1.2,letterSpacing:0},transform:{position:{x:.5,y:.8},scale:{x:1,y:1},rotation:0,anchor:{x:.5,y:.5},opacity:1},keyframes:[]}]}};
doc.project.timeline.tracks.sort((a,b)=>['title-track','image-track','video-track','audio-track'].indexOf(a.id)-['title-track','image-track','video-track','audio-track'].indexOf(b.id));
fs.writeFileSync(`${dir}/constructed-edit.json`,JSON.stringify(doc,null,2));
await page.getByText('Edit JSON & reusable presets',{exact:true}).click();
const jsonbox=page.getByRole('textbox',{name:'Edit or preset JSON'});
await jsonbox.fill(JSON.stringify(doc));
await page.getByRole('button',{name:'Import edit JSON',exact:true}).click();
await page.getByText('Edit imported as one undo step.',{exact:false}).waitFor();
assert.equal((await state()).project.timeline.tracks.find(t=>t.id==='video-track').clips[0].id,'opening');
await page.evaluate(async()=>{const{useTimelineStore}=await import(window.__testModuleURLs.timeline);useTimelineStore.getState().setPlayheadPosition(1);});
await page.waitForTimeout(1500);
await page.screenshot({path:`${dir}/workspace-imported.png`,fullPage:true});
await page.getByText('Edit JSON & reusable presets',{exact:true}).click();
const before=await state();
await send([{name:'update_text_clip',args:{clipId:'demo-title',updates:{text:'PRECISE REVISION',style:{color:'#ffcc33'}}}}],'Change only the demo-title text to PRECISE REVISION and color it gold. Preserve everything else.');
await waitIdle();
const after=await state();
assert.equal(after.project.textClips[0].text,'PRECISE REVISION');
assert.deepEqual(after.project.timeline,before.project.timeline);
assert.deepEqual(after.project.media,before.project.media);
await page.getByText('PRECISE REVISION',{exact:true}).waitFor();
await page.waitForTimeout(500);await page.screenshot({path:`${dir}/workspace-targeted-revision.png`,fullPage:true});
console.log('PASS fixture model tool loop targeted revision preserves all unrelated clips');
await page.getByRole('button',{name:'Undo last AI turn',exact:true}).click();
assert.equal((await state()).project.textClips[0].text,'SINTEL / AI EDIT');
await page.getByText('Edit JSON & reusable presets',{exact:true}).click();
await page.getByRole('button',{name:'Redo edit',exact:true}).click();
assert.equal((await state()).project.textClips[0].text,'PRECISE REVISION');
console.log('PASS normal undo/redo restores stable-ID targeted edit');
const roundtrip=await state();
await page.getByRole('button',{name:'Export edit JSON',exact:true}).click();
const exported=JSON.parse(await jsonbox.inputValue());assert.deepEqual(exported,roundtrip);fs.writeFileSync(`${dir}/roundtrip-edit.json`,JSON.stringify(exported,null,2));
await page.getByRole('button',{name:'Import edit JSON',exact:true}).click();
await page.getByText('All media references are linked.',{exact:false}).waitFor();
assert.deepEqual(await state(),roundtrip);
console.log('PASS JSON roundtrip and media references');
const baseline=await state();
await jsonbox.fill('{"format":"openreel-edit","version":2,"instructions":"execute arbitrary code"}');
await page.getByRole('button',{name:'Import edit JSON',exact:true}).click();
await page.getByRole('alert').waitFor();assert.deepEqual(await state(),baseline);
console.log('PASS malformed/untrusted JSON rejected without changes');
await jsonbox.fill(JSON.stringify({format:'openreel-preset',version:1,name:'Soft dissolve',effects:[{id:'preset-look',type:'brightness',enabled:true,params:{value:.08}}],transition:{type:'crossfade',duration:.25,params:{}}}));
await page.getByRole('combobox',{name:'Preset target clip'}).selectOption('opening');
await page.getByRole('button',{name:'Apply preset JSON',exact:true}).click();
await page.getByText('Applied preset Soft dissolve',{exact:false}).waitFor();
const presetApplied=await state();assert.equal(presetApplied.project.timeline.tracks.find(t=>t.id==='video-track').clips[0].effects.length,1);assert.notEqual(presetApplied.project.timeline.tracks.find(t=>t.id==='video-track').clips[0].effects[0].id,'preset-look');
await page.getByRole('button',{name:'Export preset',exact:true}).click();fs.writeFileSync(`${dir}/shared-preset.json`,await jsonbox.inputValue());
console.log('PASS transition/effect preset sharing and fresh IDs');
await page.getByText('Edit JSON & reusable presets',{exact:true}).click();
const beforeFailure=await state();
await send([{name:'set_clip_volume',args:{clipId:'tone',volume:.7}},{name:'move_clip',args:{clipId:'does-not-exist',startTime:2}}],'Apply the fixture failure scenario');
await waitIdle();assert.deepEqual(await state(),beforeFailure);console.log('PASS failed multi-tool turn is fully discarded');
await send([{name:'set_clip_volume',args:{clipId:'tone',volume:.7}}],'Apply the fixture cancellation scenario',3000);
await poll(async()=>{const{useChatStore}=await import(window.__testModuleURLs.chat);return useChatStore.getState().messages.at(-1)?.toolCalls.some(c=>c.status==='done');});
await page.getByRole('button',{name:'Stop',exact:true}).click();await waitIdle();assert.deepEqual(await state(),beforeFailure);console.log('PASS cancellation discards pending edits');
const missing=structuredClone(await state());const ref=missing.project.media.find(m=>m.type==='image');const oldId=ref.id;ref.id='unlinked-image';ref.sourceFile.name='different-image.png';for(const t of missing.project.timeline.tracks)for(const c of t.clips)if(c.mediaId===oldId)c.mediaId='unlinked-image';
await page.getByText('Edit JSON & reusable presets',{exact:true}).click();await jsonbox.fill(JSON.stringify(missing));await page.getByRole('button',{name:'Import edit JSON',exact:true}).click();
await page.getByLabel('Relink sample-still.png',{exact:true}).waitFor();
await page.getByLabel('Relink sample-still.png',{exact:true}).setInputFiles(`${dir}/sample-still.png`);
await page.getByText('relinked. Element IDs were preserved.',{exact:false}).waitFor();
assert.equal((await state()).project.timeline.tracks.find(t=>t.id==='image-track').clips[0].mediaId,'unlinked-image');
console.log('PASS explicit local media relinking preserves stable element IDs');
const beforeStale=await state();
await page.getByText('Edit JSON & reusable presets',{exact:true}).click();
await send([{name:'set_clip_volume',args:{clipId:'tone',volume:.7}}],'Apply the stale-state fixture',3000);
await poll(async()=>{const{useChatStore}=await import(window.__testModuleURLs.chat);return useChatStore.getState().messages.at(-1)?.toolCalls.some(c=>c.status==='done');});
await page.getByRole('textbox',{name:'Project name',exact:true}).fill('User intervening edit');await page.getByRole('textbox',{name:'Project name',exact:true}).press('Enter');await waitIdle();
const stale=await state();assert.equal(stale.project.name,'User intervening edit');assert.deepEqual(stale.project.timeline,beforeStale.project.timeline);console.log('PASS stale AI turn rejected while preserving manual edit');
await page.getByText('Edit JSON & reusable presets',{exact:true}).click();
fs.writeFileSync(`${dir}/final-edit.json`,JSON.stringify(await state(),null,2));
await page.getByText('Edit JSON & reusable presets',{exact:true}).click();
await page.screenshot({path:`${dir}/workspace-final.png`,fullPage:true});
await page.setViewportSize({width:1000,height:800});await page.waitForTimeout(1000);await page.screenshot({path:`${dir}/workspace-1000.png`,fullPage:true});
await page.setViewportSize({width:820,height:900});await page.waitForTimeout(1000);await page.screenshot({path:`${dir}/workspace-820.png`,fullPage:true});
console.log('ERRORS',errors);assert.deepEqual(errors,[]);
fs.writeFileSync(`${dir}/browser-results.json`,JSON.stringify({mediaImport:true,constructedJSONImport:true,targetedRevision:true,undoRedo:true,jsonRoundtrip:true,presetSharing:true,malformedJSON:true,atomicFailure:true,cancellation:true,relinking:true,staleTurn:true,pageErrors:errors,liveModelTested:false},null,2));
await page.setViewportSize({width:1440,height:960});
await send([{name:'open_export',args:{}}],'Open the local export settings');await waitIdle();
await page.getByRole('radio',{name:/^Custom(?: Settings)?$/}).click();
await page.getByRole('combobox',{name:'Format',exact:true}).selectOption('webm');
await page.getByRole('combobox',{name:'Codec',exact:true}).selectOption('vp9');
await page.getByRole('combobox',{name:/^Frame rate$/i}).selectOption('24');
await page.evaluate(()=>{window.showSaveFilePicker=undefined;});
const output=page.waitForEvent('download',{timeout:180000});
await page.getByRole('button',{name:/^(?:Start Export|Export video|Export)$/i}).click();
const download=await output;await download.saveAs(`${dir}/verified-export.webm`);
console.log('PASS actual local encoded video export',await download.failure());
await page.screenshot({path:`${dir}/export-complete.png`,fullPage:true});
fs.writeFileSync(`${dir}/browser-results.json`,JSON.stringify({...JSON.parse(fs.readFileSync(`${dir}/browser-results.json`)),export:true,keyPersistence:false},null,2));
assert.equal(await page.evaluate(()=>JSON.stringify({...localStorage,...sessionStorage}).includes('fixture-session-key')),false);
await page.reload();
await page.evaluate(async()=>{const {useAIConnectionStore}=await import('/src/stores/ai-connection-store.ts');if(useAIConnectionStore.getState().apiKey)throw new Error('API key survived reload');});
console.log('PASS session key cleared on reload and absent from web storage');
await browser.close();
})().catch(e=>{console.error(e);process.exit(1)});