Text to vertical video in 100+ styles: AI codes each scene (HTML/SVG/WebGL), renders a 9:16 MP4 with music and English/Vietnamese voice. MCP, CLI and REST for AI agents.
#!/usr/bin/env node
// Kiểm phần API mở rộng cho Studio (edit/manual.mjs + edit/http.mjs + edit/studio-media.mjs):
// zoom thêm/sửa (giây bản ra, không chồng), đồ hoạ dời/giãn giờ + sửa ô chữ/số (kiểu khớp, ≥ 1,5 s), giữ qua dựng lại,
// view có look css / vết cắt / ô đồ hoạ. Có cổng thì kiểm REST: manual?rev, strip, wave, tên file lạ, Origin lạ.
// node edit/test/studio-check.mjs [port] [editId đã dựng xong]
import http from 'node:http';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { parseManual, applyPatch, applyManual, manualView, changedLines } from '../manual.mjs';
import { scriptFixes, ReelImportSchema } from '../reel.mjs';
import { baseSig, cleanSig, glassItems, gfxWindow, gfxSig, dirtyRanges } from '../pipeline.mjs';
import { validateEdl } from '../edl.mjs';
let fails = 0;
const check = (ok, what) => { console.log(`${ok ? 'PASS' : 'FAIL'} ${what}`); if (!ok) fails++; };
const throws = (f, code, re) => { try { f(); return false; } catch (e) { return (code == null || e.code === code) && (!re || re.test(e.message)); } };
// ---- schema ----
check(!throws(() => parseManual({ zooms: { add: [{ at: 2, dur: 1, scale: 1.1, kind: 'push' }] } })), 'zoom add hợp lệ qua');
check(throws(() => parseManual({ zooms: { add: [{ at: 2, dur: 1, scale: 2, kind: 'push' }] } }), 400, /scale/), 'zoom scale 2 (trần 1,6) → 400');
check(throws(() => parseManual({ zooms: { add: [{ at: 2, dur: 1, scale: 1.1, kind: 'spin' }] } }), 400), 'zoom kiểu lạ → 400');
check(throws(() => parseManual({ zooms: { set: [{ n: 0, x: 1 }] } }), 400), 'zoom set khoá lạ → 400');
check(throws(() => parseManual({ graphics: { set: [{ id: 'g1', data: { html: '<b>' } }] } }), 400), 'đồ hoạ: ô lạ (html) → 400');
check(throws(() => parseManual({ graphics: { set: [{ id: 'g1', data: { title: 'x'.repeat(31) } }] } }), 400), 'đồ hoạ: tiêu đề > 30 ký tự → 400');
check(throws(() => parseManual({ graphics: { set: [{ id: 'g1', data: { rows: [{ k: 12, label: 'a' }] } }] } }), 400), 'đồ hoạ: dòng số 12 → 400');
// ---- EDL giả: 2 đoạn giữ, 2 zoom, 2 đồ hoạ ----
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'lumedit-studio-'));
const words = Array.from({ length: 24 }, (_, i) => ({ i, w: `chữ${i}`, start: 1 + i * 0.5, end: 1.4 + i * 0.5 })).filter((w) => w.end <= 7 || w.start >= 8);
const edl = {
version: 1, id: 't', createdAt: new Date().toISOString(), style: 'sach-gon',
source: { file: 'x.mp4', sha256: '0'.repeat(64), size: 1, duration: 20, startTime: 0, fps: 30, vfr: false, rotation: 0, width: 1920, height: 1080, codec: 'h264', hdr: false, hasAudio: true },
proxy: { file: 'x.mov', width: 1920, height: 1080, fps: 30, audioRate: 48000 },
output: { width: 1080, height: 1920, fps: 30, audioRate: 48000, lufs: -14 },
keep: [{ start: 0.5, end: 7 }, { start: 8, end: 13.5 }], removed: [{ start: 7, end: 8, reason: 'pause', words: '' }], reframe: { mode: 'center' },
zooms: [{ at: 1.2, dur: 1, scale: 1.2, kind: 'punch' }, { at: 9, dur: 1.5, scale: 1.1, kind: 'push' }],
captions: { style: 'sach-gon', renderer: 'hyperframes', maxWords: 3, position: 'lower', words, highlights: [1] },
sfx: [], music: null,
graphics: [
{ id: 'g1', type: 'spec_table', start: 2, end: 5, estimate: false, data: { at: 2.05, title: 'Giá', unit: 'triệu', rows: [{ label: 'A', value: '15', at: 3 }, { label: 'B', value: '22', at: 4 }] }, box: { x: 120, y: 200, w: 840, h: 300, scale: 1 }, face: null, squeeze: null },
{ id: 'g2', type: 'price_tag', start: 9.5, end: 11.5, estimate: false, data: { at: 9.55, value: 9.5, prefix: '', suffix: 'triệu', label: 'RTX' }, box: { x: 230, y: 600, w: 620, h: 240, scale: 1 }, face: null, squeeze: null },
],
hook: null, hookText: null, quote: null, audio: { crossfadeMs: 20, keepSourceAudio: true },
};
check(validateEdl(edl, { checkFiles: false }).ok, 'EDL giả hợp lệ');
const state = { style: 'sach-gon', draft: false };
// bản ra: [0.5–7] → 0–6.5, [8–13.5] → 6.5–12
const v = manualView(edl, state);
check(JSON.stringify(v.cuts) === '[6.5]', `vết cắt bản ra: ${JSON.stringify(v.cuts)}`);
check(v.captions.looks.every((l) => l.css && l.css.font && l.css.size > 0 && l.css.cy > 0), 'mỗi look có css (font, cỡ, cy) cho lớp xem trước');
check(v.graphics[0].data.rows[1].value === '22' && v.graphics[0].data.at === undefined && v.graphics[0].box?.w === 840, 'đồ hoạ trong view: ô chữ/số + box, không lộ mốc nội bộ');
// zoom thêm ở giây bản ra 7.0 (= nguồn 8.5), sửa zoom 0, xoá zoom 1
const a = applyPatch(edl, state, parseManual({ zooms: { add: [{ at: 7, dur: 1, scale: 1.15, kind: 'punch' }], set: [{ n: 0, scale: 1.3, dur: 0.8 }], remove: [1] } }), { dir: tmp });
check(a.edl.zooms.length === 2 && a.edl.zooms[1].at === 8.5 && a.edl.zooms[0].scale === 1.3 && a.edl.zooms[0].dur === 0.8, `zoom: thêm 7 s bản ra → 8,5 s nguồn, sửa zoom 0, xoá zoom 1 (${JSON.stringify(a.edl.zooms)})`);
check(a.redo.base && !a.redo.layer && !a.redo.mix, 'zoom đổi → chỉ dựng lại nền');
check(throws(() => applyPatch(edl, state, parseManual({ zooms: { add: [{ at: 0.9, dur: 1, scale: 1.1, kind: 'push' }] } }), { dir: tmp }), 400, /chồng/), 'zoom mới chồng zoom cũ → 400');
check(throws(() => applyPatch(edl, state, parseManual({ zooms: { add: [{ at: 11.9, dur: 1, scale: 1.1, kind: 'push' }] } }), { dir: tmp }), 400, /cuối/), 'zoom chạy quá cuối video → 400');
check(throws(() => applyPatch(edl, state, parseManual({ zooms: { set: [{ n: 5, scale: 1.1 }] } }), { dir: tmp }), 400), 'sửa zoom không có → 400');
// đồ hoạ: dời g1 sang 3–6 s bản ra, sửa ô; giãn g2
const b = applyPatch(edl, state, parseManual({ graphics: { set: [{ id: 'g1', start: 3, end: 6, data: { title: 'Giá mới', rows: [{ k: 0, value: '16' }] } }, { id: 'g2', end: 11.5 }] } }), { dir: tmp });
const g1 = b.edl.graphics.find((g) => g.id === 'g1'); const g2 = b.edl.graphics.find((g) => g.id === 'g2');
check(g1.start === 3.5 && g1.end === 6.5 && g1.data.title === 'Giá mới' && g1.data.rows[0].value === '16', `dời g1 3–6 s bản ra → ${g1.start}–${g1.end} s nguồn, sửa tiêu đề + ô`);
check(g1.data.rows[0].at > g1.data.at && g1.data.rows[1].at <= g1.end && g1.data.at >= g1.start, 'mốc dòng trong đồ hoạ dời theo, nằm trong khoảng mới');
check(g2.end === 13 && b.redo.base && b.redo.layer, `giãn g2 tới 11,5 s bản ra (nguồn ${g2.end}); dời giờ → nền + lớp chữ`);
check(validateEdl(b.edl, { checkFiles: false }).ok, 'EDL sau dời đồ hoạ hợp lệ');
check(throws(() => applyPatch(edl, state, parseManual({ graphics: { set: [{ id: 'g1', start: 3, end: 4 }] } }), { dir: tmp }), 400, /1.5/), 'đồ hoạ < 1,5 s → 400');
check(throws(() => applyPatch(edl, state, parseManual({ graphics: { set: [{ id: 'g2', data: { value: 'mười' } }] } }), { dir: tmp }), 400, /số/), 'ô số nhận chữ → 400');
check(throws(() => applyPatch(edl, state, parseManual({ graphics: { set: [{ id: 'g1', data: { text: 'x' } }] } }), { dir: tmp }), 400, /không có ô/), 'ô không có ở loại đồ hoạ này → 400');
check(throws(() => applyPatch(edl, state, parseManual({ graphics: { set: [{ id: 'g9', end: 9 }] } }), { dir: tmp }), 400), 'đồ hoạ không có → 400');
const c = applyPatch(edl, state, parseManual({ graphics: { set: [{ id: 'g2', data: { value: '10,5' } }] } }), { dir: tmp });
check(c.edl.graphics[1].data.value === 10.5 && c.redo.layer, 'ô số nhận "10,5" → 10.5, chỉ đổi chữ → lớp chữ');
// dựng lại EDL (sửa bằng lời): giữ zoom thêm/sửa/xoá + đồ hoạ dời/sửa
const man = { ...a.manual, ...b.manual };
const rebuilt = JSON.parse(JSON.stringify(edl));
applyManual(rebuilt, man);
check(rebuilt.zooms.length === 2 && rebuilt.zooms.some((z) => z.at === 8.5 && z.kind === 'punch') && rebuilt.zooms.some((z) => z.scale === 1.3), 'dựng lại: giữ zoom thêm + zoom sửa, bỏ zoom đã xoá');
const rg = rebuilt.graphics.find((g) => g.id === 'g1');
check(rg.start === 3.5 && rg.end === 6.5 && rg.data.title === 'Giá mới', 'dựng lại: giữ đồ hoạ đã dời + sửa chữ');
fs.rmSync(tmp, { recursive: true, force: true });
// ---- mục 6: đếm dòng đổi đúng (chữ AI sửa thành 2 từ, nhấn) ----
{
const e6 = JSON.parse(JSON.stringify(edl));
e6.graphics = []; e6.zooms = [];
e6.captions.words = e6.captions.words.map((w) => (w.i === 1 ? { ...w, w: 'RTX 5060' } : w));
e6.captions.highlights = [1];
const v6 = manualView(e6, state);
check(v6.captions.lines.some((l) => l.text.includes('*RTX 5060*')), 'chữ AI sửa thành 2 từ hiện "*RTX 5060*" trong dòng');
const ls = v6.captions.lines.map((l) => ({ start: l.start, end: l.end, text: l.text }));
const k = ls.findIndex((l) => !l.text.includes('RTX'));
ls[k].text += ' nhé';
const r6 = applyPatch(e6, state, parseManual({ captions: { lines: ls } }), { dir: os.tmpdir() });
check(/phụ đề: 1 dòng đổi/.test(r6.summary.join('; ')), `sửa 1 dòng → lịch sử "${r6.summary[0]}" (trước đây đếm cả dòng *RTX 5060* thành đổi)`);
check(changedLines(['a', 'a', 'b'], ['a', 'b', 'b']) === 1 && changedLines(['a', 'b'], ['a']) === 1, 'đếm dòng đổi theo bội (dòng trùng chữ)');
}
// ---- mục 5: chữ ký nền chỉ băm phần vẽ trong nền; lớp phụ đề render lại từng đoạn ----
{
const e5 = JSON.parse(JSON.stringify(edl));
const b0 = baseSig(e5, false);
const e5b = JSON.parse(JSON.stringify(e5)); e5b.graphics[0].data.title = 'khác'; e5b.graphics[0].start += 0.5; e5b.graphics[0].box.y += 10;
check(baseSig(e5b, false) === b0, 'sửa chữ / giờ / vị trí đồ hoạ: chữ ký nền KHÔNG đổi (không render lại nền)');
const e5c = JSON.parse(JSON.stringify(e5)); e5c.captions.lines = [{ start: 0, end: 1, words: [{ w: 'a', o: 0, hi: false }] }];
check(baseSig(e5c, false) === b0, 'sửa phụ đề: chữ ký nền không đổi');
const e5d = JSON.parse(JSON.stringify(e5)); e5d.zooms[0].scale = 1.3;
check(baseSig(e5d, false) !== b0, 'đổi zoom: chữ ký nền đổi');
const e5e = JSON.parse(JSON.stringify(e5)); e5e.graphics[0].squeeze = { scale: 0.8, anchorY: 900 };
check(baseSig(e5e, false) !== b0, 'đồ hoạ thu hình (squeeze): chữ ký nền đổi');
check(cleanSig(e5d) === cleanSig(e5), 'bản sạch xem trước không đổi khi chỉ đổi zoom');
const gi = glassItems(e5);
check(gi.length === 1 && gi[0].w === 840 && gi[0].t0 === 1.5 && gi[0].r === 38, `kính mờ vẽ lúc ghép: bảng có kính, tem giá không (${JSON.stringify(gi)})`);
const w1 = gfxWindow(e5, e5.graphics[0]);
check(w1.from === 1.5 && Math.abs(w1.dur - 3) < 0.05, `lớp đồ hoạ riêng chỉ render khoảng nó hiện (${JSON.stringify(w1)})`);
check(gfxSig(e5.graphics[0], '#fff', w1) !== gfxSig(e5b.graphics[0], '#fff', w1), 'sửa chữ đồ hoạ: chữ ký lớp đồ hoạ đổi');
const card = (s, e, k) => ({ s, e, k });
const prev = { global: 'G', duration: 30, cards: [card(1, 2, 'a'), card(2, 3, 'b'), card(10, 11, 'c')] };
const dr = dirtyRanges(prev, { global: 'G', duration: 30, cardsMeta: [card(1, 2, 'a'), card(2, 3, 'B'), card(10, 11, 'c')] });
check(dr.length === 1 && dr[0][0] <= 1.95 && dr[0][0] >= 1.9 && dr[0][1] >= 3.3 && dr[0][1] <= 3.4, `khoảng render lại quanh thẻ đổi: ${JSON.stringify(dr)}`);
check(dirtyRanges(prev, { global: 'G2', duration: 30, cardsMeta: prev.cards }) === null, 'đổi kiểu chữ (global) → render cả lớp');
check(JSON.stringify(dirtyRanges(prev, { global: 'G', duration: 30, cardsMeta: prev.cards })) === '[]', 'không thẻ nào đổi → không render gì');
const many = { global: 'G', duration: 30, cardsMeta: [card(0, 20, 'x')] };
check(dirtyRanges(prev, many) === null, 'đổi > 55% thời lượng → render cả lớp');
}
// ---- mục 9: cắt bỏ đoạn trên track video, bật/tắt phụ đề, sửa chữ theo kịch bản reel ----
{
const e9 = JSON.parse(JSON.stringify(edl));
// bản ra: [0.5–7] → 0–6.5, [8–13.5] → 6.5–12; dòng chỉnh tay để kiểm dời giờ
const v9 = manualView(e9, state);
const lines9 = v9.captions.lines.map((l) => ({ start: l.start, end: l.end, text: l.text }));
const base9 = applyPatch(e9, state, parseManual({ captions: { lines: lines9.map((l, k) => (k === 0 ? { ...l, text: l.text + ' a' } : l)) } }), { dir: os.tmpdir() }).edl;
const lv = manualView(base9, state).captions.lines;
const c = applyPatch(base9, state, parseManual({ cuts: { remove: [{ start: 2, end: 3 }] } }), { dir: os.tmpdir() });
const tl9 = c.edl.keep.map((k) => [k.start, k.end]);
check(JSON.stringify(tl9) === JSON.stringify([[0.5, 2.5], [3.5, 7], [8, 13.5]]), `cắt 2–3 s bản ra → keep ${JSON.stringify(tl9)}`);
check(c.redo.base && c.redo.layer && c.redo.mix && JSON.stringify(c.extraCuts) === JSON.stringify([{ start: 2.5, end: 3.5 }]), `cắt → dựng lại nền + chữ + tiếng; lưu khoảng nguồn ${JSON.stringify(c.extraCuts)}`);
const after = manualView(c.edl, state);
check(Math.abs(after.duration - 11) < 0.01, `bản ra 12 → ${after.duration} s`);
const l0 = lv.find((l) => l.start >= 3); const l1 = after.captions.lines.find((l) => l.text === l0.text);
check(!!l1 && Math.abs(l1.start - (l0.start - 1)) < 0.02, `dòng phụ đề sau chỗ cắt dời lên 1 s (${l0.start} → ${l1?.start})`);
const lc = lv[2]; const c2 = applyPatch(base9, state, parseManual({ cuts: { remove: [{ start: lc.start, end: lc.end }] } }), { dir: os.tmpdir() });
const after2 = manualView(c2.edl, state); const inside = 1;
check(!after2.captions.lines.some((l) => l.text === lc.text) && after2.captions.lines.length === lv.length - inside, `dòng nằm trọn trong chỗ cắt bị bỏ (${lv.length} → ${after2.captions.lines.length}, bỏ dòng \"${lc.text}\")`);
check(validateEdl(c.edl, { checkFiles: false }).ok, 'EDL sau cắt hợp lệ');
check(throws(() => applyPatch(e9, state, parseManual({ cuts: { remove: [{ start: 0, end: 11.5 }] } }), { dir: os.tmpdir() }), 400, /còn/), 'cắt gần hết (còn < 1 s) → 400');
check(throws(() => parseManual({ cuts: { remove: [] } }), 400), 'cuts rỗng → 400');
check(throws(() => parseManual({ cuts: { remove: [{ start: 1, end: 2, x: 1 }] } }), 400), 'cuts khoá lạ → 400');
const re = JSON.parse(JSON.stringify(edl)); applyManual(re, c.manual);
const off = applyPatch(e9, state, parseManual({ captions: { show: false } }), { dir: os.tmpdir() });
check(off.edl.captions.off === true && off.redo.layer && !off.redo.base && manualView(off.edl, state).captions.show === false, 'tắt phụ đề → captions.off, chỉ lớp chữ');
const on = applyPatch(off.edl, state, parseManual({ captions: { show: true } }), { dir: os.tmpdir() });
check(on.edl.captions.off === false && /bật phụ đề/.test(on.summary.join()), 'bật lại phụ đề');
const re2 = JSON.parse(JSON.stringify(edl)); applyManual(re2, off.manual);
check(re2.captions.off === true, 'dựng lại giữ trạng thái tắt phụ đề');
const fx = scriptFixes([{ i: 0, w: 'Go' }, { i: 1, w: 'chu.' }, { i: 2, w: 'Chọn' }, { i: 3, w: 'mẫu' }, { i: 4, w: 'reo' }, { i: 5, w: 'video.' }], 'Gõ chữ. Chọn mẫu. Ra video.');
check(JSON.stringify(fx) === JSON.stringify([{ word: 0, text: 'Gõ' }, { word: 1, text: 'chữ' }, { word: 4, text: 'Ra' }]), `sửa chữ whisper theo lời đọc reel: ${JSON.stringify(fx)}`);
check(ReelImportSchema.safeParse({ job: '../x' }).success === false && ReelImportSchema.safeParse({ job: 'abc-1', x: 1 }).success === false, 'nhập reel: id lạ / khoá lạ → từ chối');
}
// ---- REST ----
const PORT = Number(process.argv[2]); const ID = process.argv[3];
if (PORT) {
const HOST = `127.0.0.1:${PORT}`;
const req = ({ method = 'GET', p, headers = {}, body }) => new Promise((resolve) => {
const r = http.request({ host: '127.0.0.1', port: PORT, method, path: p, headers: { Host: HOST, ...headers } }, (res) => {
let d = ''; res.on('data', (x) => { d += x; }); res.on('end', () => resolve({ code: res.statusCode, body: d, type: res.headers['content-type'] }));
});
r.on('error', (e) => resolve({ code: -1, body: e.message }));
r.end(body);
});
let r = await req({ p: '/api/edits/khong-co/strip' }); check(r.code === 404, `strip id lạ → 404 (${r.code})`);
r = await req({ p: '/api/edits/khong-co/wave' }); check(r.code === 404, `wave id lạ → 404 (${r.code})`);
if (ID) {
r = await req({ p: `/api/edits/${ID}/manual?rev=0` });
const v0 = r.code === 200 ? JSON.parse(r.body) : null;
check(!!v0 && v0.rev === 0 && v0.readOnly === true && /out\.mp4/.test(v0.media.out || ''), `manual?rev=0 → bản gốc, chỉ đọc (${r.code})`);
r = await req({ p: `/api/edits/${ID}/manual` });
const vl = JSON.parse(r.body);
check(vl.rev === vl.latest && !vl.readOnly && Array.isArray(vl.versions) && vl.versions.length === vl.latest + 1, `manual mới nhất r${vl.latest}, ${vl.versions.length} bản`);
r = await req({ p: `/api/edits/${ID}/manual?rev=999` }); check(r.code === 404, `rev không có → 404 (${r.code})`);
r = await req({ p: `/api/edits/${ID}/manual?rev=-1` }); check(r.code === 404, `rev âm → 404 (${r.code})`);
r = await req({ p: `/api/edits/${ID}/strip?out=${encodeURIComponent(vl.media.outName)}` });
const s = r.code === 200 ? JSON.parse(r.body) : null;
check(!!s && s.n > 0 && s.every > 0 && /^\/edits\//.test(s.url), `strip ${vl.media.outName}: ${s?.n} ô, ${s?.every} s/ô`);
if (s) { r = await req({ p: s.url.split('?')[0] }); check(r.code === 200 && r.type === 'image/jpeg', `ảnh strip phục vụ được (${r.code} ${r.type})`); }
r = await req({ p: `/api/edits/${ID}/strip?out=..%2F..%2Fx.mp4` }); check(r.code === 400, `strip out có ../ → 400 (${r.code})`);
r = await req({ p: `/api/edits/${ID}/strip?out=job.json` }); check(r.code === 400, `strip out không phải bản ra → 400 (${r.code})`);
r = await req({ p: `/api/edits/${ID}/wave?src=synth:chill` });
const w = r.code === 200 ? JSON.parse(r.body) : null;
check(!!w && w.rate === 25 && w.peaks.length > 100 && Math.max(...w.peaks) <= 1 && /music-chill\.wav/.test(w.url), `wave synth:chill: ${w?.peaks.length} đỉnh, ${w?.seconds} s`);
r = await req({ p: `/api/edits/${ID}/wave?src=../../etc/passwd` }); check(r.code === 400, `wave nguồn lạ → 400 (${r.code})`);
r = await req({ p: `/api/edits/${ID}/wave?file=job.json&src=x` }); check(r.code === 400, `wave file lạ không được đọc → 400 (${r.code})`);
r = await req({ p: `/edits/${ID}/job.json` }); check(r.code === 404, `/edits/<id>/job.json không phục vụ (${r.code})`);
r = await req({ p: `/edits/${ID}/state.json` }); check(r.code === 404, `/edits/<id>/state.json không phục vụ (${r.code})`);
r = await req({ method: 'HEAD', p: `/edits/${ID}/base.mp4` }); check(r.code === 200 || r.code === 404, `base.mp4 phục vụ được khi có (${r.code})`);
r = await req({ method: 'POST', p: `/api/edits/${ID}/manual`, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ zooms: { add: [{ at: 0.01, dur: 8, scale: 1.1, kind: 'push' }, { at: 0.02, dur: 8, scale: 1.1, kind: 'push' }] } }) });
check(r.code === 400, `zoom thêm chồng nhau → 400 đồng bộ, không xếp hàng (${r.code})`);
r = await req({ method: 'POST', p: '/api/edits/from-reel', headers: { 'Content-Type': 'application/json' }, body: '{"job":"../../etc"}' }); check(r.code === 400, `nhập reel: id có ../ → 400 (${r.code})`);
r = await req({ method: 'POST', p: '/api/edits/from-reel', headers: { 'Content-Type': 'application/json' }, body: '{"job":"khong-co-video"}' }); check(r.code === 404, `nhập reel: video không có → 404 (${r.code})`);
r = await req({ method: 'POST', p: '/api/edits/from-reel', headers: { 'Content-Type': 'application/json', Origin: 'https://evil.example' }, body: '{"job":"x"}' }); check(r.code === 403, `nhập reel từ Origin lạ → 403 (${r.code})`);
r = await req({ method: 'POST', p: `/api/edits/${ID}/manual`, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ cuts: { remove: [{ start: 0, end: 3600 }] } }) }); check(r.code === 400, `cắt hết video → 400 đồng bộ (${r.code})`);
r = await req({ method: 'POST', p: `/api/edits/${ID}/manual`, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ graphics: { set: [{ id: 'khong-co', end: 3 }] } }) });
check(r.code === 400, `đồ hoạ không có → 400 (${r.code})`);
}
}
console.log(fails ? `\n${fails} FAIL` : '\nTẤT CẢ PASS');
process.exit(fails ? 1 : 0);