#!/usr/bin/env node // E2E fake chough. Mimics the args the chough app builds (transcriptionApps.ts): // chough -f json -o [-c ] [-r] // Writes the output to EXACTLY (no ".json" appended — this is the key // behavioural difference from whisper-cli's -of), in chough's native JSON shape // { duration_seconds, chunks, text, chunk_data: [{ start_time, end_time, text }] } // with times in SECONDS. Run from cwd == the video dir (set by runWhisperBatch). import { writeFile } from "node:fs/promises"; import { installFixtureWatchdog } from "./_watchdog.mjs"; // Never outlive the run that spawned us — see _watchdog.mjs. installFixtureWatchdog(); const argv = process.argv.slice(2); function arg(flag) { const i = argv.indexOf(flag); return i < 0 ? undefined : argv[i + 1]; } const out = arg("-o"); const audio = argv[argv.length - 1]; if (!out) { process.stderr.write(`[fake-chough] missing -o\n`); process.exit(2); } const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); // Videos whose dir (== video id) contains the SLOWOP marker emit chough-style // progress output (audio header + █/░ bars + ETA) with real delays, so the // per-operation progress bars and drain behaviour can be observed. Videos // without the marker stay instant so the rest of the suite is fast. const totalSec = 50; if (process.cwd().toLowerCase().includes("slowop")) { process.stdout.write(`mode: local\n`); process.stdout.write(`audio: ${totalSec}.0s • chunks: 60s • format: json\n`); const width = 40; for (let step = 1; step <= 10; step += 1) { const filled = Math.round((step / 10) * width); const bar = "█".repeat(filled) + "░".repeat(width - filled); const etaSec = Math.max(0, Math.round(((10 - step) / 10) * 30)); process.stdout.write( `${bar} ETA ${Math.floor(etaSec / 60)}m ${etaSec % 60}s\x1b[K\n`, ); await sleep(700); } } const doc = { duration_seconds: totalSec, chunks: 2, text: `Synthetic chough output for ${audio} #1 Synthetic chough output for ${audio} #2`, chunk_data: [ { start_time: 0, end_time: 5, text: `Synthetic chough output for ${audio} #1` }, { start_time: 5, end_time: 10, text: `Synthetic chough output for ${audio} #2` }, ], }; // chough writes EXACTLY the -o path (no extension munging). await writeFile(out, JSON.stringify(doc)); process.stdout.write(`Output: ${out}\n`);