Skip to content

Commit bfd0895

Browse files
committed
fix(cli): honor HOME when resolving global skill install path
1 parent fb5019f commit bfd0895

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/main/logseq/cli/command/skill.cljs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@
113113
{:ok? true
114114
:dir (:destination-dir action)
115115
:file (:destination-file action)}
116+
(let [env-home (or (some-> js/process .-env .-HOME)
117+
(some-> js/process .-env .-USERPROFILE))]
116118
(resolve-install-target {:global? (:global? action)
117119
:cwd (.cwd js/process)
118-
:home-dir (.homedir os)})))
120+
:home-dir (or env-home
121+
(.homedir os))}))))
119122

120123
(defn execute-skill-install
121124
[action _config]

src/test/logseq/cli/command/skill_test.cljs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,27 @@
139139
(finally
140140
(fs/rmSync tmp-root #js {:recursive true :force true})))))
141141

142+
(deftest test-execute-skill-install-global-prefers-home-env
143+
(let [tmp-root (.mkdtempSync fs (node-path/join (.tmpdir os) "logseq-skill-home-"))
144+
source-path (node-path/join tmp-root "source-skill.md")
145+
installed-file (node-path/join tmp-root ".agents" "skills" "logseq-cli" "SKILL.md")
146+
previous-home (.. js/process -env -HOME)]
147+
(try
148+
(fs/writeFileSync source-path "# installed\ncontent" "utf8")
149+
(set! (.. js/process -env -HOME) tmp-root)
150+
(let [result (skill-command/execute-skill-install {:type :skill-install
151+
:source-path source-path
152+
:global? true}
153+
{})]
154+
(is (= :ok (:status result)))
155+
(is (= installed-file (get-in result [:data :installed-path])))
156+
(is (= "# installed\ncontent" (fs/readFileSync installed-file "utf8"))))
157+
(finally
158+
(if (some? previous-home)
159+
(set! (.. js/process -env -HOME) previous-home)
160+
(js-delete (.-env js/process) "HOME"))
161+
(fs/rmSync tmp-root #js {:recursive true :force true})))))
162+
142163
(deftest test-execute-skill-install-write-error
143164
(let [mkdir-sync (.-mkdirSync fs)
144165
write-file-sync (.-writeFileSync fs)

0 commit comments

Comments
 (0)