New files, no local counterpart, taken verbatim from upstream:
qwan/org-roam-export-blog.el org-roam note -> firehose draft / jekyll draft
qwan/org-roam-export-blog-test.el 364-line ERT suite for the above
qwan/test-fixtures/vault/ vault fixture (notes + .attach tree)
mostalive/{my-org-roam,convert-chats-to-org,journelly-convert-entry-to-org-roam}.el
config-local.example.el template for gitignored config-local.el
elfeed.org, mise.toml feed list; node 24 pin (2ad9dfd)
Not imported, deliberately:
qwan/qwan-markdown-dnd.el earlier, cruder prototype of the same idea as
our firehose-blog.el: copies dropped files to a
cwd-relative dir, overwrites on name clash,
no year dirs, no tests, and evaluates an
ert-deftest at load time (upstream had to
disable it in 7153a24/e1d2415). Installing it
alongside firehose-blog.el would put two
handlers in dnd-protocol-alist for markdown
buffers. Ours supersedes it.
.devcontainer/, run-container.sh, coe-xx/, .pi/, CLAUDE.md, investigation.md
container/game-and-watch/agent scaffolding
README.org, AGENTS.md upstream's docs; ours are doom-specific
Nothing is wired up yet -- these files are inert until the next commit
requires them. Note that mostalive/my-org-roam.el shadows the `my-org-roam'
we currently load from ~/dev/emacs/org-roaming, so do not put mostalive/ on
the load-path without deciding which one wins.
365 lines
16 KiB
EmacsLisp
365 lines
16 KiB
EmacsLisp
;;; org-roam-export-blog-test.el --- ERT tests for org-roam-export-blog -*- lexical-binding: t; -*-
|
|
|
|
;;; Commentary:
|
|
|
|
;; Run with:
|
|
;; emacs --batch -Q -l org -l ox-md -L ~/.doom.d/qwan \
|
|
;; -l org-roam-export-blog.el -l org-roam-export-blog-test.el \
|
|
;; -f ert-run-tests-batch-and-exit
|
|
;;
|
|
;; Tests use a fixture vault under test-fixtures/vault and write output into
|
|
;; throw-away firehose/jekyll repo skeletons under /tmp.
|
|
|
|
;;; Code:
|
|
|
|
(require 'ert)
|
|
(require 'org-roam-export-blog)
|
|
|
|
(defconst roeb-test-dir
|
|
(directory-file-name (file-name-directory (or load-file-name default-directory))))
|
|
|
|
(defconst roeb-test-vault (expand-file-name "test-fixtures/vault" roeb-test-dir))
|
|
|
|
(defun roeb-test--file (name)
|
|
"Path to fixture file NAME in the test vault."
|
|
(expand-file-name name roeb-test-vault))
|
|
|
|
(defun roeb-test--new-firehose-root ()
|
|
"Create a throw-away firehose repo skeleton and return its root."
|
|
(let ((root (make-temp-file "/tmp/roeb-firehose-" t)))
|
|
(make-directory (expand-file-name "app/priv/blog/engineering" root) t)
|
|
(make-directory (expand-file-name "app/priv/static/images/blog" root) t)
|
|
root))
|
|
|
|
(defun roeb-test--new-jekyll-root ()
|
|
"Create a throw-away jekyll site skeleton and return its root."
|
|
(let ((root (make-temp-file "/tmp/roeb-jekyll-" t)))
|
|
(make-directory (expand-file-name "_drafts" root) t)
|
|
(make-directory (expand-file-name "attachments/blogposts" root) t)
|
|
root))
|
|
|
|
(defun roeb-test--setup-org-id ()
|
|
"Point org-id at a writable temp locations file and index the fixture vault."
|
|
(setq org-id-locations-file (make-temp-file "/tmp/roeb-orgid-"))
|
|
(setq org-id-locations nil)
|
|
(org-id-update-id-locations
|
|
(mapcar #'roeb-test--file '("note.org" "jev.org" "laya.org" "notitle.org")) t))
|
|
|
|
(defmacro roeb-test--with-export (firehose-root jekyll-root &rest body)
|
|
"Run BODY with the given roots and a pinned export date."
|
|
(declare (indent 2))
|
|
`(progn
|
|
(roeb-test--setup-org-id)
|
|
(let ((org-roam-export-blog-firehose-root ,firehose-root)
|
|
(org-roam-export-jekyll-root ,jekyll-root)
|
|
(org-roam-export-blog--current-date '("2026" "10" "08")))
|
|
,@body)))
|
|
|
|
(defun roeb-test--filetags-of (filetags-line)
|
|
"Write a one-keyword org file to /tmp and return its parsed filetags."
|
|
(let ((file (make-temp-file "roeb-filetags-" nil ".org")))
|
|
(unwind-protect
|
|
(progn
|
|
(with-temp-file file
|
|
(insert "#+title: T\n" (or filetags-line "") "\n"))
|
|
(org-roam-export-blog--filetags (find-file-noselect file)))
|
|
(delete-file file))))
|
|
|
|
;;; Pure helpers
|
|
|
|
(ert-deftest org-roam-export-blog/slug ()
|
|
(should (equal "will-it-blend" (org-roam-export-blog--slug "Will It Blend")))
|
|
(should (equal "improve-diagnostic-in-the-tdd-cycle"
|
|
(org-roam-export-blog--slug "Improve Diagnostic in the TDD cycle")))
|
|
(should (equal "v0-2-0-rss-subscribe-links"
|
|
(org-roam-export-blog--slug "v0.2.0 — RSS Subscribe Links"))))
|
|
|
|
(ert-deftest org-roam-export-blog/truncate-description-short ()
|
|
(should (equal "Short paragraph."
|
|
(org-roam-export-blog--truncate-description "Short paragraph."))))
|
|
|
|
(ert-deftest org-roam-export-blog/truncate-description-at-word-boundary ()
|
|
(let* ((words (make-list 60 "word"))
|
|
(text (string-join words " "))
|
|
(result (org-roam-export-blog--truncate-description text)))
|
|
(should (<= (length result) (+ org-roam-export-blog-description-length 1)))
|
|
(should (string-suffix-p "…" result))
|
|
(should-not (string-suffix-p " " result))
|
|
(should (string-prefix-p "word word" result))))
|
|
|
|
;;; Filetags
|
|
|
|
(ert-deftest org-roam-export-blog/filetags-colon-syntax ()
|
|
(should (equal '("writing" "blender")
|
|
(roeb-test--filetags-of "#+filetags: :writing:blender:"))))
|
|
|
|
(ert-deftest org-roam-export-blog/filetags-bracket-syntax ()
|
|
(should (equal '("writing" "blender")
|
|
(roeb-test--filetags-of "#+filetags: [writing blender]"))))
|
|
|
|
(ert-deftest org-roam-export-blog/filetags-absent ()
|
|
(should (null (roeb-test--filetags-of nil))))
|
|
|
|
;;; Targets and configuration
|
|
|
|
(ert-deftest org-roam-export-blog/firehose-target-requires-root ()
|
|
(let ((org-roam-export-blog-firehose-root nil))
|
|
(should-error (org-roam-export-blog--firehose-target) :type 'user-error)))
|
|
|
|
(ert-deftest org-roam-export-blog/jekyll-target-requires-root ()
|
|
(let ((org-roam-export-jekyll-root nil))
|
|
(should-error (org-roam-export-blog--jekyll-target) :type 'user-error)))
|
|
|
|
(ert-deftest org-roam-export-blog/target-requires-existing-root ()
|
|
"A configured but absent root must fail loudly, not create a stray tree."
|
|
(let ((org-roam-export-blog-firehose-root "/tmp/roeb-does-not-exist"))
|
|
(should-error (org-roam-export-blog--firehose-target) :type 'user-error)))
|
|
|
|
;;; Roam ref resolution
|
|
|
|
(ert-deftest org-roam-export-blog/roam-refs ()
|
|
(roeb-test--setup-org-id)
|
|
(should (equal "https://example.com/jev"
|
|
(org-roam-export-blog--roam-refs (roeb-test--file "jev.org"))))
|
|
(should (null (org-roam-export-blog--roam-refs (roeb-test--file "laya.org")))))
|
|
|
|
;;; Aborts
|
|
|
|
(ert-deftest org-roam-export-blog/no-title-aborts ()
|
|
(let ((root (roeb-test--new-firehose-root)))
|
|
(roeb-test--with-export root nil
|
|
(should-error (org-roam-export-blog--export-file
|
|
(org-roam-export-blog--firehose-target)
|
|
(roeb-test--file "notitle.org"))
|
|
:type 'user-error)
|
|
;; Aborting must not have written any posts.
|
|
(should (null
|
|
(directory-files-recursively
|
|
(expand-file-name "app/priv/blog" root) "\\.md$"))))))
|
|
|
|
(ert-deftest org-roam-export-blog/filename-collision-aborts ()
|
|
(let ((root (roeb-test--new-firehose-root)))
|
|
(roeb-test--with-export root nil
|
|
;; Pre-create the exact target file.
|
|
(make-directory
|
|
(expand-file-name "app/priv/blog/engineering/2026" root) t)
|
|
(write-region "" nil
|
|
(expand-file-name
|
|
"app/priv/blog/engineering/2026/10-08-will-it-blend.md" root))
|
|
(should-error (org-roam-export-blog--export-file
|
|
(org-roam-export-blog--firehose-target)
|
|
(roeb-test--file "note.org"))
|
|
:type 'user-error)
|
|
;; Aborting must not have copied any images (no side effects).
|
|
(should (null
|
|
(directory-files-recursively
|
|
(expand-file-name "app/priv/static/images/blog" root)
|
|
"."))))))
|
|
|
|
(ert-deftest org-roam-export-blog/jekyll-filename-collision-aborts ()
|
|
(let ((root (roeb-test--new-jekyll-root)))
|
|
(roeb-test--with-export nil root
|
|
;; Pre-create the exact target file.
|
|
(write-region "" nil
|
|
(expand-file-name "_drafts/will-it-blend.md" root))
|
|
(should-error (org-roam-export-blog--export-file
|
|
(org-roam-export-blog--jekyll-target)
|
|
(roeb-test--file "note.org"))
|
|
:type 'user-error)
|
|
;; Aborting must not have copied any images (no side effects).
|
|
(should (null
|
|
(directory-files-recursively
|
|
(expand-file-name "attachments" root)
|
|
"."))))))
|
|
|
|
;;; Full export: firehose
|
|
|
|
(ert-deftest org-roam-export-blog/end-to-end ()
|
|
(let ((root (roeb-test--new-firehose-root))
|
|
result path body)
|
|
(roeb-test--with-export root nil
|
|
(setq result (org-roam-export-blog--export-file
|
|
(org-roam-export-blog--firehose-target)
|
|
(roeb-test--file "note.org"))))
|
|
(setq path (car result))
|
|
;; Written at the agreed path.
|
|
(should (equal (expand-file-name
|
|
"app/priv/blog/engineering/2026/10-08-will-it-blend.md" root)
|
|
path))
|
|
(should (file-exists-p path))
|
|
;; Image attachment copied into static images with unchanged content.
|
|
(let ((image (expand-file-name "app/priv/static/images/blog/2026/will-it-blend.svg" root)))
|
|
(should (file-exists-p image))
|
|
(should (equal (with-temp-buffer (insert-file-contents image) (buffer-string))
|
|
(with-temp-buffer
|
|
(insert-file-contents (roeb-test--file ".attach/00/000000-0000-0000-0000-000000000001/will-it-blend.svg"))
|
|
(buffer-string)))))
|
|
(setq body (with-temp-buffer (insert-file-contents path) (buffer-string)))
|
|
;; Frontmatter.
|
|
(should (string-match-p "title: \"Will It Blend\"" body))
|
|
(should (string-match-p "author: \"Willem van den Ende\"" body))
|
|
(should (string-match-p "tags: ~w()" body))
|
|
(should (string-match-p
|
|
"description: \"Will it Blend was a series of videos promoting a blender brand.\""
|
|
body))
|
|
(should (string-match-p "image: \"/images/blog/2026/will-it-blend.svg\"" body))
|
|
(should (string-match-p "published: false" body))
|
|
;; Markdown body.
|
|
(should (string-match-p "Will it Blend was a series of videos promoting a blender brand." body))
|
|
(should (string-match-p
|
|
(regexp-quote "")
|
|
body))
|
|
(should (string-match-p (regexp-quote "[Jev](https://example.com/jev)") body))
|
|
(should (string-match-p "Laya popped up" body))
|
|
(should (string-match-p "a missing note vanished" body))
|
|
(should (string-match-p "TODO source needed (LinkedIn)" body))
|
|
(should (string-match-p "^## I learnt this from Julia$" body))
|
|
(should (string-match-p "^> A quoted comment.$" body))
|
|
(should (string-match-p "^```elixir$" body))
|
|
(should (string-match-p (regexp-quote "**bold**") body))
|
|
;; Org syntax must not leak into the markdown.
|
|
(should-not (string-match-p "#\\+begin" body))
|
|
(should-not (string-match-p "attachment:" body))
|
|
(should-not (string-match-p "id:0000" body))
|
|
(should-not (string-match-p "A private comment that must not be exported" body))
|
|
;; Warnings: dangling ref, ref without ROAM_REFS, ignored non-image
|
|
;; attachment.
|
|
(should (= 3 (length (cdr result))))
|
|
(should (cl-some (lambda (w) (string-match-p "00000000-0000-0000-0000-000000009999" w))
|
|
(cdr result)))
|
|
(should (cl-some (lambda (w) (string-match-p "00000000-0000-0000-0000-000000000003" w))
|
|
(cdr result)))
|
|
(should (cl-some (lambda (w) (string-match-p "attached-notes.txt" w))
|
|
(cdr result)))))
|
|
|
|
(ert-deftest org-roam-export-blog/description-truncated-in-frontmatter ()
|
|
(let* ((root (roeb-test--new-firehose-root))
|
|
(vault (make-temp-file "/tmp/roeb-vault-" t))
|
|
(note (expand-file-name "longpar.org" vault))
|
|
(long-text (string-join (make-list 50 "lorem" ) " ")))
|
|
(with-temp-file note
|
|
(insert ":PROPERTIES:\n:ID: 00000000-0000-0000-0000-000000000005\n:END:\n"
|
|
"#+title: Long Paragraph\n\n" long-text "\n"))
|
|
(roeb-test--with-export root nil
|
|
(let ((result (org-roam-export-blog--export-file
|
|
(org-roam-export-blog--firehose-target) note)))
|
|
(let ((body (with-temp-buffer
|
|
(insert-file-contents (car result))
|
|
(buffer-string))))
|
|
(string-match "description: \"\\([^\"]*\\)\"" body)
|
|
(let ((desc (match-string 1 body)))
|
|
(should (<= (length desc) (+ org-roam-export-blog-description-length 1)))
|
|
(should (string-suffix-p "…" desc))
|
|
(should (string-prefix-p "lorem lorem" desc))))))))
|
|
|
|
(ert-deftest org-roam-export-blog/elixir-frontmatter-escapes-quotes-once ()
|
|
"Quotes in title/description must produce valid Elixir string literals.
|
|
|
|
Regression test: the old escape-then-%S combination double-escaped,
|
|
so a title containing a quote mark came out with literal
|
|
backslash-quote sequences in the exported post."
|
|
(let* ((root (roeb-test--new-firehose-root))
|
|
(vault (make-temp-file "/tmp/roeb-vault-" t))
|
|
(note (expand-file-name "quoted.org" vault)))
|
|
(with-temp-file note
|
|
(insert ":PROPERTIES:\n:ID: 00000000-0000-0000-0000-000000000007\n:END:\n"
|
|
"#+title: Say \"hi\"\n\n"
|
|
"A \"quoted\" remark.\n"))
|
|
(roeb-test--with-export root nil
|
|
(let* ((result (org-roam-export-blog--export-file
|
|
(org-roam-export-blog--firehose-target) note))
|
|
(body (with-temp-buffer
|
|
(insert-file-contents (car result))
|
|
(buffer-string))))
|
|
(should (string-match-p (regexp-quote "title: \"Say \\\"hi\\\"\",") body))
|
|
(should (string-match-p (regexp-quote
|
|
"description: \"A \\\"quoted\\\" remark.\",")
|
|
body))))))
|
|
|
|
;;; Full export: jekyll
|
|
|
|
(ert-deftest org-roam-export-blog/jekyll-end-to-end ()
|
|
(let ((root (roeb-test--new-jekyll-root))
|
|
result path body)
|
|
(roeb-test--with-export nil root
|
|
(setq result (org-roam-export-blog--export-file
|
|
(org-roam-export-blog--jekyll-target)
|
|
(roeb-test--file "note.org"))))
|
|
(setq path (car result))
|
|
;; Drafts live in _drafts, without a date prefix.
|
|
(should (equal (expand-file-name "_drafts/will-it-blend.md" root) path))
|
|
(should (file-exists-p path))
|
|
;; Image attachment copied into the site's attachments tree.
|
|
(let ((image (expand-file-name "attachments/blogposts/2026/will-it-blend.svg" root)))
|
|
(should (file-exists-p image))
|
|
(should (equal (with-temp-buffer (insert-file-contents image) (buffer-string))
|
|
(with-temp-buffer
|
|
(insert-file-contents (roeb-test--file ".attach/00/000000-0000-0000-0000-000000000001/will-it-blend.svg"))
|
|
(buffer-string)))))
|
|
(setq body (with-temp-buffer (insert-file-contents path) (buffer-string)))
|
|
;; YAML frontmatter, tags from #+filetags:.
|
|
(should (string-match-p "^---$" body))
|
|
(should (string-match-p "^layout: post$" body))
|
|
(should (string-match-p "^title: \"Will It Blend\"$" body))
|
|
(should (string-match-p "^tags:$" body))
|
|
(should (string-match-p "^ - writing$" body))
|
|
(should (string-match-p "^ - blender$" body))
|
|
(should (string-match-p "^author: \"Willem van den Ende\"$" body))
|
|
(should (string-match-p "^image: /attachments/blogposts/2026/will-it-blend.svg$" body))
|
|
;; Jekyll posts carry no description key.
|
|
(should-not (string-match-p "description:" body))
|
|
;; Markdown body.
|
|
(should (string-match-p
|
|
(regexp-quote "")
|
|
body))
|
|
(should (string-match-p (regexp-quote "[Jev](https://example.com/jev)") body))
|
|
(should (string-match-p "Laya popped up" body))
|
|
(should (string-match-p "^## I learnt this from Julia$" body))
|
|
(should (string-match-p "^```elixir$" body))
|
|
;; Org syntax must not leak into the markdown.
|
|
(should-not (string-match-p "#\\+begin" body))
|
|
(should-not (string-match-p "attachment:" body))
|
|
(should-not (string-match-p "id:0000" body))
|
|
;; Same warnings as the firehose target for the same note.
|
|
(should (= 3 (length (cdr result))))))
|
|
|
|
(ert-deftest org-roam-export-blog/jekyll-untagged-note-gets-empty-tags ()
|
|
(let* ((root (roeb-test--new-jekyll-root))
|
|
(vault (make-temp-file "/tmp/roeb-vault-" t))
|
|
(note (expand-file-name "untagged.org" vault)))
|
|
(with-temp-file note
|
|
(insert "#+title: Untagged Note\n\nFirst paragraph.\n"))
|
|
(roeb-test--with-export nil root
|
|
(let* ((result (org-roam-export-blog--export-file
|
|
(org-roam-export-blog--jekyll-target) note))
|
|
(body (with-temp-buffer
|
|
(insert-file-contents (car result))
|
|
(buffer-string))))
|
|
(should (string-match-p "^tags: \\[\\]$" body))
|
|
(should (string-match-p "^image: $" body))))))
|
|
|
|
(ert-deftest org-roam-export-blog/run-opens-the-generated-post ()
|
|
(let ((root (roeb-test--new-jekyll-root)))
|
|
(roeb-test--with-export nil root
|
|
(with-current-buffer (find-file-noselect (roeb-test--file "note.org"))
|
|
(org-roam-export-blog--run (org-roam-export-blog--jekyll-target)))
|
|
(should (get-file-buffer
|
|
(expand-file-name "_drafts/will-it-blend.md" root))))))
|
|
|
|
(ert-deftest org-roam-export-blog/jekyll-frontmatter-shape ()
|
|
(let ((org-roam-export-blog-author "Willem"))
|
|
(should (equal
|
|
(concat "---\n"
|
|
"layout: post\n"
|
|
"title: \"Say \\\"hi\\\"\"\n"
|
|
"tags:\n"
|
|
" - a\n"
|
|
" - b\n"
|
|
"author: \"Willem\"\n"
|
|
"image: \n"
|
|
"---\n")
|
|
(org-roam-export-blog--jekyll-frontmatter "Say \"hi\"" nil '("a" "b") nil)))))
|
|
|
|
(provide 'org-roam-export-blog-test)
|
|
;;; org-roam-export-blog-test.el ends here
|