diff --git a/src/main/logseq/cli/command/query.cljs b/src/main/logseq/cli/command/query.cljs index 49bf43da49..ed8b5f9caa 100644 --- a/src/main/logseq/cli/command/query.cljs +++ b/src/main/logseq/cli/command/query.cljs @@ -248,36 +248,35 @@ query-result (let [inputs-text (some-> (:inputs options) string/trim) inputs-result (when (seq inputs-text) - (parse-edn "inputs" inputs-text)) - named-inputs (when-let [entry (:entry query-result)] - (normalize-named-inputs entry (or (:value inputs-result) [])))] + (parse-edn "inputs" inputs-text))] (cond (and inputs-result (not (:ok? inputs-result))) inputs-result - (and named-inputs (not (:ok? named-inputs))) - named-inputs - (and inputs-result (not (vector? (:value inputs-result)))) {:ok? false :error {:code :invalid-options :message "inputs must be a vector"}} :else - (let [inputs (normalize-task-search-inputs - (:entry query-result) - (or (:value named-inputs) - (:value inputs-result) - [])) - validated (validate-recent-updated-inputs (:entry query-result) inputs)] - (if-not (:ok? validated) - validated - {:ok? true - :action {:type :query - :repo repo - :graph (core/repo->graph repo) - :query (:value query-result) - :inputs (:value validated)}})))))))))) + (let [named-inputs (when-let [entry (:entry query-result)] + (normalize-named-inputs entry (or (:value inputs-result) [])))] + (if (and named-inputs (not (:ok? named-inputs))) + named-inputs + (let [inputs (normalize-task-search-inputs + (:entry query-result) + (or (:value named-inputs) + (:value inputs-result) + [])) + validated (validate-recent-updated-inputs (:entry query-result) inputs)] + (if-not (:ok? validated) + validated + {:ok? true + :action {:type :query + :repo repo + :graph (core/repo->graph repo) + :query (:value query-result) + :inputs (:value validated)}})))))))))))) (defn build-list-action [_options _repo] diff --git a/src/test/logseq/cli/commands_test.cljs b/src/test/logseq/cli/commands_test.cljs index 0d10f3a53e..c857958fc4 100644 --- a/src/test/logseq/cli/commands_test.cljs +++ b/src/test/logseq/cli/commands_test.cljs @@ -4,6 +4,7 @@ [logseq.cli.command.add :as add-command] [logseq.cli.command.graph :as graph-command] [logseq.cli.command.list :as list-command] + [logseq.cli.command.query :as query-command] [logseq.cli.command.show :as show-command] [logseq.cli.command.sync :as sync-command] [logseq.cli.commands :as commands] @@ -3174,3 +3175,16 @@ (is (= 2 (get-in result [:human :graph-list :legacy-count]))))) (p/catch (fn [e] (is false (str "unexpected error: " e)))) (p/finally done)))) + +(deftest test-query-build-action-non-vector-inputs + (testing "non-vector inputs gives explicit error" + (let [result (query-command/build-action {:name "block-search" :inputs "b1"} + "test-repo" {})] + (is (false? (:ok? result))) + (is (= :invalid-options (get-in result [:error :code]))) + (is (= "inputs must be a vector" (get-in result [:error :message]))))) + + (testing "valid vector inputs succeeds" + (let [result (query-command/build-action {:name "block-search" :inputs "[\"daily\"]"} + "test-repo" {})] + (is (true? (:ok? result))))))