Created
July 30, 2026 18:31
-
-
Save d12frosted/1e547f0ad1f978bfa5365a79f09ee234 to your computer and use it in GitHub Desktop.
Repro test for d12frosted/vulpea#427 (deleted properties/meta removed on sync)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; vulpea-issue-427-test.el --- Repro for issue #427 -*- lexical-binding: t; -*- | |
| ;; | |
| ;;; Commentary: | |
| ;; | |
| ;; Reproduction steps of https://github.com/d12frosted/vulpea/issues/427 | |
| ;; as an ERT test, going through the same code path autosync uses in | |
| ;; synchronous mode (`vulpea-db-sync--update-file-if-changed'). | |
| ;; | |
| ;; Self-contained on purpose (no project test helpers), so it can run | |
| ;; against older checkouts as well: drop it into test/ and run | |
| ;; | |
| ;; eldev test vulpea-issue-427-test.el | |
| ;; | |
| ;;; Code: | |
| (require 'ert) | |
| (require 'vulpea-db) | |
| (require 'vulpea-db-sync) | |
| (defun vulpea-issue-427--prop-rows (id) | |
| "Rows of the properties table for note ID." | |
| (emacsql (vulpea-db) | |
| [:select [key value] :from properties | |
| :where (= note-id $s1)] | |
| id)) | |
| (defun vulpea-issue-427--meta-rows (id) | |
| "Rows of the meta table for note ID." | |
| (emacsql (vulpea-db) | |
| [:select [key value] :from meta | |
| :where (= note-id $s1)] | |
| id)) | |
| (defun vulpea-issue-427--write (path &rest lines) | |
| "Write LINES to PATH and wait past filesystem timestamp granularity." | |
| (with-temp-file path | |
| (insert (mapconcat #'identity lines "\n") "\n")) | |
| (sleep-for 0.05)) | |
| (ert-deftest vulpea-issue-427/file-level-prop-and-meta-removed-on-sync () | |
| "Steps of #427 against a file-level note." | |
| (let* ((root (file-name-as-directory (make-temp-file "vulpea-427-" t))) | |
| (vulpea-db-location (make-temp-file "vulpea-427-" nil ".db")) | |
| (vulpea-db--connection nil) | |
| (path (expand-file-name "note.org" root)) | |
| (id "11111111-1111-1111-1111-111111110427")) | |
| (unwind-protect | |
| (progn | |
| (vulpea-db) | |
| ;; Step 1: new note with PROP 1 and `- metadata :: 2' | |
| (vulpea-issue-427--write | |
| path | |
| ":PROPERTIES:" | |
| (concat ":ID: " id) | |
| ":PROP: 1" | |
| ":END:" | |
| "#+title: Note" | |
| "" | |
| "- metadata :: 2") | |
| ;; Step 2: sync | |
| (should (eq t (vulpea-db-sync--update-file-if-changed path))) | |
| ;; Steps 4-5: DB has PROP=1 and metadata=2 | |
| (should (equal '("1") (cdr (assoc "PROP" (vulpea-issue-427--prop-rows id))))) | |
| (should (equal '("2") (cdr (assoc "metadata" (vulpea-issue-427--meta-rows id))))) | |
| ;; Step 6: change PROP to 3 and metadata to 4 | |
| (vulpea-issue-427--write | |
| path | |
| ":PROPERTIES:" | |
| (concat ":ID: " id) | |
| ":PROP: 3" | |
| ":END:" | |
| "#+title: Note" | |
| "" | |
| "- metadata :: 4") | |
| (should (eq t (vulpea-db-sync--update-file-if-changed path))) | |
| ;; Step 7: changes reflect | |
| (should (equal '("3") (cdr (assoc "PROP" (vulpea-issue-427--prop-rows id))))) | |
| (should (equal '("4") (cdr (assoc "metadata" (vulpea-issue-427--meta-rows id))))) | |
| ;; Step 8: delete PROP and the metadata item | |
| (vulpea-issue-427--write | |
| path | |
| ":PROPERTIES:" | |
| (concat ":ID: " id) | |
| ":END:" | |
| "#+title: Note") | |
| (should (eq t (vulpea-db-sync--update-file-if-changed path))) | |
| ;; Step 9: they must be gone from the DB | |
| (should-not (assoc "PROP" (vulpea-issue-427--prop-rows id))) | |
| (should-not (assoc "metadata" (vulpea-issue-427--meta-rows id)))) | |
| (when vulpea-db--connection (vulpea-db-close)) | |
| (when (file-exists-p vulpea-db-location) (delete-file vulpea-db-location)) | |
| (delete-directory root t)))) | |
| (ert-deftest vulpea-issue-427/heading-level-prop-and-meta-removed-on-sync () | |
| "Same steps against a heading-level note." | |
| (let* ((root (file-name-as-directory (make-temp-file "vulpea-427-" t))) | |
| (vulpea-db-location (make-temp-file "vulpea-427-" nil ".db")) | |
| (vulpea-db--connection nil) | |
| (path (expand-file-name "note.org" root)) | |
| (file-id "11111111-1111-1111-1111-111111110428") | |
| (id "11111111-1111-1111-1111-111111110429")) | |
| (unwind-protect | |
| (progn | |
| (vulpea-db) | |
| (vulpea-issue-427--write | |
| path | |
| ":PROPERTIES:" | |
| (concat ":ID: " file-id) | |
| ":END:" | |
| "#+title: Note" | |
| "" | |
| "* Section" | |
| ":PROPERTIES:" | |
| (concat ":ID: " id) | |
| ":PROP: 1" | |
| ":END:" | |
| "" | |
| "- metadata :: 2") | |
| (should (eq t (vulpea-db-sync--update-file-if-changed path))) | |
| (should (equal '("1") (cdr (assoc "PROP" (vulpea-issue-427--prop-rows id))))) | |
| (should (equal '("2") (cdr (assoc "metadata" (vulpea-issue-427--meta-rows id))))) | |
| ;; Delete both | |
| (vulpea-issue-427--write | |
| path | |
| ":PROPERTIES:" | |
| (concat ":ID: " file-id) | |
| ":END:" | |
| "#+title: Note" | |
| "" | |
| "* Section" | |
| ":PROPERTIES:" | |
| (concat ":ID: " id) | |
| ":END:") | |
| (should (eq t (vulpea-db-sync--update-file-if-changed path))) | |
| (should-not (assoc "PROP" (vulpea-issue-427--prop-rows id))) | |
| (should-not (assoc "metadata" (vulpea-issue-427--meta-rows id)))) | |
| (when vulpea-db--connection (vulpea-db-close)) | |
| (when (file-exists-p vulpea-db-location) (delete-file vulpea-db-location)) | |
| (delete-directory root t)))) | |
| (provide 'vulpea-issue-427-test) | |
| ;;; vulpea-issue-427-test.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment