From 995d5114429fe8d49c4a627857894070451e9d9d Mon Sep 17 00:00:00 2001 From: examples-bot Date: Sun, 29 Mar 2026 21:48:08 +0000 Subject: [PATCH] =?UTF-8?q?[Fix]=20020-twilio-media-streams=20=E2=80=94=20?= =?UTF-8?q?install=20ffmpeg=20when=20missing=20from=20CI=20runner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ubuntu-24.04 GitHub Actions runner image (20260323.65) no longer ships ffmpeg pre-installed. The test crashed with "Cannot read properties of null (reading 'toString')" because spawnSync returns { stderr: null, status: null } when the binary is not found (ENOENT), and the error handler assumed stderr was always a Buffer. - Add ensureFfmpeg() that installs ffmpeg via apt-get if not present - Guard against null result.error before checking result.status - Guard against null result.stderr in the error message 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../020-twilio-media-streams-node/tests/test.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/020-twilio-media-streams-node/tests/test.js b/examples/020-twilio-media-streams-node/tests/test.js index 49bf852..cdc4a9d 100644 --- a/examples/020-twilio-media-streams-node/tests/test.js +++ b/examples/020-twilio-media-streams-node/tests/test.js @@ -32,9 +32,16 @@ const TMP_MULAW = '/tmp/twilio_test.mulaw'; // We use 320 to match Twilio's actual observed frame size. const CHUNK_SIZE = 320; -// Convert a known audio file to μ-law 8 kHz using ffmpeg. -// ffmpeg is pre-installed on all GitHub Actions ubuntu runners. +function ensureFfmpeg() { + const check = spawnSync('ffmpeg', ['-version'], { stdio: 'pipe' }); + if (check.status === 0) return; + console.log('ffmpeg not found — installing via apt-get...'); + execSync('sudo apt-get update -qq && sudo apt-get install -y -qq ffmpeg', { stdio: 'pipe' }); +} + function prepareMulawAudio() { + ensureFfmpeg(); + console.log('Downloading test audio...'); execSync(`curl -s -L -o "${TMP_WAV}" "${AUDIO_URL}"`, { stdio: 'pipe' }); @@ -44,8 +51,11 @@ function prepareMulawAudio() { '-ar', '8000', '-ac', '1', '-f', 'mulaw', TMP_MULAW, ], { stdio: 'pipe' }); + if (result.error) { + throw new Error(`ffmpeg spawn error: ${result.error.message}`); + } if (result.status !== 0) { - throw new Error(`ffmpeg failed: ${result.stderr.toString().slice(0, 300)}`); + throw new Error(`ffmpeg failed: ${(result.stderr || Buffer.alloc(0)).toString().slice(0, 300)}`); } const audio = fs.readFileSync(TMP_MULAW);