fix: delete old mirror path on rename when new path content is unchanged

Agent-Logs-Url: https://github.com/logseq/logseq/sessions/9db79397-9189-4b9b-a75c-ec333a6ca7b5

Co-authored-by: tiensonqin <479169+tiensonqin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-05 12:41:19 +00:00
committed by Tienson Qin
parent 9189755b3a
commit 94f2cbc5f6
2 changed files with 30 additions and 1 deletions

View File

@@ -314,7 +314,9 @@
_ (when (and old-path
new-path
(not= old-path new-path)
(= :written (:status result)))
(or (= :written (:status result))
(and (= :skipped (:status result))
(= :unchanged (:reason result)))))
(<delete-file! platform* old-path))]
result)))

View File

@@ -368,6 +368,33 @@
(p/catch (fn [e] (is false (str "unexpected error: " e))))
(p/finally done)))))
(deftest rename-with-unchanged-content-removes-old-mirror-path-test
(async done
(let [{:keys [platform files deletes]} (fake-platform)
page-uuid #uuid "55555555-5555-4555-8555-555555555556"
conn (db-test/create-conn-with-blocks
{:pages-and-blocks [{:page {:block/title "Old Name2"
:block/uuid page-uuid}
:blocks [{:block/title "body"}]}]})
page (db-test/find-page-by-title @conn "Old Name2")
old-path (page-path "pages/Old Name2.md")
new-path (page-path "pages/New Name2.md")
;; pre-populate both old and new paths with same content
_ (swap! files assoc old-path "- body")
_ (swap! files assoc new-path "- body")
tx-report (d/with @conn [{:db/id (:db/id page)
:block/title "New Name2"
:block/name "new name2"}])
_ (d/reset-conn! conn (:db-after tx-report))]
(markdown-mirror/set-enabled! test-repo true)
(-> (markdown-mirror/<handle-tx-report! test-repo conn tx-report {:platform platform})
(p/then (fn [_]
;; old-path must be cleaned up even though new-path was unchanged
(is (= [old-path] @deletes))
(is (nil? (get @files old-path)))))
(p/catch (fn [e] (is false (str "unexpected error: " e))))
(p/finally done)))))
(deftest delete-removes-mirror-file-test
(async done
(let [{:keys [platform files deletes writes]} (fake-platform)