Skip to content

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.

4.5 KB
Raw Blame
// T4 (THIET-KE gói mẫu §3.3): xuất 143 mẫu + 14 cách dựng gốc rồi nhập lại vào LUMREELS_HOME tạm:
// 0 lỗi, text trùng từng byte với file trong repo (file CRLF trong repo: trùng sau khi đổi \r\n → \n, vì L6 chuẩn hoá xuống dòng).
//   node packs/test/t4-roundtrip.mjs [--out <thư mục>]   (--out: ghi thêm 2 file gói chính thức lumreels.* ra thư mục đó)
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { check, info, done, ROOT } from './helpers.mjs';

const HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'lumreels-t4-'));
process.env.LUMREELS_HOME = HOME;
const { exportPack, readPack, installPack } = await import('../pack.mjs');
const { packsDir, BUILTIN_STYLES, resolveTemplate, listTemplates } = await import('../registry.mjs');
const catalog = JSON.parse(fs.readFileSync(path.join(ROOT, 'templates', 'catalog.json'), 'utf8'));
const outDir = (() => { const i = process.argv.indexOf('--out'); return i > 0 ? path.resolve(process.argv[i + 1]) : null; })();

const tplItems = catalog.map((t) => 'template:' + t.id);
const styleItems = BUILTIN_STYLES.map((s) => 'style:' + s);
console.log(`== T4: ${tplItems.length} mẫu + ${styleItems.length} cách dựng (LUMREELS_HOME=${HOME})`);
const common = { author: { name: 'Lumtek', contact: 'reels.lumtek.net' }, license: 'MIT', provenance: 'original', version: '1.0.0' };
const packs = [
  { id: 't4.mau-goc', name: 'Mẫu gốc LumReels', items: tplItems, kind: 'template', dir: 'templates', src: (slug) => path.join(ROOT, 'templates', 'guidance', `${slug.replace(/^mau-/, '')}.md`), thumb: (slug) => path.join(ROOT, 'templates', 'thumbs', `${slug.replace(/^mau-/, '')}.webp`) },
  { id: 't4.cach-dung-goc', name: 'Cách dựng gốc LumReels', items: styleItems, kind: 'edit-style', dir: 'styles', src: (slug) => path.join(ROOT, 'edit-styles', `${slug}.md`), thumb: (slug) => path.join(ROOT, 'edit-styles', 'thumbs', `${slug}.webp`) },
];
for (const p of packs) {
  const t0 = Date.now();
  const ex = exportPack({ ...common, id: p.id, name: p.name, items: p.items });
  info(`${p.id}: ${ex.manifest.items.length} mục, ${(ex.buffer.length / 1024 / 1024).toFixed(2)} MB, ${ex.report.warnings.length} cảnh báo chữ, ${((Date.now() - t0) / 1000).toFixed(1)}s`);
  check(ex.manifest.items.length === p.items.length, `${p.id}: xuất đủ ${p.items.length} mục`);
  check(ex.buffer.length <= 12 * 1024 * 1024, `${p.id}: file ≤ 12 MB`, `${ex.buffer.length} byte`);
  const f = path.join(HOME, `${p.id}.lumpack`);
  fs.writeFileSync(f, ex.buffer);
  const rd = readPack(f);
  check(rd.report.errors.length === 0, `${p.id}: nhập lại 0 lỗi`, rd.report.errors.slice(0, 2).join(' | '));
  installPack(rd);
  let same = 0; let sameLf = 0; const diff = []; let thumbs = 0; let thumbOk = 0;
  for (const it of rd.items) {
    const repo = fs.readFileSync(p.src(it.slug));
    const got = fs.readFileSync(path.join(packsDir(), p.id, p.dir, `${it.slug}.md`));
    if (repo.equals(got)) same++;
    else if (Buffer.from(repo.toString('utf8').replace(/\r\n/g, '\n'), 'utf8').equals(got)) sameLf++;
    else diff.push(it.slug);
    if (fs.existsSync(p.thumb(it.slug))) {
      thumbs++;
      const g = path.join(packsDir(), p.id, 'thumbs', `${p.kind}-${it.slug}.webp`);
      if (fs.existsSync(g) && fs.readFileSync(g).equals(fs.readFileSync(p.thumb(it.slug)))) thumbOk++;
    }
  }
  check(diff.length === 0, `${p.id}: text khớp repo — ${same} trùng từng byte, ${sameLf} chỉ khác CRLF→LF`, diff.slice(0, 5).join(', '));
  check(thumbOk === thumbs, `${p.id}: ảnh trùng từng byte ${thumbOk}/${thumbs}`);
}
const lt = listTemplates();
check(lt.filter((t) => t.source === 'pack').length === tplItems.length, `listTemplates thấy ${tplItems.length} mẫu gói + ${lt.filter((t) => t.source === 'builtin').length} mẫu gốc`);
const r = resolveTemplate('t4.mau-goc/mau-009');
check(!!r && r.restricted && r.source === 'pack' && r.meta.name === catalog.find((t) => t.id === '009').name, 'resolveTemplate("t4.mau-goc/mau-009"): nguồn pack, chạy khoá, đúng tên');

if (outDir) {
  fs.mkdirSync(outDir, { recursive: true });
  for (const p of packs) {
    const id = p.id.replace(/^t4\./, 'lumreels.');
    const ex = exportPack({ ...common, id, name: p.name, items: p.items });
    const f = path.join(outDir, `${id}-1.0.0.lumpack`);
    fs.writeFileSync(f, ex.buffer);
    info(`đã ghi ${f} (${(ex.buffer.length / 1024 / 1024).toFixed(2)} MB, sha256 ${ex.fileSha256})`);
  }
}
fs.rmSync(HOME, { recursive: true, force: true });
done('T4');