From f867f50d1675d5f9a251f7b5a2633d2eac3f0de7 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 25 May 2026 17:51:17 -0500 Subject: fix(org): guard external-tool assumptions in export and publishing commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four export/publishing commands shelled out to external tools without checking they exist, so a missing tool surfaced as an opaque process error — or, for reveal.js, a silently broken presentation. I added a command-time guard to each that names the tool and what's needed: - zathura, in the pandoc PDF export-and-open command - the hugo binary and the platform file-manager opener, in hugo-config - the local reveal.js checkout (run scripts/setup-reveal.sh), shared by the reveal export and preview commands - pandoc, in the web-clip protocol handler The checks run only when the command runs, so startup stays quiet. Each guard has a test asserting the user-error fires when the tool is absent, and the existing happy-path tests now stub the lookups so they exercise the real path rather than tripping the new guard. --- tests/test-org-export-config-pdf-open-guard.el | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/test-org-export-config-pdf-open-guard.el (limited to 'tests/test-org-export-config-pdf-open-guard.el') diff --git a/tests/test-org-export-config-pdf-open-guard.el b/tests/test-org-export-config-pdf-open-guard.el new file mode 100644 index 00000000..8d798871 --- /dev/null +++ b/tests/test-org-export-config-pdf-open-guard.el @@ -0,0 +1,45 @@ +;;; test-org-export-config-pdf-open-guard.el --- zathura open guard test -*- lexical-binding: t; -*- + +;;; Commentary: +;; `my/org-pandoc-export-to-pdf-and-open' opens the exported PDF with zathura +;; via `start-process'. Without zathura on PATH that call fails with an opaque +;; error. These tests pin the command-time guard: a missing zathura signals a +;; `user-error' naming the tool, and a present zathura lets the open proceed. +;; Requiring the module then ox fires the deferred ox-pandoc :config in batch, +;; which is where the function is defined. + +;;; Code: + +;; Initialize package system for batch mode so elpa packages (ox-pandoc) load. +(when noninteractive + (package-initialize)) + +(require 'ert) +(require 'cl-lib) +(require 'org) +(require 'org-export-config) +(require 'ox) +;; The function under test lives in ox-pandoc's :config block. In batch the +;; deferred :after-ox config does not fire on a bare module load, so require +;; ox-pandoc directly to ensure the function is defined. +(require 'ox-pandoc) + +(ert-deftest test-org-export-config-pdf-open-missing-zathura-errors () + "Error: missing zathura signals a user-error before opening the PDF." + (cl-letf (((symbol-function 'executable-find) (lambda (&rest _) nil))) + (should-error (my/org-pandoc-export-to-pdf-and-open) :type 'user-error))) + +(ert-deftest test-org-export-config-pdf-open-present-zathura-proceeds () + "Normal: with zathura present, the open step runs without error." + (let ((started nil)) + (cl-letf (((symbol-function 'executable-find) + (lambda (cmd &rest _) (if (equal cmd "zathura") "/usr/bin/zathura" nil))) + ((symbol-function 'org-pandoc-export-to-latex-pdf) + (lambda (&rest _) "/tmp/out.pdf")) + ((symbol-function 'start-process) + (lambda (&rest _) (setq started t) 'fake-process))) + (my/org-pandoc-export-to-pdf-and-open) + (should started)))) + +(provide 'test-org-export-config-pdf-open-guard) +;;; test-org-export-config-pdf-open-guard.el ends here -- cgit v1.2.3