From 556f48a2a0518253015496a618eec9e7a7142dcc Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 24 May 2026 04:08:19 -0500 Subject: fix(recording): scope wf-recorder stop signal to our own process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stopping a Wayland recording ran pkill -INT wf-recorder, which signals every wf-recorder on the system — including an unrelated screen capture the user started outside Emacs. The stop path now scopes the producer-first interrupt to the wf-recorder child of our own recording shell via pkill -P , in the new cj/recording--interrupt-child-wf-recorder helper. The producer-first ordering is unchanged: wf-recorder still gets SIGINT before the process-group signal so ffmpeg sees a clean EOF on pipe:0 and finalizes the MKV. The orphan-cleanup at recording start stays a broad by-name kill on purpose — those leftover recorders come from crashed sessions whose shells are already dead, so there is no live PID to scope to. Tests cover the scoped call, the nil-PID no-op, and that the bare system-wide form is never used. --- ...audio-recording--interrupt-child-wf-recorder.el | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/test-video-audio-recording--interrupt-child-wf-recorder.el (limited to 'tests') diff --git a/tests/test-video-audio-recording--interrupt-child-wf-recorder.el b/tests/test-video-audio-recording--interrupt-child-wf-recorder.el new file mode 100644 index 00000000..6e4cda1c --- /dev/null +++ b/tests/test-video-audio-recording--interrupt-child-wf-recorder.el @@ -0,0 +1,56 @@ +;;; test-video-audio-recording--interrupt-child-wf-recorder.el --- Tests for scoped wf-recorder interrupt -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests for cj/recording--interrupt-child-wf-recorder. +;; Verifies the producer-first stop signal targets only the wf-recorder +;; child of this module's own shell process, not every wf-recorder on the +;; system. + +;;; 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--interrupt-child-wf-recorder-normal-scopes-to-parent-pid () + "Normal: interrupt is scoped to the wf-recorder child of the given PID." + (let ((captured nil)) + (cl-letf (((symbol-function 'call-process) + (lambda (&rest args) (setq captured args) 0))) + (cj/recording--interrupt-child-wf-recorder 12345) + ;; Targets wf-recorder, by parent PID, with SIGINT — not a bare + ;; system-wide name match. + (should (member "-INT" captured)) + (should (member "-P" captured)) + (should (member "12345" captured)) + (should (member "wf-recorder" captured))))) + +;;; Boundary Cases + +(ert-deftest test-video-audio-recording--interrupt-child-wf-recorder-boundary-nil-pid-no-call () + "Boundary: a nil PID issues no kill at all (nothing to scope to)." + (let ((called nil)) + (cl-letf (((symbol-function 'call-process) + (lambda (&rest _) (setq called t) 0))) + (cj/recording--interrupt-child-wf-recorder nil) + (should-not called)))) + +;;; Error Cases + +(ert-deftest test-video-audio-recording--interrupt-child-wf-recorder-error-never-bare-name () + "Error: must never call pkill with only the program name (system-wide kill)." + (let ((captured nil)) + (cl-letf (((symbol-function 'call-process) + (lambda (&rest args) (setq captured args) 0))) + (cj/recording--interrupt-child-wf-recorder 999) + ;; The whole point of the fix: a parent-scoping flag is always present. + (should (member "-P" captured))))) + +(provide 'test-video-audio-recording--interrupt-child-wf-recorder) +;;; test-video-audio-recording--interrupt-child-wf-recorder.el ends here -- cgit v1.2.3