Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

9.3 KB
Raw Blame
import {mkdtemp,cp,mkdir,writeFile,readFile} from 'node:fs/promises';
import {tmpdir} from 'node:os';
import {join} from 'node:path';
import {fileURLToPath,pathToFileURL} from 'node:url';
import assert from 'node:assert/strict';
import {createHash} from 'node:crypto';
import {chromium} from '../toolchain/node_modules/playwright-core/index.mjs';
import {browserPath} from '../toolchain/browser.mjs';
import {createFlightViewer} from '../viewer/viewer.mjs';
import {buildFlight} from '../template/tools/build.mjs';
import {yard,siteGeoJSON,recordedCSV,logMapping} from './fixtures.mjs';
import {planProject} from '../template/studio/project.mjs';
const root=process.env.DRONE_QA_ROOT||await mkdtemp(join(tmpdir(),'vector-browser-')),workspace=join(root,'workspace');await mkdir(root,{recursive:true});await cp(fileURLToPath(new URL('../template/',import.meta.url)),workspace,{recursive:true});
process.env.DRONE_DSH_DIR=fileURLToPath(new URL('../',import.meta.url));await buildFlight(workspace);const server=await createFlightViewer(workspace);await new Promise(r=>server.listen(0,'127.0.0.1',r));
const url='http://127.0.0.1:'+server.address().port,browser=await chromium.launch({executablePath:await browserPath(),headless:true});const context=await browser.newContext({viewport:{width:1536,height:980},acceptDownloads:true}),page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message));
const shot=async name=>{await page.screenshot({path:join(root,name+'.png')});};
async function downloaded(selector,name){const promise=page.waitForEvent('download');await page.locator(selector).click();const d=await promise,path=join(root,name||d.suggestedFilename());await d.saveAs(path);return path;}
const editedField=async(key,value)=>{const el=page.locator('[data-field="'+key+'"]');await el.fill(String(value));await el.press('Tab');};
try{
  await page.goto(url);await page.waitForFunction(()=>window.vector?.connected);assert.equal(await page.evaluate(()=>vector.plan.photos.length),336);await shot('01-studio');
  const approved=await page.evaluate(()=>JSON.stringify(vector.project.areas.find(a=>a.id==='pond')));
  await page.locator('[data-area="pond"]').click();assert.equal(await page.locator('[data-handle]').count(),0);await page.locator('[data-area="orchard"]').click();
  const vertex=await page.evaluate(()=>vector.screenPoint([420,0])),target=await page.evaluate(()=>vector.screenPoint([455,0]));await page.mouse.move(vertex.x,vertex.y);await page.mouse.down();await page.mouse.move(target.x,target.y,{steps:8});await page.mouse.up();await page.waitForFunction(()=>vector.project.areas[0].ring[1][0]>450);assert.equal(await page.evaluate(()=>JSON.stringify(vector.project.areas.find(a=>a.id==='pond'))),approved);
  await page.locator('#undo').click();assert.equal(await page.evaluate(()=>vector.project.areas[0].ring[1][0]),420);await page.locator('#redo').click();
  await editedField('height',65);assert.ok(await page.evaluate(()=>vector.plan.camera.gsdX)>1.7);
  await page.locator('#compare-angles').click();await page.locator('[data-angle="45"]').waitFor();await page.locator('[data-angle="45"]').click();assert.equal(await page.evaluate(()=>vector.project.settings.angle),45);assert.equal(await page.evaluate(()=>vector.project.settings.height),65);
  await page.locator('[data-sortie="1"]').click();await page.locator('#inspect-photo').fill('5');await page.locator('#inspect-photo').dispatchEvent('input');assert.match(await page.locator('#photo-details').textContent(),/Photo/);await shot('02-revised');
  await editedField('speed',30);await page.locator('#plan-error').waitFor({state:'visible'});assert.match(await page.locator('#plan-error').textContent(),/camera cannot capture/);assert.equal(await page.locator('#deliver').isDisabled(),true);await page.locator('#undo').click();assert.ok(await page.evaluate(()=>vector.plan));
  await page.locator('#save-source').click();await page.waitForFunction(()=>!vector.dirty);const saved=JSON.parse(await readFile(join(workspace,'flight/project.json'),'utf8'));assert.equal(saved.settings.height,65);
  await editedField('height',70);const external=structuredClone(saved);external.title='Agent revised orchard';await writeFile(join(workspace,'flight/project.json'),JSON.stringify(external));await buildFlight(workspace);await page.locator('#source-notice').waitFor({state:'visible'});
  const draft=await downloaded('#draft-keep','conflict-draft.vector.json');assert.equal(JSON.parse(await readFile(draft,'utf8')).settings.height,70);await downloaded('#source-load','before-source-restore.vector.json');await page.waitForFunction(()=>vector.project.title==='Agent revised orchard');assert.equal(await page.evaluate(()=>vector.project.settings.height),65);
  const site=join(root,'supplied-yard.geojson');await writeFile(site,JSON.stringify(siteGeoJSON(yard())));await page.locator('#import-geo').click();await page.locator('#geo-file').setInputFiles(site);await page.waitForFunction(()=>vector.project.title==='supplied-yard');assert.equal(await page.evaluate(()=>vector.project.areas.filter(a=>a.kind==='exclusion').length),2);assert.ok(await page.evaluate(()=>vector.plan));
  await page.locator('[data-tool="exclusion"]').click();for(const p of [[170,25],[192,25],[192,45],[170,45]]){const pos=await page.evaluate(p=>vector.screenPoint(p),p);await page.mouse.click(pos.x,pos.y);}await page.locator('#finish-draw').click();assert.equal(await page.evaluate(()=>vector.project.areas.length),4);await page.locator('#undo').click();assert.equal(await page.evaluate(()=>vector.project.areas.length),3);
  await page.locator('#save-source').click();await page.waitForFunction(()=>!vector.dirty);
  const project=await page.evaluate(()=>vector.project),flight=join(root,'synthetic-flight.csv');await writeFile(flight,'\uFEFF'+recordedCSV(planProject(project)));
  await page.locator('#evidence-tab').click();await page.locator('#log-file').setInputFiles(flight);await page.locator('#log-dialog').waitFor({state:'visible'});
  for(const [key,value] of Object.entries(logMapping)){const el=page.locator('[data-map="'+key+'"]');if(key==='homeElevation')await el.fill(String(value));else await el.selectOption(value);}
  await page.locator('#apply-log').click();await page.waitForFunction(()=>vector.evidence?.captureEvents>0);assert.equal(await page.evaluate(()=>vector.evidence.discontinuities),1);assert.equal(await page.evaluate(()=>vector.evidence.unmodeledCaptures),1);await page.locator('#inspect-log').fill('12');await page.locator('#inspect-log').dispatchEvent('input');assert.match(await page.locator('#sample-details').textContent(),/Row 14/);await page.locator('#show-coverage').check();await shot('03-recorded-evidence');
  await page.locator('#save-source').click();await page.waitForFunction(()=>!vector.dirty);
  assert.equal(await page.evaluate(()=>vector.project.log.sha256),createHash('sha256').update(await readFile(flight)).digest('hex'),'UTF-8 BOM and original source bytes survive browser import');
  await page.locator('#deliver').click();const kit=await downloaded('#export-kit','field-kit.zip'),geo=await downloaded('#export-geo','survey.geojson'),report=await downloaded('#export-report','report.html');await page.locator('#export-dialog [data-close]').click();
  const offlineFile=join(root,'planner.html');await writeFile(offlineFile,await page.evaluate(()=>vector.portable()));const offline=await context.newPage();offline.on('pageerror',e=>errors.push(e.message));await context.setOffline(true);await offline.goto(pathToFileURL(offlineFile).href);await offline.waitForFunction(()=>window.vector?.evidence);assert.equal(await offline.evaluate(()=>vector.project.log.name),'synthetic-flight.csv');await offline.locator('[data-field="height"]').fill('60');await offline.locator('[data-field="height"]').press('Tab');assert.equal(await offline.evaluate(()=>vector.project.settings.height),60);await offline.screenshot({path:join(root,'04-offline.png')});await context.setOffline(false);
  const mobile=await browser.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true}),phone=await mobile.newPage();await phone.goto(url);await phone.waitForFunction(()=>window.vector);await phone.screenshot({path:join(root,'05-mobile.png')});assert.equal(await phone.evaluate(()=>document.documentElement.scrollWidth<=390&&[...document.querySelectorAll("header nav button")].filter(b=>!b.hidden).every(b=>b.getBoundingClientRect().right<=390)),true);await mobile.close();
  assert.deepEqual(errors,[]);const result={root,workspace,kit,geo,report,browserErrors:errors,checks:['drag vertex and preserve locked exclusion','undo/redo','camera geometry and infeasible cadence','compare sampled directions','inspect individual planned captures','save source with history','retain both sides of an agent/browser conflict','import a supplied multi-layer GeoJSON site','draw a new exclusion','explicit CSV mapping and units','inspect recorded samples and missing data','export complete kit','reopen/edit offline planner','mobile layout without horizontal overflow']};await writeFile(join(root,'report.json'),JSON.stringify(result,null,2));console.log(JSON.stringify(result));
}catch(error){await page.screenshot({path:join(root,'failure.png')}).catch(()=>{});console.error('Browser status:',await page.locator('#status').textContent().catch(()=>''),'errors:',errors);throw error;}finally{await browser.close();server.closeAllConnections();await new Promise(r=>server.close(r));}