Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { createStickmanRemotionExecutor } from '../../src/creator/stickman/remotion-executor.js';
import { readStickmanRemotionRuntime } from '../../src/creator/stickman/remotion-runtime.js';
let tempDir = '';
afterEach(() => {
if (tempDir) rmSync(tempDir, { recursive: true, force: true });
tempDir = '';
});
describe('stickman Remotion worker isolation', () => {
it('accepts visual assets from the packaged runtime manifest', () => {
tempDir = mkdtempSync(join(tmpdir(), 'creator-stickman-runtime-'));
const visualAssetPath = join(tempDir, 'catalog.json');
writeFileSync(visualAssetPath, '{}\n');
writeFileSync(join(tempDir, 'manifest.json'), JSON.stringify({
version: 1,
platform: process.platform,
arch: process.arch,
remotionVersion: '4.0.473',
chromiumVersion: 'test',
bundlePath: 'bundle',
browserExecutable: 'browser',
resources: [{
path: 'catalog.json',
kind: 'visual-asset',
sha256: '0'.repeat(64),
bytes: 3,
version: '1',
platform: process.platform,
arch: process.arch
}]
}));
expect(readStickmanRemotionRuntime(tempDir)).toEqual({
root: tempDir,
bundlePath: join(tempDir, 'bundle'),
browserExecutable: join(tempDir, 'browser')
});
});
it('runs the worker without spawning process.execPath as a Node executable', async () => {
tempDir = mkdtempSync(join(tmpdir(), 'creator-stickman-remotion-success-'));
const timelinePath = join(tempDir, 'timeline.json');
writeFileSync(timelinePath, JSON.stringify({ fps: 30, width: 1280, height: 720, totalFrames: 30, shots: [] }));
const successWorker = join(tempDir, 'success-worker.mjs');
writeFileSync(successWorker, [
"import { readFileSync, writeFileSync } from 'node:fs';",
'const request = JSON.parse(readFileSync(process.argv[2], \'utf8\'));',
"writeFileSync(request.outputPath, 'fixture-video');",
"writeFileSync(process.argv[3], JSON.stringify({ ok: true }));"
].join('\n'));
const executor = createStickmanRemotionExecutor({
ffprobePath: 'unused',
runtimeRoot: tempDir,
workerEntrypoint: successWorker,
runtime: { root: tempDir, bundlePath: join(tempDir, 'bundle'), browserExecutable: join(tempDir, 'browser') },
validateVideo: async () => ({ duration: 1, width: 1280, height: 720, hasVideo: true, hasAudio: true })
});
const result = await executor.run({
stageRun: { id: 'stage-success', stageId: 'render-clean' },
job: { id: 'job-success' },
inputArtifacts: [{ id: 'timeline-1', kind: 'timeline_manifest', status: 'completed', path: timelinePath }],
workdir: tempDir,
reportProgress() {},
signal: new AbortController().signal
} as never);
expect(result.outputs).toHaveLength(1);
expect(existsSync(join(tempDir, 'landscape-clean.mp4'))).toBe(true);
});
it('preserves structured component rendering errors instead of stderr warnings', async () => {
tempDir = mkdtempSync(join(tmpdir(), 'creator-stickman-remotion-error-'));
const timelinePath = join(tempDir, 'timeline.json');
writeFileSync(timelinePath, JSON.stringify({ fps: 30, totalFrames: 30, shots: [] }));
const errorWorker = join(tempDir, 'error-worker.mjs');
writeFileSync(errorWorker, [
"import { writeFileSync } from 'node:fs';",
"process.stderr.write('environment warning');",
"writeFileSync(process.argv[3], JSON.stringify({ ok: false, error: 'renderer dependency missing' }));",
'process.exitCode = 1;'
].join('\n'));
const executor = createStickmanRemotionExecutor({
ffprobePath: 'unused', runtimeRoot: tempDir, workerEntrypoint: errorWorker,
runtime: { root: tempDir, bundlePath: join(tempDir, 'bundle'), browserExecutable: join(tempDir, 'browser') }
});
await expect(executor.run({
stageRun: { id: 'stage-error', stageId: 'render-clean' }, job: { id: 'job-error' },
inputArtifacts: [{ id: 'timeline-1', kind: 'timeline_manifest', status: 'completed', path: timelinePath }],
workdir: tempDir, reportProgress() {}, signal: new AbortController().signal
} as never)).rejects.toMatchObject({ code: 'stickman_remotion_failed', message: 'renderer dependency missing' });
});
it('isolates worker crashes and cancellation without leaving a clean video', async () => {
tempDir = mkdtempSync(join(tmpdir(), 'creator-stickman-remotion-'));
const timelinePath = join(tempDir, 'timeline.json');
writeFileSync(timelinePath, JSON.stringify({ fps: 30, width: 1280, height: 720, totalFrames: 30, shots: [] }));
const crashWorker = join(tempDir, 'crash-worker.ts');
writeFileSync(crashWorker, "const code: number = 2; process.stderr.write('injected crash'); process.exit(code);\n");
const executor = createStickmanRemotionExecutor({
ffprobePath: 'unused',
runtimeRoot: tempDir,
workerEntrypoint: crashWorker,
runtime: { root: tempDir, bundlePath: join(tempDir, 'bundle'), browserExecutable: join(tempDir, 'browser') },
validateVideo: async () => ({ duration: 1, width: 1280, height: 720, hasVideo: true, hasAudio: true })
});
const baseInput = {
stageRun: { id: 'stage-1', stageId: 'render-clean' },
job: { id: 'job-1' },
inputArtifacts: [{ id: 'timeline-1', kind: 'timeline_manifest', status: 'completed', path: timelinePath }],
workdir: tempDir,
reportProgress() {}
};
await expect(executor.run({
...baseInput,
signal: new AbortController().signal
} as never)).rejects.toMatchObject({ code: 'stickman_remotion_worker_failed' });
expect(existsSync(join(tempDir, 'landscape-clean.mp4'))).toBe(false);
const waitWorker = join(tempDir, 'wait-worker.mjs');
writeFileSync(waitWorker, 'setInterval(() => {}, 1000);\n');
const cancelExecutor = createStickmanRemotionExecutor({
ffprobePath: 'unused',
runtimeRoot: tempDir,
workerEntrypoint: waitWorker,
runtime: { root: tempDir, bundlePath: join(tempDir, 'bundle'), browserExecutable: join(tempDir, 'browser') },
validateVideo: async () => ({ duration: 1, width: 1280, height: 720, hasVideo: true, hasAudio: true })
});
const controller = new AbortController();
const running = cancelExecutor.run({ ...baseInput, signal: controller.signal } as never);
setTimeout(() => controller.abort(), 100);
await expect(running).rejects.toMatchObject({ code: 'creator_stage_canceled' });
expect(existsSync(join(tempDir, 'landscape-clean.mp4'))).toBe(false);
});
});