diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 04:04:59 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 04:04:59 -0500 |
| commit | 39795e850f2027a88021307a37de0381996df8a5 (patch) | |
| tree | 7b0c6a011ca25de0e0a42303008db3c41aa8bb85 /tests | |
| parent | 746e770ade412c8e7992b2a98441aebde000db3c (diff) | |
| download | dotemacs-39795e850f2027a88021307a37de0381996df8a5.tar.gz dotemacs-39795e850f2027a88021307a37de0381996df8a5.zip | |
fix(recording): shell-quote device names and output paths in ffmpeg commands
The X11 video path and the audio path interpolated the mic device, system device, and output filename straight into the shell command, so a device name or recording directory with a space (or other shell metacharacter) would break the command or mishandle the path. The Wayland video branch already quoted these; the other two did not.
I wrapped all three in shell-quote-argument on both paths. To make the audio command testable, I extracted it into cj/recording--build-audio-command mirroring the existing cj/recording--build-video-command, then quoted there. Tests cover device names and filenames with spaces on both the X11 and audio builders.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-video-audio-recording--build-audio-command.el | 76 | ||||
| -rw-r--r-- | tests/test-video-audio-recording--build-video-command.el | 16 |
2 files changed, 92 insertions, 0 deletions
diff --git a/tests/test-video-audio-recording--build-audio-command.el b/tests/test-video-audio-recording--build-audio-command.el new file mode 100644 index 00000000..54e5f56c --- /dev/null +++ b/tests/test-video-audio-recording--build-audio-command.el @@ -0,0 +1,76 @@ +;;; test-video-audio-recording--build-audio-command.el --- Tests for audio command builder -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests for cj/recording--build-audio-command. +;; Verifies correct ffmpeg command construction for audio-only recording +;; (mic + system monitor mixed to M4A/AAC), including shell quoting of +;; device names and output paths. + +;;; Code: + +(require 'ert) + +;; Stub dependencies before loading the module +(defvar cj/custom-keymap (make-sparse-keymap) + "Stub keymap for testing.") + +(require 'video-audio-recording) + +;;; Normal Cases + +(ert-deftest test-video-audio-recording--build-audio-command-normal-uses-ffmpeg-pulse () + "Normal: audio command uses ffmpeg with two PulseAudio inputs mixed to AAC." + (let ((cj/recording-mic-boost 2.0) + (cj/recording-system-volume 1.0)) + (let ((cmd (cj/recording--build-audio-command "mic" "sys" "/tmp/out.m4a"))) + (should (string-match-p "ffmpeg" cmd)) + (should (string-match-p "-f pulse -i" cmd)) + (should (string-match-p "amix=inputs=2" cmd)) + (should (string-match-p "-c:a aac" cmd))))) + +(ert-deftest test-video-audio-recording--build-audio-command-normal-devices-in-command () + "Normal: both mic and system device names appear in the command." + (let ((cj/recording-mic-boost 1.0) + (cj/recording-system-volume 1.0)) + (let ((cmd (cj/recording--build-audio-command + "alsa_input.usb-Jabra-00.mono" + "alsa_output.usb-JDS-00.monitor" + "/tmp/out.m4a"))) + (should (string-match-p "alsa_input.usb-Jabra-00.mono" cmd)) + (should (string-match-p "alsa_output.usb-JDS-00.monitor" cmd))))) + +(ert-deftest test-video-audio-recording--build-audio-command-normal-volume-in-filter () + "Normal: volume settings appear in the filter_complex expression." + (let ((cj/recording-mic-boost 1.5) + (cj/recording-system-volume 0.7)) + (let ((cmd (cj/recording--build-audio-command "mic" "sys" "/tmp/out.m4a"))) + (should (string-match-p "volume=1\\.5" cmd)) + (should (string-match-p "volume=0\\.7" cmd))))) + +;;; Boundary Cases + +(ert-deftest test-video-audio-recording--build-audio-command-boundary-device-quoted () + "Boundary: device names with spaces are shell-quoted." + (let ((cj/recording-mic-boost 1.0) + (cj/recording-system-volume 1.0)) + (let ((cmd (cj/recording--build-audio-command + "device with spaces" "sys" "/tmp/out.m4a"))) + (should (string-match-p "device\\\\ with\\\\ spaces" cmd))))) + +(ert-deftest test-video-audio-recording--build-audio-command-boundary-filename-quoted () + "Boundary: output filename with spaces is shell-quoted." + (let ((cj/recording-mic-boost 1.0) + (cj/recording-system-volume 1.0)) + (let ((cmd (cj/recording--build-audio-command + "mic" "sys" "/tmp/my recording.m4a"))) + (should (string-match-p "my\\\\ recording\\.m4a" cmd))))) + +(ert-deftest test-video-audio-recording--build-audio-command-boundary-zero-volume () + "Boundary: zero volume values produce 0.0 in the command." + (let ((cj/recording-mic-boost 0.0) + (cj/recording-system-volume 0.0)) + (let ((cmd (cj/recording--build-audio-command "mic" "sys" "/tmp/out.m4a"))) + (should (string-match-p "volume=0\\.0" cmd))))) + +(provide 'test-video-audio-recording--build-audio-command) +;;; test-video-audio-recording--build-audio-command.el ends here diff --git a/tests/test-video-audio-recording--build-video-command.el b/tests/test-video-audio-recording--build-video-command.el index 7f54f053..3b79c9ec 100644 --- a/tests/test-video-audio-recording--build-video-command.el +++ b/tests/test-video-audio-recording--build-video-command.el @@ -76,6 +76,22 @@ ;; Filename should be quoted/escaped (should (string-match-p "recording" cmd)))))) +(ert-deftest test-video-audio-recording--build-video-command-boundary-x11-device-quoted () + "Boundary: X11 device names with spaces are shell-quoted." + (let ((cj/recording-mic-boost 1.0) + (cj/recording-system-volume 1.0)) + (let ((cmd (cj/recording--build-video-command + "device with spaces" "sys" "/tmp/out.mkv" nil))) + (should (string-match-p "device\\\\ with\\\\ spaces" cmd))))) + +(ert-deftest test-video-audio-recording--build-video-command-boundary-x11-filename-quoted () + "Boundary: X11 output filename with spaces is shell-quoted." + (let ((cj/recording-mic-boost 1.0) + (cj/recording-system-volume 1.0)) + (let ((cmd (cj/recording--build-video-command + "mic" "sys" "/tmp/my recording.mkv" nil))) + (should (string-match-p "my\\\\ recording\\.mkv" cmd))))) + (ert-deftest test-video-audio-recording--build-video-command-boundary-zero-volume () "Zero volume values produce 0.0 in the command." (let ((cj/recording-mic-boost 0.0) |
