smoke.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env node
  2. const fs = require('fs');
  3. const path = require('path');
  4. const { spawnSync } = require('child_process');
  5. const { pathToFileURL } = require('url');
  6. const ROOT = path.resolve(__dirname, '..');
  7. const SKILL_DIR = path.join(ROOT, 'skills', 'fmode-ffmpeg');
  8. const BIN = path.join(ROOT, 'bin', 'fmode-ffmpeg.js');
  9. function fail(msg) { console.error('SMOKE FAIL: ' + msg); process.exit(1); }
  10. const required = [
  11. 'SKILL.md',
  12. 'scripts/ffmpeg-runner.mjs'
  13. ];
  14. for (const rel of required) {
  15. if (!fs.existsSync(path.join(SKILL_DIR, rel))) fail('missing ' + rel);
  16. }
  17. (async () => {
  18. // 1. skill runner module exports
  19. const mod = await import(pathToFileURL(path.join(SKILL_DIR, 'scripts', 'ffmpeg-runner.mjs')).href);
  20. for (const fn of ['ffmpegPath', 'ffprobePath', 'runFfmpeg', 'probeMedia', 'probeDurationMs']) {
  21. if (typeof mod[fn] !== 'function') fail('export ' + fn + ' is not a function');
  22. }
  23. // 2. bundled ffmpeg binary resolves and runs
  24. const which = spawnSync(process.execPath, [BIN, 'which'], { encoding: 'utf8' });
  25. if (which.status !== 0) fail('`fmode-ffmpeg which` exited ' + which.status);
  26. const ffmpegBin = (which.stdout || '').trim();
  27. if (!ffmpegBin || !fs.existsSync(ffmpegBin)) fail('ffmpeg binary not resolved: ' + ffmpegBin);
  28. const version = spawnSync(ffmpegBin, ['-version'], { encoding: 'utf8' });
  29. if (version.status !== 0 || !/ffmpeg version/i.test(version.stdout || '')) {
  30. fail('ffmpeg -version did not run');
  31. }
  32. // 3. bundled ffprobe binary resolves
  33. const whichProbe = spawnSync(process.execPath, [BIN, 'which-ffprobe'], { encoding: 'utf8' });
  34. if (whichProbe.status !== 0) fail('`fmode-ffmpeg which-ffprobe` exited ' + whichProbe.status);
  35. const ffprobeBin = (whichProbe.stdout || '').trim();
  36. if (!ffprobeBin || !fs.existsSync(ffprobeBin)) fail('ffprobe binary not resolved: ' + ffprobeBin);
  37. const probeVersion = spawnSync(ffprobeBin, ['-version'], { encoding: 'utf8' });
  38. if (probeVersion.status !== 0 || !/ffprobe version/i.test(probeVersion.stdout || '')) {
  39. fail('ffprobe -version did not run');
  40. }
  41. console.log('SMOKE OK: fmode-ffmpeg structure + bundled ffmpeg/ffprobe verified');
  42. console.log(' ffmpeg : ' + ffmpegBin);
  43. console.log(' ffprobe: ' + ffprobeBin);
  44. })().catch(e => fail(e.message));