Initial import of LogDarioSeq baseline

Establishes version control for the personal Logseq DB fork before
starting the server-client architecture migration and domain features
described in docs/agent-guide and the approved implementation plan.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-25 15:32:15 +02:00
commit 40631362b3
2016 changed files with 543898 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
(ns logseq.common.config-test
(:require [cljs.test :refer [deftest is testing]]
[logseq.common.config :as common-config]))
(deftest remove-hidden-files
(let [files ["pages/foo.md" "pages/bar.md"
"script/README.md" "script/config.edn"
"dev/README.md" "dev/config.edn"]]
(is (= ["pages/foo.md" "pages/bar.md"]
(common-config/remove-hidden-files
files
{:hidden ["script" "/dev"]}
identity))
"Removes hidden relative files")
(is (= ["/pages/foo.md" "/pages/bar.md"]
(common-config/remove-hidden-files
(map #(str "/" %) files)
{:hidden ["script" "/dev"]}
identity))
"Removes hidden files if they start with '/'")))
(deftest local-relative-asset?
(testing "local-relative-asset?"
(is (common-config/local-relative-asset? "assets/test.png"))
(is (common-config/local-relative-asset? "../assets/test.png"))
(is (common-config/local-relative-asset? "./assets/test.png"))
(is (not (common-config/local-relative-asset? "assets://")))
(is (not (common-config/local-relative-asset? "assets://test.png")))
(is (not (common-config/local-relative-asset? "http://assets/test.png")))
(is (not (common-config/local-relative-asset? "file://assets/test.png")))
(is (not (common-config/local-relative-asset? nil))))
(testing "Windows backslash paths"
(is (common-config/local-relative-asset? "assets\\test.png"))))

View File

@@ -0,0 +1,50 @@
(ns logseq.common.graph-test
(:require [logseq.common.graph :as common-graph]
[cljs.test :refer [deftest is use-fixtures async]]
["fs" :as fs]
["path" :as node-path]))
(use-fixtures
:each
;; Cleaning tmp/ before leaves last tmp/ after a test run for dev and debugging
{:before
#(async done
(if (fs/existsSync "tmp")
(fs/rm "tmp" #js {:recursive true} (fn [err]
(when err (js/console.log err))
(done)))
(done)))})
(defn- create-logseq-graph
"Creates a minimal mock graph"
[dir]
(fs/mkdirSync (node-path/join dir "logseq") #js {:recursive true})
(fs/mkdirSync (node-path/join dir "journals"))
(fs/mkdirSync (node-path/join dir "pages")))
(deftest get-files
(create-logseq-graph "tmp/test-graph")
;; Create files that are recognized
(fs/writeFileSync "tmp/test-graph/pages/foo.md" "")
(fs/writeFileSync "tmp/test-graph/journals/2023_05_09.md" "")
(fs/mkdirSync (node-path/join "tmp/test-graph" "mirror" "markdown-notes") #js {:recursive true})
(fs/mkdirSync (node-path/join "tmp/test-graph" "mirror" "markdown2") #js {:recursive true})
(fs/writeFileSync "tmp/test-graph/mirror/markdown-notes/foo.md" "")
(fs/writeFileSync "tmp/test-graph/mirror/markdown2/foo.md" "")
;; Create files that are ignored
(fs/mkdirSync (node-path/join "tmp/test-graph" "logseq" "bak"))
(fs/mkdirSync (node-path/join "tmp/test-graph" "mirror" "markdown" "pages") #js {:recursive true})
(fs/writeFileSync "tmp/test-graph/logseq/bak/baz.md" "")
(fs/writeFileSync "tmp/test-graph/logseq/.gitignore" "")
(fs/writeFileSync "tmp/test-graph/mirror/markdown/pages/foo.md" "")
(is (= ["tmp/test-graph/journals/2023_05_09.md"
"tmp/test-graph/mirror/markdown-notes/foo.md"
"tmp/test-graph/mirror/markdown2/foo.md"
"tmp/test-graph/pages/foo.md"]
(common-graph/get-files "tmp/test-graph"))))
(deftest ignored-markdown-mirror-path-honors-directory-boundary-test
(is (common-graph/ignored-path? "tmp/test-graph" "tmp/test-graph/mirror/markdown"))
(is (common-graph/ignored-path? "tmp/test-graph" "tmp/test-graph/mirror/markdown/pages/foo.md"))
(is (not (common-graph/ignored-path? "tmp/test-graph" "tmp/test-graph/mirror/markdown-notes/foo.md")))
(is (not (common-graph/ignored-path? "tmp/test-graph" "tmp/test-graph/mirror/markdown2/foo.md"))))

View File

@@ -0,0 +1,73 @@
(ns logseq.common.path-test
(:require [cljs.test :refer [deftest is testing]]
[logseq.common.path :as path]))
(deftest filename
(is (= nil (path/filename "/path/to/dir/")))
(is (= "file-name" (path/filename "/path/to/dir/file-name")))
(is (= "file-name" (path/filename "dir/file-name"))))
(deftest split-ext
(is (= ["some-song" "mp3"] (path/split-ext "some-song.MP3")))
(is (= ["some-song" ""] (path/split-ext "some-song")))
(is (= ["some-file.edn" "txt"] (path/split-ext "some-file.edn.txt"))))
(deftest path-join
(testing "path-join"
(is (= "foo/bar" (path/path-join "foo" "bar")))
(is (= "foo/bar" (path/path-join "foo/" "bar")))
(is (= "foo/bar" (path/path-join nil "foo" "bar"))
"global dir")
(is (= "/foo/bar/baz/asdf" (path/path-join "/foo/bar//baz/asdf/quux/..")))
(is (= "assets:///foo.bar/baz" (path/path-join "assets:///foo.bar" "baz")))
(is (= "assets:///foo.bar/baz" (path/path-join "assets:///foo.bar/" "baz")))
(is (= "file:///D:/a.txt" (path/path-join "file://" "D:/a.txt")))
(is (= "file:///c:/x" (path/path-join "file://" "c:/x")))
(is (= "//NAS/MyGraph/logseq/config.edn" (path/path-join "//NAS/MyGraph" "logseq/config.edn")))))
(deftest prepend-protocol
(testing "prepend-protocol"
(is (= "file:///home/logseq/graph" (path/prepend-protocol "file:" "/home/logseq/graph")))
(is (= "file:///C:/Graph/pages" (path/prepend-protocol "file:" "C:/Graph/pages")))
(is (= "file://NAS/MyGraph" (path/prepend-protocol "file:" "//NAS/MyGraph"))
"Windows UNC URL")))
(deftest file-url-or-path->path
(testing "file URL paths"
(is (= "D:/a.txt" (path/file-url-or-path->path "file:///D:/a.txt")))
(is (= "c:/x" (path/file-url-or-path->path "file:///c:/x")))
(is (= "//nas/share/x" (path/file-url-or-path->path "file://NAS/share/x")))
(is (= "D:/a.txt" (path/file-url-or-path->path "file:///D%3A/a.txt")))
(is (= "/home/admin/a.txt" (path/file-url-or-path->path "file:///home/admin/a.txt")))
(is (= "/D:/a.txt" (path/file-url-or-path->path "/D:/a.txt")))
(is (= "/D:\\a.txt" (path/file-url-or-path->path "/D:\\a.txt")))
(is (= "/home/admin/a.txt" (path/file-url-or-path->path "/home/admin/a.txt")))))
(deftest path-absolute
(testing "absolute"
(is (true? (path/absolute? "D:\\sources\\sources.md")))
(is (true? (path/absolute? "/home/xxx/logseq/test.md")))
(is (false? (path/absolute? "logseq/test.md")))
(is (false? (path/absolute? "test.md")))
(is (false? (path/absolute? "test")))
(is (false? (path/absolute? "D:test.md")))))
(deftest protocol-url
(testing "protocol url"
(is (true? (path/protocol-url? "mailto:help@logseq.com")))
(is (true? (path/protocol-url? "https://logseq.com")))
(is (true? (path/protocol-url? "ftp://logseq.com")))
(is (true? (path/protocol-url? "file:///home/xxx/logseq/test.md")))
(is (true? (path/protocol-url? "assets:///home/xxx/logseq/test.md")))
(is (false? (path/protocol-url? "logseq/test.md")))
(is (false? (path/protocol-url? "test.md")))
(is (false? (path/protocol-url? "test")))
(is (false? (path/protocol-url? "D:test.md")))))
(deftest invalid-or-bare-protocol-urls
(testing "invalid or bare protocol URLs do not crash"
(is (string? (path/url-to-path "assets://")))
(is (string? (path/url-to-path "file://")))
(is (= "assets:///foo" (path/path-join "assets://" "foo")))
(is (string? (path/path-join "file://" "assets://")))
(is (string? (path/url-normalize "assets://")))))

View File

@@ -0,0 +1,11 @@
(ns logseq.common.util.page-ref-test
(:require [logseq.common.util.page-ref :as page-ref]
[cljs.test :refer [are deftest]]))
(deftest page-ref?
(are [x y] (= (page-ref/page-ref? x) y)
"[[page]]" true
"[[another page]]" true
"[[some [[nested]] page]]" true
"[single bracket]" false
"no brackets" false))

View File

@@ -0,0 +1,68 @@
(ns logseq.common.util-test
(:require [clojure.test :refer [deftest are testing]]
[logseq.common.util :as common-util]))
(deftest valid-edn-keyword?
(are [x y]
(= (common-util/valid-edn-keyword? x) y)
":foo-bar" true
":foo!" true
":foo,bar" false
"4" false
"foo bar" false
"`property" false))
(deftest extract-file-extension?
(are [x y]
(= (common-util/path->file-ext x) y)
"foo.bar" "bar"
"foo" nil
"foo.bar.baz" "baz"
"../assets/audio.mp3" "mp3"
;; From https://www.w3.org/TR/media-frags/
"../assets/audio.mp3?t=10,20" "mp3"
"../assets/audio.mp3?t=10,20#t=10" "mp3"
"/root/Documents/audio.mp3" "mp3"
"C:\\Users\\foo\\Documents\\audio.mp3" "mp3"
"/root/Documents/audio" nil
"/root/Documents/audio." nil
"special/characters/aäääöüß.7z" "7z"
"asldk lakls .lsad" "lsad"
"中文asldk lakls .lsad" "lsad"))
(deftest url?
(are [x y]
(= (common-util/url? x) y)
"http://logseq.com" true
"prop:: value" false
"a:" false))
(deftest escape-regex-chars
(testing "ensure the result is a valid regex string"
(are [x]
(some? (re-find (re-pattern (common-util/escape-regex-chars x)) x))
"[[page-name]]"
"end-with-backslash\\"
"\\[]{}().+*?|$^")))
(deftest safe-subs
(testing "behaves like subs for in-range indices"
(are [args y]
(= (apply common-util/safe-subs args) y)
["hello" 1 3] "el"
["hello" 2] "llo"
["hello" 0 5] "hello"))
(testing "clamps out-of-range indices instead of throwing"
(are [args y]
(= (apply common-util/safe-subs args) y)
["hello" 0 99] "hello"
["hello" 99 99] ""
["hello" 99] ""))
(testing "returns \"\" for a non-string instead of throwing"
(are [args y]
(= (apply common-util/safe-subs args) y)
[nil 0 0] ""
[nil 0 5] ""
[nil 0] ""
[42 0 1] "")))