From 58ef63abd5a9187ee93609f142cb21a933da16c5 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 26 Feb 2026 17:08:19 -0600 Subject: feat(recording): validate system audio device before recording Add pre-recording validation that catches stale or drifted system audio devices before they cause silent recordings. When the default audio output changes (Bluetooth reconnect, device switch) between setup and recording, the monitor device is auto-updated. Warns if no audio is currently playing through the monitored sink. Co-Authored-By: Craig Jennings --- .../test-video-audio-recording--source-exists-p.el | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/test-video-audio-recording--source-exists-p.el (limited to 'tests/test-video-audio-recording--source-exists-p.el') diff --git a/tests/test-video-audio-recording--source-exists-p.el b/tests/test-video-audio-recording--source-exists-p.el new file mode 100644 index 00000000..f062ac0f --- /dev/null +++ b/tests/test-video-audio-recording--source-exists-p.el @@ -0,0 +1,67 @@ +;;; test-video-audio-recording--source-exists-p.el --- Tests for cj/recording--source-exists-p -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests for cj/recording--source-exists-p function. +;; Tests checking whether a PulseAudio source exists in pactl output. + +;;; Code: + +(require 'ert) + +;; Stub dependencies before loading the module +(defvar cj/custom-keymap (make-sparse-keymap) + "Stub keymap for testing.") + +(require 'video-audio-recording) + +;;; Test Fixtures Helper + +(defun test-load-fixture (filename) + "Load fixture file FILENAME from tests/fixtures directory." + (let ((fixture-path (expand-file-name + (concat "tests/fixtures/" filename) + user-emacs-directory))) + (with-temp-buffer + (insert-file-contents fixture-path) + (buffer-string)))) + +;;; Normal Cases + +(ert-deftest test-source-exists-p-normal-existing-device-returns-t () + "Test that an existing device returns non-nil." + (let ((output (test-load-fixture "pactl-output-normal.txt"))) + (should (cj/recording--source-exists-p + "alsa_output.pci-0000_00_1f.3.analog-stereo.monitor" output)))) + +(ert-deftest test-source-exists-p-normal-input-device-returns-t () + "Test that an existing input device returns non-nil." + (let ((output (test-load-fixture "pactl-output-normal.txt"))) + (should (cj/recording--source-exists-p + "alsa_input.pci-0000_00_1f.3.analog-stereo" output)))) + +(ert-deftest test-source-exists-p-normal-bluetooth-device-returns-t () + "Test that a Bluetooth device returns non-nil." + (let ((output (test-load-fixture "pactl-output-normal.txt"))) + (should (cj/recording--source-exists-p + "bluez_input.00:1B:66:C0:91:6D" output)))) + +;;; Boundary Cases + +(ert-deftest test-source-exists-p-boundary-nonexistent-device-returns-nil () + "Test that a non-existent device returns nil." + (let ((output (test-load-fixture "pactl-output-normal.txt"))) + (should-not (cj/recording--source-exists-p + "nonexistent_device.monitor" output)))) + +(ert-deftest test-source-exists-p-boundary-empty-output-returns-nil () + "Test that empty pactl output returns nil." + (should-not (cj/recording--source-exists-p "any-device" ""))) + +(ert-deftest test-source-exists-p-boundary-partial-name-no-match () + "Test that partial device name does not match." + (let ((output (test-load-fixture "pactl-output-normal.txt"))) + (should-not (cj/recording--source-exists-p + "alsa_output.pci-0000_00_1f.3.analog-stereo" output)))) + +(provide 'test-video-audio-recording--source-exists-p) +;;; test-video-audio-recording--source-exists-p.el ends here -- cgit v1.2.3