two way sync requires markdown mirror to be enabled first

This commit is contained in:
Tienson Qin
2026-05-06 17:08:33 +08:00
parent e3a1201860
commit b5cff21cd7
3 changed files with 56 additions and 11 deletions

View File

@@ -1115,6 +1115,12 @@
:feature :markdown-mirror-two-way
:reason :collaborated-graph}))
(not (markdown-mirror/enabled? repo))
(p/rejected (ex-info "Two-way Markdown Mirror requires Markdown Mirror to be enabled"
{:repo repo
:feature :markdown-mirror-two-way
:reason :markdown-mirror-disabled}))
:else
(when-let [conn (worker-state/get-datascript-conn repo)]
(p/let [_ (markdown-mirror/<start-file-watcher! repo conn {})

View File

@@ -205,7 +205,8 @@
(->
(restoring-worker-state
(fn []
(let [set-two-way-enabled! (get-thread-api :thread-api/markdown-mirror-set-two-way-enabled)
(let [set-enabled! (get-thread-api :thread-api/markdown-mirror-set-enabled)
set-two-way-enabled! (get-thread-api :thread-api/markdown-mirror-set-two-way-enabled)
conn (d/create-conn)
calls (atom [])]
(reset! worker-state/*datascript-conns {test-repo conn})
@@ -217,7 +218,9 @@
(fn [& _]
(swap! calls conj :mirror-repo)
(p/resolved {:status :mirrored})))
(-> (set-two-way-enabled! test-repo true false)
(-> (p/let [_ (set-enabled! test-repo true)
_ (reset! calls [])]
(set-two-way-enabled! test-repo true false))
(p/then (fn [_]
(is (= [:start-file-watcher :mirror-repo] @calls))))))))
(p/catch (fn [error]
@@ -253,6 +256,41 @@
(set! markdown-mirror/<start-file-watcher! start-file-watcher!-orig)
(done)))))))
(deftest markdown-mirror-two-way-enable-rejects-disabled-mirror-test
(async done
(let [start-file-watcher!-orig markdown-mirror/<start-file-watcher!
mirror-repo!-orig markdown-mirror/<mirror-repo!]
(->
(restoring-worker-state
(fn []
(let [set-enabled! (get-thread-api :thread-api/markdown-mirror-set-enabled)
set-two-way-enabled! (get-thread-api :thread-api/markdown-mirror-set-two-way-enabled)
conn (d/create-conn)
calls (atom [])]
(reset! worker-state/*datascript-conns {test-repo conn})
(set! markdown-mirror/<start-file-watcher!
(fn [& _]
(swap! calls conj :start-file-watcher)
(p/resolved {:status :watching})))
(set! markdown-mirror/<mirror-repo!
(fn [& _]
(swap! calls conj :mirror-repo)
(p/resolved {:status :mirrored})))
(-> (p/let [_ (set-enabled! test-repo true)
_ (set-enabled! test-repo false)]
(set-two-way-enabled! test-repo true false))
(p/then (fn [_]
(is false "expected disabled markdown mirror to be rejected")))
(p/catch (fn [error]
(is (= :markdown-mirror-disabled (:reason (ex-data error))))
(is (= [:mirror-repo] @calls))))))))
(p/catch (fn [error]
(is false (str "unexpected error: " error))))
(p/finally (fn []
(set! markdown-mirror/<start-file-watcher! start-file-watcher!-orig)
(set! markdown-mirror/<mirror-repo! mirror-repo!-orig)
(done)))))))
(deftest resolve-initial-config-falls-back-to-template-config-test
(let [resolve-initial-config #'db-core/resolve-initial-config
template-config (rc/inline "templates/config.edn")]

View File

@@ -1852,16 +1852,17 @@
(-> (markdown-mirror/<import-file-content! test-repo conn "pages/Tag Edit.md" content {})
(p/then (fn [result]
(let [tag (db-test/find-page-by-title @conn "tag1")
block (d/entity @conn [:block/uuid block-uuid])]
block (d/entity @conn [:block/uuid block-uuid])
block-content-ref-ids (->> (:block/refs block)
(remove #(= :block/tags (:db/ident %)))
(map :db/id)
set)]
(is (= :imported (:status result)))
(is (some? tag))
(is (some #(= :logseq.class/Tag (:db/ident %)) (:block/tags tag)))
(is (block-title-includes? @conn block-uuid "#tag1"))
(is (= #{(:db/id tag)} (set (map :db/id (:block/tags block)))))
(is (= #{(:db/id tag)} (set (map :db/id (:block/refs block))))
(pr-str (map (fn [ref]
(select-keys ref [:db/id :db/ident :block/title :block/uuid]))
(:block/refs block)))))))
(is (some? tag))
(is (some #(= :logseq.class/Tag (:db/ident %)) (:block/tags tag)))
(is (block-title-includes? @conn block-uuid "#tag1"))
(is (= #{(:db/id tag)} (set (map :db/id (:block/tags block)))))
(is (= #{(:db/id tag)} block-content-ref-ids)))))
(p/catch (fn [e] (is false (str "unexpected error: " e))))
(p/finally done)))))