diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-15 02:32:04 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-15 02:32:04 -0500 |
| commit | 2f06d6e98f3b2d8ae9f8506262f59f0249770e34 (patch) | |
| tree | ed243b71e46ee0b1d5ce127813c589b8088c3c1f /modules/org-roam-config.el | |
| parent | 1e59e346ab7e15c07e3b176cefaa92dbadb53c27 (diff) | |
| download | dotemacs-2f06d6e98f3b2d8ae9f8506262f59f0249770e34.tar.gz dotemacs-2f06d6e98f3b2d8ae9f8506262f59f0249770e34.zip | |
refactor(org-roam-config): indirect node-tags accessor for testability
`cj/org-roam-filter-by-tag' called `org-roam-node-tags' directly.
That accessor is generated by `cl-defstruct' and ships with a
compiler-macro that inlines the call to an `aref' against the
`cl-struct-org-roam-node-tags' tag variable at byte-compile time.
In tests, `cl-letf' on `(symbol-function 'org-roam-node-tags)' sets
the function cell but the byte-compiled call site never consults it
-- it executes the inlined `aref' instead. When org-roam isn't
loaded (legitimate for a tag-filter unit test), the inlined code
fails with `void-variable cl-struct-org-roam-node-tags'.
Wrap the accessor in `cj/--org-roam-node-tags' that calls through
`funcall' with a quoted symbol. Quoted symbols skip the
compiler-macro (which only fires on direct call forms), so the
funcall resolves the function cell at runtime and picks up the
test's `cl-letf' stub. Production behavior is unchanged; tests
no longer need org-roam loaded.
Diffstat (limited to 'modules/org-roam-config.el')
| -rw-r--r-- | modules/org-roam-config.el | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/modules/org-roam-config.el b/modules/org-roam-config.el index 52c41127..d0851ee4 100644 --- a/modules/org-roam-config.el +++ b/modules/org-roam-config.el @@ -103,10 +103,22 @@ the arguments that org-roam-node-insert expects." ;; ------------------------- Tag Listing And Filtering ------------------------- +(defun cj/--org-roam-node-tags (node) + "Return NODE's tag list. + +Thin indirection over `org-roam-node-tags'. The accessor is generated +by `cl-defstruct' and ships with a compiler-macro that inlines call +sites into an `aref' against `cl-struct-org-roam-node-tags' at +byte-compile time. Plain `(org-roam-node-tags node)' here would +also be inlined, defeating `cl-letf' stubs in tests. Using +`funcall' with a quoted symbol skips the compiler-macro and forces +runtime function-cell resolution, so the test stub fires." + (funcall 'org-roam-node-tags node)) + (defun cj/org-roam-filter-by-tag (tag-name) "Return a predicate function that filters org-roam nodes by TAG-NAME." (lambda (node) - (member tag-name (org-roam-node-tags node)))) + (member tag-name (cj/--org-roam-node-tags node)))) (defun cj/org-roam-list-notes-by-tag (tag-name) "Return a list of file paths for all org-roam nodes tagged with TAG-NAME." |
