From e958410cbc14d2bfa0f97890aafe38031e082aa7 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 11 May 2026 17:17:53 -0500 Subject: fix(calendar-sync): give the no-init .ics worker its module load-path The async .ics-to-Org worker runs `emacs --batch --no-site-file --no-site-lisp' and loads `calendar-sync.el' by absolute path, but that doesn't make its sibling `(require 'cj-org-text-lib)' resolvable, so the conversion died with "Cannot open load file: cj-org-text-lib". `calendar-sync--worker-command' now inserts `-L ' before `-l calendar-sync.el', which keeps the worker isolated from `init.el' while letting it load its local module deps. Updated the worker-command test and added a regression test that runs the real no-init worker shape. --- modules/calendar-sync.el | 4 +++- tests/test-calendar-sync-async-worker.el | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/calendar-sync.el b/modules/calendar-sync.el index 74b2e5c6..62d1b5f1 100644 --- a/modules/calendar-sync.el +++ b/modules/calendar-sync.el @@ -1282,7 +1282,8 @@ processes, not direct interactive use." (defun calendar-sync--worker-command (ics-file output-file) "Build the batch Emacs command that converts ICS-FILE to OUTPUT-FILE." - (let ((private-config-file + (let ((module-dir (file-name-directory calendar-sync--module-file)) + (private-config-file (make-temp-name (expand-file-name "calendar-sync-worker-config-" temporary-file-directory))) (state-file @@ -1294,6 +1295,7 @@ processes, not direct interactive use." "--no-site-lisp" "--eval" (format "(setq load-prefer-newer t calendar-sync-auto-start nil calendar-sync-private-config-file %S calendar-sync--state-file %S)" private-config-file state-file) + "-L" module-dir "-l" calendar-sync--module-file "--eval" (format "(calendar-sync--batch-convert-file %S %S %S %S '%S)" ics-file diff --git a/tests/test-calendar-sync-async-worker.el b/tests/test-calendar-sync-async-worker.el index d5982d32..6701df85 100644 --- a/tests/test-calendar-sync-async-worker.el +++ b/tests/test-calendar-sync-async-worker.el @@ -21,6 +21,8 @@ (should (member "--batch" command)) (should (member "--no-site-file" command)) (should (member "--no-site-lisp" command)) + (should (member "-L" command)) + (should (member "/tmp/" command)) (should (member "-l" command)) (should (member "/tmp/calendar-sync.el" command)) (should (cl-some (lambda (arg) @@ -35,6 +37,27 @@ (string-match-p "'(\"me@example\\.test\")" arg))) command)))) +(ert-deftest test-calendar-sync--worker-command-loads-sibling-modules-without-init () + "The worker command should load calendar-sync and sibling modules without init." + (let* ((calendar-sync--module-file + (expand-file-name "modules/calendar-sync.el" user-emacs-directory)) + (command (append + (calendar-sync--worker-command "/tmp/input.ics" "/tmp/output.org") + (list "--eval" "(princ \"loaded\")")))) + ;; Replace the conversion eval with a harmless smoke expression so this + ;; test exercises load-path setup without requiring temp ICS input. + (setq command + (cl-loop for arg in command + collect (if (and (stringp arg) + (string-match-p "calendar-sync--batch-convert-file" arg)) + "(princ \"\")" + arg))) + (with-temp-buffer + (let ((exit-code (apply #'call-process + (car command) nil t nil (cdr command)))) + (should (= 0 exit-code)) + (should (string-match-p "loaded" (buffer-string))))))) + (ert-deftest test-calendar-sync--batch-convert-file-writes-org-output () "The worker entry point should convert an ICS file and write Org output." (let* ((input-file (make-temp-file "calendar-sync-worker-" nil ".ics")) -- cgit v1.2.3