Explainer videos and product demos made by your AI agent. Free and open source: a local voice (Kokoro), word timing (Whisper) and a canvas renderer turn a script into a narrated MP4.
JavaScript ai-agentsanimationcanvasclaude-codecodexexplainer-videoffmpegjavascriptkokoroproduct-demotext-to-speechvideo-generationwhisper
Pre-launch fixes from review: voice cache covers markers and shown words, pace speeds up camera, counts, bars and typing, grid and column center on the content area, Node 20.11 minimum, Windows browser paths, preview server only serves media and scripts to localhost with contained uploads, scoped local and free claims
Vincent Schmalbach9af53b416d36
diff --git a/AGENTS.md b/AGENTS.mdindex a3af2c9..1495823 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -416,11 +416,11 @@ Easing names: `linear`, `in`, `out`, `inOut`, `outBack`, `outElastic`,| Member | Meaning ||---|---|-| `s.W`, `s.H`, `s.cx`, `s.cy` | canvas size and the center of the safe area |+| `s.W`, `s.H`, `s.cx`, `s.cy` | canvas size and its center (on Shorts, TikTok and Reels the center of `s.safe`) || `s.safe` | `{ x, y, w, h, left, top, right, bottom }`: the area for content (a 7% margin, or the part a platform leaves free) || `s.row(n, { width, x })` | n x positions spread over a width |-| `s.col(n, { height, y })` | n y positions spread over a height |-| `s.grid(cols, rows, { x, y, w, h, gap })` | cells `{ x, y, w, h }`, row by row |+| `s.col(n, { height, y })` | n y positions spread over a height, centered in `s.safe` |+| `s.grid(cols, rows, { x, y, w, h, gap })` | cells `{ x, y, w, h }`, row by row, filling `s.safe` || `s.get(id)` | size and position of an element drawn earlier with that `id` |Most elements return `{ x, y, w, h, left, right, top, bottom }`, so you candiff --git a/README.md b/README.mdindex 27672da..51d1abd 100644--- a/README.md+++ b/README.md@@ -73,9 +73,11 @@ work: still pictures of every scene, contact sheets, a layout check that findscut-off or overlapping text, and a speech check that catches words the voicegot wrong.-Nothing leaves your computer, and making a video costs nothing. The one-exception is optional: for how-to topics the agent can make illustrations-with an AI image model through OpenRouter, which you pay per image.+explainroo's own part runs on your computer: the voice, the timing and the+rendering send nothing anywhere and cost nothing. Your coding agent is a+separate service with its own terms and costs. For how-to topics the agent can+also make illustrations with an AI image model through OpenRouter, which is+optional and paid per image.## Looks, sizes and pace@@ -94,9 +96,10 @@ with an AI image model through OpenRouter, which you pay per image.## Install it yourself-You need Node.js 20 or newer, ffmpeg, and Chrome or Chromium. The first setup+You need Node.js 20.11 or newer, ffmpeg, and Chrome or Chromium. The first setupdownloads the speech models once (about 400 MB). You don't need a graphics-card.+card. explainroo is developed and tested on Linux; macOS and Windows should+work, but they have seen less testing so far.```bashgit clone https://github.com/vincentsch/explainroo.gitdiff --git a/engine/stage.js b/engine/stage.jsindex 57c0460..c015bde 100644--- a/engine/stage.js+++ b/engine/stage.js@@ -30,6 +30,9 @@ export class Stage {this.platform = Boolean(engine.config.safe);this.cx = this.platform ? this.safe.x + this.safe.w / 2 : this.W / 2;this.cy = this.platform ? this.safe.y + this.safe.h / 2 : this.H / 2;+ // The center of the content area. With captions on it sits above the+ // frame center; layout helpers center on it by default.+ this._mid = { x: this.safe.x + this.safe.w / 2, y: this.safe.y + this.safe.h / 2 };// pace > 1 makes animations shorter. Times stay real seconds of the// scene, like s.t and the word cues, so `s.cue('word') + 0.3` keeps working.this.pace = engine.timeline.pace || 1;@@ -149,8 +152,8 @@ export class Stage {}col(n, o = {}) {- const height = o.height ?? (this.platform ? this.safe.h * 0.7 : this.H * 0.56);- const y = o.y ?? this.cy;+ const height = o.height ?? (this.platform ? this.safe.h * 0.7 : Math.min(this.H * 0.56, this.safe.h * 0.8));+ const y = o.y ?? this._mid.y;if (n <= 1) return [y];return Array.from({ length: n }, (_, i) => y - height / 2 + (height * i) / (n - 1));}@@ -158,8 +161,8 @@ export class Stage {grid(cols, rows, o = {}) {const w = o.w ?? this.safe.w;const h = o.h ?? this.safe.h;- const x0 = (o.x ?? this.cx) - w / 2;- const y0 = (o.y ?? this.cy) - h / 2;+ const x0 = (o.x ?? this._mid.x) - w / 2;+ const y0 = (o.y ?? this._mid.y) - h / 2;const gap = o.gap ?? 24;const cw = (w - gap * (cols - 1)) / cols;const ch = (h - gap * (rows - 1)) / rows;@@ -193,7 +196,8 @@ export class Stage {const enter = o.enter ?? extra.enter ?? this.theme.enter[kind] ?? this.theme.enter.shape ?? 'fade';const at = this.time(o.at ?? 0);const out = o.out === undefined ? Infinity : this.time(o.out);- const dur = (o.dur ?? extra.dur ?? DEFAULT_DUR[enter] ?? 0.6) / this.pace;+ const base = o.dur ?? extra.dur ?? DEFAULT_DUR[enter] ?? 0.6;+ const dur = extra.real ? base : base / this.pace;this._record(kind, at, dur, o, extra);if (this._suppress > 0) return null;if (this.t < at) return null;@@ -387,7 +391,7 @@ export class Stage {const k = list[i];if (this.t < k.at) break;const prev = cur;- const p = easeFn(k.ease ?? 'inOut')(clamp((this.t - k.at) / Math.max(0.001, k.dur)));+ const p = easeFn(k.ease ?? 'inOut')(clamp((this.t - k.at) / Math.max(0.001, k.dur / this.pace)));cur = { x: lerp(prev.x, k.x, p), y: lerp(prev.y, k.y, p), zoom: lerp(prev.zoom, k.zoom, p), rotate: lerp(prev.rotate || 0, k.rotate || 0, p) };}const ctx = this.ctx;@@ -484,8 +488,10 @@ export class Stage {else if (enter === 'words') dur = Math.max(0.4, lay.count * 0.18);}let times = null;- if (enter === 'sync' || enter === 'words') times = this._wordTimes(lay, enter, o, dur);- const life = this._life({ ...o, enter }, kind, { dur: enter === 'sync' ? Math.max(0.3, (times[times.length - 1] ?? 0) - this.time(o.at ?? 0) + 0.3) : dur, label: plain.slice(0, 40) });+ // 'sync' follows the real word times; 'words' is spread over `dur`, which+ // the pace shortens like every other animation.+ if (enter === 'sync' || enter === 'words') times = this._wordTimes(lay, enter, o, enter === 'words' ? dur / this.pace : dur);+ const life = this._life({ ...o, enter }, kind, { dur: enter === 'sync' ? Math.max(0.3, (times[times.length - 1] ?? 0) - this.time(o.at ?? 0) + 0.3) : dur, real: enter === 'sync', label: plain.slice(0, 40) });if (!life) return g;this._push(bx, by, life, o);@@ -986,7 +992,7 @@ export class Stage {const bullet = o.bullet ?? 'dot';const indent = size * 1.25;const base = this.time(o.at ?? 0);- const stagger = o.stagger ?? 0.7;+ const stagger = (o.stagger ?? 0.7) / this.pace;const role = o.font ?? 'body';const font = fontString(th, role, size, o.weight);const out = [];@@ -1046,7 +1052,7 @@ export class Stage {number(value, o = {}) {const th = this.theme;const from = o.from ?? 0;- const dur = o.dur ?? 1.4;+ const dur = (o.dur ?? 1.4) / this.pace;const at = this.time(o.at ?? 0);const decimals = o.decimals ?? (Number.isInteger(value) && Number.isInteger(from) ? 0 : 1);const steps = Math.min(18, Math.max(4, Math.round(dur * 10)));@@ -1080,10 +1086,10 @@ export class Stage {const bw = slot * (1 - (o.gapRatio ?? 0.36));const base = y + h / 2;const at = this.time(o.at ?? 0);- const stagger = o.stagger ?? 0.22;+ const stagger = (o.stagger ?? 0.22) / this.pace;this._register(o.id, x, y, w, h);// Each bar can have its own `at` (seconds, a spoken word or "#marker").- const barAt = items.map((d, i) => (d.at !== undefined ? this.time(d.at) : at + 0.3 + i * stagger));+ const barAt = items.map((d, i) => (d.at !== undefined ? this.time(d.at) : at + 0.3 / this.pace + i * stagger));items.forEach((d, i) => this._record('chart', barAt[i], 0.8, { sfx: o.sfx }, { label: `bar${i}` }));const axisLife = this._life({ at, out: o.out, sfx: null }, 'chart', { enter: 'draw', dur: 0.5 });if (!axisLife) return geom(x, y, w, h);@@ -1093,7 +1099,7 @@ export class Stage {this.pen.draw(ctx, { kind: 'poly', points: [[x - w / 2 - 20, base], [x + w / 2 + 20, base]] }, { stroke: colorOf(th, 'ink'), width: th.stroke.width, seed: this._seed('axis', o), single: true }, { stroke: ease.inOut(axisLife.p), fill: 1 });items.forEach((d, i) => {const t0 = barAt[i];- const g = ease.out(clamp((this.t - t0) / (o.growDur ?? 0.9)));+ const g = ease.out(clamp((this.t - t0) / ((o.growDur ?? 0.9) / this.pace)));const cx = x - w / 2 + slot * i + slot / 2;const bh = (d.value / max) * h;if (g > 0) {@@ -1261,11 +1267,11 @@ export class Stage {this._register(o.id, x, y, w, h);const at = this.time(o.at ?? 0);const reveal = o.reveal ?? 'type';- const cps = o.cps ?? 40;+ const cps = (o.cps ?? 40) * this.pace;const chars = lines.reduce((a, l) => a + l.length + 1, 0);const typeDur = chars / cps;- const lineDelay = o.lineDelay ?? 0.3;- const startText = at + 0.35;+ const lineDelay = (o.lineDelay ?? 0.3) / this.pace;+ const startText = at + 0.35 / this.pace;if (reveal === 'type') this._record('code', startText, typeDur, { sfx: o.sfx }, { label: 'typing', sustain: true });const life = this._life({ ...o, sfx: null }, 'code', { dur: 0.5 });if (!life) return geom(x, y, w, h);@@ -1358,15 +1364,15 @@ export class Stage {const y = o.y ?? this.cy;this._register(o.id, x, y, w, h);const at = this.time(o.at ?? 0);- const cps = o.cps ?? 22;- let clock = at + 0.5;+ const cps = (o.cps ?? 22) * this.pace;+ let clock = at + 0.5 / this.pace;const timed = items.map((it) => {const r = { ...it };if (it.at !== undefined) clock = this.time(it.at);r.start = clock;if (it.cmd !== undefined) {r.end = r.start + String(it.cmd).length / cps;- clock = r.end + (o.outputDelay ?? 0.35);+ clock = r.end + (o.outputDelay ?? 0.35) / this.pace;this._record('terminal', r.start, r.end - r.start, { sfx: o.sfx }, { label: String(it.cmd).slice(0, 20), sustain: true });} else {r.end = r.start;diff --git a/package.json b/package.jsonindex 7f2ee86..c9ba573 100644--- a/package.json+++ b/package.json@@ -37,7 +37,7 @@"LICENSE"],"engines": {- "node": ">=20.6"+ "node": ">=20.11"},"license": "MIT","author": "Vincent Schmalbach",diff --git a/src/browser.js b/src/browser.jsindex 361dd5f..da64157 100644--- a/src/browser.js+++ b/src/browser.js@@ -4,8 +4,16 @@ import fs from 'node:fs';import os from 'node:os';import path from 'node:path';+// Where "npx playwright install" puts browsers on each system.+function playwrightBase() {+ if (process.env.PLAYWRIGHT_BROWSERS_PATH) return process.env.PLAYWRIGHT_BROWSERS_PATH;+ if (process.platform === 'win32') return path.join(process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local'), 'ms-playwright');+ if (process.platform === 'darwin') return path.join(os.homedir(), 'Library', 'Caches', 'ms-playwright');+ return path.join(os.homedir(), '.cache', 'ms-playwright');+}+function playwrightCandidates() {- const base = process.env.PLAYWRIGHT_BROWSERS_PATH || path.join(os.homedir(), process.platform === 'darwin' ? 'Library/Caches/ms-playwright' : '.cache/ms-playwright');+ const base = playwrightBase();if (!fs.existsSync(base)) return [];const dirs = fs.readdirSync(base).filter((d) => /^chromium(_headless_shell)?-\d+$/.test(d))@@ -14,7 +22,7 @@ function playwrightCandidates() {for (const d of dirs) {const root = path.join(base, d);for (const sub of fs.readdirSync(root)) {- for (const bin of ['headless_shell', 'chrome', 'Chromium.app/Contents/MacOS/Chromium', 'chrome-headless-shell']) {+ for (const bin of ['headless_shell', 'chrome', 'Chromium.app/Contents/MacOS/Chromium', 'chrome-headless-shell', 'headless_shell.exe', 'chrome.exe', 'chrome-headless-shell.exe']) {out.push(path.join(root, sub, bin));}}@@ -31,7 +39,13 @@ export function findChrome() {const system = process.platform === 'darwin'? ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Chromium.app/Contents/MacOS/Chromium']: process.platform === 'win32'- ? [path.join(process.env.PROGRAMFILES || 'C:\\Program Files', 'Google/Chrome/Application/chrome.exe'), path.join(process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)', 'Google/Chrome/Application/chrome.exe')]+ ? [+ path.join(process.env.PROGRAMFILES || 'C:\\Program Files', 'Google/Chrome/Application/chrome.exe'),+ path.join(process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)', 'Google/Chrome/Application/chrome.exe'),+ path.join(process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local'), 'Google/Chrome/Application/chrome.exe'),+ path.join(process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)', 'Microsoft/Edge/Application/msedge.exe'),+ path.join(process.env.PROGRAMFILES || 'C:\\Program Files', 'Microsoft/Edge/Application/msedge.exe'),+ ]: ['/usr/bin/google-chrome', '/usr/bin/google-chrome-stable', '/usr/bin/chromium', '/usr/bin/chromium-browser', '/snap/bin/chromium'];for (const p of [...playwrightCandidates(), ...system]) {if (fs.existsSync(p)) return p;diff --git a/src/cli.js b/src/cli.jsindex 7b55ae2..1d95e56 100644--- a/src/cli.js+++ b/src/cli.js@@ -320,8 +320,10 @@ function icons(words, print) {async function doctor(flags, log, print) {const rows = [];const add = (name, ok, detail) => rows.push({ name, ok, detail });- const [maj] = process.versions.node.split('.').map(Number);- add('node', maj >= 20, `v${process.versions.node}${maj >= 20 ? '' : ' (need 20 or newer)'}`);+ // The voice library (kokoro-js) needs import.meta.dirname, added in Node 20.11.+ const [maj, min] = process.versions.node.split('.').map(Number);+ const nodeOk = maj > 20 || (maj === 20 && min >= 11);+ add('node', nodeOk, `v${process.versions.node}${nodeOk ? '' : ' (need 20.11 or newer)'}`);const ff = ffmpegVersion();add('ffmpeg', !!ff, ff || 'not found; install ffmpeg or set EXPLAINROO_FFMPEG');try {diff --git a/src/server.js b/src/server.jsindex 807e3c0..2236081 100644--- a/src/server.js+++ b/src/server.js@@ -36,17 +36,44 @@ function safeJoin(base, rel) {return p;}+// Project files the engine page may read: scenes.js and the modules it+// imports, images, audio and video. Never dotfiles such as .env, and no+// JSON, Markdown or text files, which can hold keys or private notes.+const PROJECT_FILES = /\.(m?js|png|jpe?g|webp|gif|svg|wav|mp3|mp4)$/i;++function projectFile(projectDir, rel) {+ const parts = rel.split(/[\\/]+/);+ if (parts.some((x) => x.startsWith('.')) || !PROJECT_FILES.test(rel)) return null;+ return safeJoin(projectDir, rel);+}++// Uploads from the page may only land in build/ or out/, checked after the+// path is normalized so "build/../scenes.js" is refused.+function uploadFile(projectDir, rel) {+ const dest = safeJoin(projectDir, rel);+ if (!dest) return null;+ const inside = ['build', 'out'].some((d) => dest.startsWith(path.join(projectDir, d) + path.sep));+ return inside ? dest : null;+}+export function startServer({ projectDir, getState, port = 0 }) {const roughPath = resolveModule('roughjs/bundled/rough.esm.js');const server = http.createServer(async (req, res) => {try {+ // Only answer requests addressed to this machine. A web page on another+ // site that points its own domain at 127.0.0.1 (DNS rebinding) sends a+ // different Host header and is turned away.+ const port = server.address().port;+ const hosts = [`127.0.0.1:${port}`, `localhost:${port}`];+ if (!hosts.includes(req.headers.host)) return send(res, 403, 'forbidden host');+ const origin = req.headers.origin;+ if (origin && !hosts.some((h) => origin === `http://${h}`)) return send(res, 403, 'forbidden origin');const url = new URL(req.url, 'http://x');const p = decodeURIComponent(url.pathname);if (req.method === 'PUT' && p === '/__upload') {const rel = url.searchParams.get('path') || '';- if (!/^(build|out)\//.test(rel)) return send(res, 400, 'uploads go to build/ or out/');- const dest = safeJoin(projectDir, rel);- if (!dest) return send(res, 400, 'bad path');+ const dest = uploadFile(projectDir, rel);+ if (!dest) return send(res, 400, 'uploads go to build/ or out/');fs.mkdirSync(path.dirname(dest), { recursive: true });const chunks = [];for await (const c of req) chunks.push(c);@@ -65,7 +92,7 @@ export function startServer({ projectDir, getState, port = 0 }) {else if (p === '/vendor/rough.js') file = roughPath;else if (p.startsWith('/engine/')) file = safeJoin(path.join(ROOT, 'engine'), p.slice(8));else if (p.startsWith('/fonts/')) file = safeJoin(path.join(ROOT, 'fonts'), p.slice(7));- else if (p.startsWith('/project/')) file = safeJoin(projectDir, p.slice(9));+ else if (p.startsWith('/project/')) file = projectFile(projectDir, p.slice(9));if (!file || !fs.existsSync(file) || !fs.statSync(file).isFile()) return send(res, 404, `not found: ${p}`);const type = TYPES[path.extname(file).toLowerCase()] || 'application/octet-stream';res.writeHead(200, { 'Content-Type': type, 'Cache-Control': 'no-store' });diff --git a/src/voice.js b/src/voice.jsindex f840fb6..4a204f2 100644--- a/src/voice.js+++ b/src/voice.js@@ -1,6 +1,6 @@// Turns each scene's narration into a WAV file plus word timings.// Results are cached per scene in build/voice/<scene>.json and only-// regenerated when the words, voice, speed or pacing change.+// regenerated when the words, markers, voice, speed or pacing change.import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';@@ -22,6 +22,9 @@ function sceneHash(scene, chunks, config) {voice: config.voice,speed: config.speed * config.pace,chunks: chunks.map((c) => [c.gapBefore, c.text]),+ // Markers and the shown text of each word are saved with the timings,+ // so moving a [#marker] or changing {shown|spoken} makes the scene again.+ layout: scene.units.map((u) => (u.type === 'mark' ? `#${u.name}` : u.type === 'word' ? u.display : '')).join('|'),})).digest('hex').slice(0, 16);diff --git a/test/browser.test.js b/test/browser.test.jsnew file mode 100644index 0000000..f23a637--- /dev/null+++ b/test/browser.test.js@@ -0,0 +1,26 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { findChrome } from '../src/browser.js';++test('finds the headless shell that Playwright installs on Windows', () => {+ const base = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-pw-'));+ const exe = path.join(base, 'chromium_headless_shell-1300', 'chrome-headless-shell-win64', 'chrome-headless-shell.exe');+ fs.mkdirSync(path.dirname(exe), { recursive: true });+ fs.writeFileSync(exe, '');+ const saved = { pw: process.env.PLAYWRIGHT_BROWSERS_PATH, ex: process.env.EXPLAINROO_CHROME, cp: process.env.CHROME_PATH };+ try {+ process.env.PLAYWRIGHT_BROWSERS_PATH = base;+ delete process.env.EXPLAINROO_CHROME;+ delete process.env.CHROME_PATH;+ assert.equal(findChrome(), exe);+ } finally {+ for (const [k, v] of [['PLAYWRIGHT_BROWSERS_PATH', saved.pw], ['EXPLAINROO_CHROME', saved.ex], ['CHROME_PATH', saved.cp]]) {+ if (v === undefined) delete process.env[k];+ else process.env[k] = v;+ }+ fs.rmSync(base, { recursive: true, force: true });+ }+});diff --git a/test/formats-pace.test.js b/test/formats-pace.test.jsindex b5c1510..45611f9 100644--- a/test/formats-pace.test.js+++ b/test/formats-pace.test.js@@ -77,3 +77,28 @@ test('pace shortens lead-ins, holds and transitions', () => {assert.ok(fast.transitionSeconds < normal.transitionSeconds);assert.equal(fast.pace, 1.5);});++test('in a scene, times stay real seconds and pace shortens animations', async () => {+ const { Stage } = await import('../engine/stage.js');+ const { getTheme } = await import('../engine/themes.js');+ const cfg = normalizeConfig({ pace: 1.6 });+ const engine = {+ config: cfg,+ theme: getTheme('paper'),+ pen: null,+ W: 1920,+ H: 1080,+ fps: 30,+ safeArea: layoutAreas(cfg, 1920, 1080).safe,+ timeline: { pace: 1.6, duration: 10, frames: 300, fps: 30, width: 1920, height: 1080, scenes: [{}] },+ recorder: null,+ };+ const scene = { id: 'a', index: 0, start: 0, dur: 10, lead: 0.2, words: [{ text: 'hello', start: 1, end: 1.4 }], marks: { go: 3 }, voice: { dur: 2 } };+ const s = new Stage(engine, null, scene, 1.5);+ assert.equal(s.time(4), 4);+ assert.equal(s.time('hello') + 0.3, 1.3);+ assert.equal(s.time('#go'), 3);+ assert.equal(s.p(1, 0.8), 1); // 0.8 s at pace 1.6 takes 0.5 s, so it is done at 1.5+ close(s.p(1, 1.6), 0.5); // halfway through 1 s of real time+ assert.equal(s.pace, 1.6);+});diff --git a/test/server.test.js b/test/server.test.jsnew file mode 100644index 0000000..efb5105--- /dev/null+++ b/test/server.test.js@@ -0,0 +1,49 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import http from 'node:http';+import { startServer } from '../src/server.js';++function request(port, { method = 'GET', path: p, host = `127.0.0.1:${port}`, origin, body }) {+ return new Promise((resolve, reject) => {+ const headers = { host };+ if (origin) headers.origin = origin;+ const req = http.request({ host: '127.0.0.1', port, method, path: p, headers }, (res) => {+ let data = '';+ res.on('data', (c) => (data += c));+ res.on('end', () => resolve({ status: res.statusCode, body: data }));+ });+ req.on('error', reject);+ req.end(body);+ });+}++test('the preview server keeps secrets and sources safe', async () => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-server-'));+ fs.writeFileSync(path.join(dir, '.env'), 'OPENROUTER_API_KEY=secret');+ fs.writeFileSync(path.join(dir, 'notes.md'), 'private');+ fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default {};');+ fs.mkdirSync(path.join(dir, 'assets'));+ fs.writeFileSync(path.join(dir, 'assets', 'logo.png'), 'png');+ const server = await startServer({ projectDir: dir, getState: () => ({}) });+ try {+ const port = server.port;+ assert.equal((await request(port, { path: '/project/scenes.js' })).status, 200);+ assert.equal((await request(port, { path: '/project/assets/logo.png' })).status, 200);+ assert.equal((await request(port, { path: '/project/.env' })).status, 404);+ assert.equal((await request(port, { path: '/project/notes.md' })).status, 404);+ assert.equal((await request(port, { path: '/project/assets/../.env' })).status, 404);+ assert.equal((await request(port, { path: '/project/scenes.js', host: 'evil.example:80' })).status, 403);+ assert.equal((await request(port, { path: '/project/scenes.js', origin: 'http://evil.example' })).status, 403);+ const put = (p) => request(port, { method: 'PUT', path: `/__upload?path=${encodeURIComponent(p)}`, body: 'x' });+ assert.equal((await put('build/../scenes.js')).status, 400);+ assert.equal(fs.readFileSync(path.join(dir, 'scenes.js'), 'utf8'), 'export default {};');+ assert.equal((await put('out/stills/a.png')).status, 200);+ assert.ok(fs.existsSync(path.join(dir, 'out', 'stills', 'a.png')));+ } finally {+ await server.close();+ fs.rmSync(dir, { recursive: true, force: true });+ }+});