014-logseq-cli-show-multi-id.md (2)

This commit is contained in:
rcmerci
2026-01-23 23:45:52 +08:00
parent 45ff243794
commit 9901d0aec6
10 changed files with 48 additions and 495 deletions

View File

@@ -12,12 +12,20 @@ We need `--id` to accept `[<id1> <id2> ...]` and print each corresponding block,
This should align with existing logseq-cli and db-worker-node patterns and preserve existing single-id behavior.
This also enables a pipeline workflow such as: `logseq query --name task-search --inputs '["todo"]' | xargs logseq show -id`.
## Note on removing `search`
Remove the `search` subcommand. No migration or compatibility work is required.
## Note on `logseq query` output
`logseq query` output handling:
1. Validate it is valid EDN.
2. Replace all spaces with commas.
## Note on `logseq query task-search` inputs
The first `task-search` input `status` should be a string like `"todo"` or `"doing"`, not `:logseq.property/status.todo`.
## Testing Plan
I will add unit tests for show argument parsing to accept a vector of ids and to reject invalid EDN in `--id`.

View File

@@ -44,10 +44,8 @@
(defn- command-usage
[cmds spec]
(let [base (string/join " " cmds)
positional (when (= cmds ["search"]) "<query>")
has-options? (seq spec)]
(cond-> base
positional (str " " positional)
has-options? (str " [options]"))))
(defn- format-commands
@@ -84,7 +82,7 @@
(defn top-level-summary
[table]
(let [groups [{:title "Graph Inspect and Edit"
:commands #{"list" "add" "remove" "move" "search" "query" "show"}}
:commands #{"list" "add" "remove" "move" "query" "show"}}
{:title "Graph Management"
:commands #{"graph" "server"}}]
render-group (fn [{:keys [title commands]}]

View File

@@ -54,7 +54,7 @@
[(identity 0) ?days-ago])
(and [(<= ?recent-days 0)]
[(identity 0) ?days-ago])
(and [(* ?recent-days 86400000) ?recent-days-ms]
(and [(* ?recent-days 86400000) ?recent-days-ms]
[(- ?now-ms ?recent-days-ms) ?days-ago]
[(>= ?updated-at ?days-ago)]))]}})
@@ -154,6 +154,21 @@
(into (vec inputs) (map input-default missing)))
inputs)})))
(defn- normalize-task-search-inputs
[entry inputs]
(if (and entry (= "task-search" (:name entry)) (seq inputs))
(let [status (first inputs)
normalized (cond
(keyword? status) status
(string? status) (let [text (string/trim status)]
(if (seq text)
(keyword "logseq.property"
(str "status." (string/lower-case text)))
status))
:else status)]
(assoc (vec inputs) 0 normalized))
inputs))
(defn build-action
[options repo config]
(if-not (seq repo)
@@ -201,14 +216,17 @@
:message "inputs must be a vector"}}
:else
{:ok? true
:action {:type :query
:repo repo
:graph (core/repo->graph repo)
:query (:value query-result)
:inputs (or (:value named-inputs)
(:value inputs-result)
[])}}))))))))
(let [inputs (normalize-task-search-inputs
(:entry query-result)
(or (:value named-inputs)
(:value inputs-result)
[]))]
{:ok? true
:action {:type :query
:repo repo
:graph (core/repo->graph repo)
:query (:value query-result)
:inputs inputs}})))))))))
(defn build-list-action
[_options _repo]

View File

@@ -1,335 +0,0 @@
(ns logseq.cli.command.search
"Search-related CLI commands."
(:require [clojure.set :as set]
[clojure.string :as string]
[logseq.cli.command.core :as core]
[logseq.cli.server :as cli-server]
[logseq.cli.transport :as transport]
[logseq.common.util :as common-util]
[promesa.core :as p]))
(def ^:private search-spec
{:type {:desc "Search types (page, block, tag, property, all)"}
:tag {:desc "Restrict to a specific tag"}
:case-sensitive {:desc "Case sensitive search"
:coerce :boolean}
:sort {:desc "Sort field (updated-at, created-at)"}
:order {:desc "Sort order (asc, desc)"}})
(def entries
[(core/command-entry ["search"] :search "Search graph" search-spec)])
(def ^:private search-types
#{"page" "block" "tag" "property" "all"})
(def ^:private uuid-ref-pattern #"\[\[([0-9a-fA-F-]{36})\]\]")
(def ^:private uuid-ref-max-depth 10)
(defn invalid-options?
[opts]
(let [type (:type opts)
order (:order opts)
sort-field (:sort opts)]
(cond
(and (seq type) (not (contains? search-types type)))
(str "invalid type: " type)
(and (seq sort-field) (not (#{"updated-at" "created-at"} sort-field)))
(str "invalid sort field: " sort-field)
(and (seq order) (not (#{"asc" "desc"} order)))
(str "invalid order: " order)
:else
nil)))
(defn build-action
[options args repo]
(if-not (seq repo)
{:ok? false
:error {:code :missing-repo
:message "repo is required for search"}}
(let [text (some-> (first args) string/trim)]
(if (seq text)
{:ok? true
:action {:type :search
:repo repo
:text text
:search-type (or (:type options) "all")
:tag (:tag options)
:case-sensitive (:case-sensitive options)
:sort (:sort options)
:order (:order options)}}
{:ok? false
:error {:code :missing-search-text
:message "search text is required"}}))))
(defn- query-pages
[cfg repo text case-sensitive?]
(let [query (if case-sensitive?
'[:find ?e ?title ?uuid ?updated ?created
:in $ ?q
:where
[?e :block/name ?name]
[?e :block/title ?title]
[?e :block/uuid ?uuid]
[(get-else $ ?e :block/updated-at 0) ?updated]
[(get-else $ ?e :block/created-at 0) ?created]
[(clojure.string/includes? ?title ?q)]]
'[:find ?e ?title ?uuid ?updated ?created
:in $ ?q
:where
[?e :block/name ?name]
[?e :block/title ?title]
[?e :block/uuid ?uuid]
[(get-else $ ?e :block/updated-at 0) ?updated]
[(get-else $ ?e :block/created-at 0) ?created]
[(clojure.string/includes? ?name ?q)]])
q* (if case-sensitive? text (string/lower-case text))]
(transport/invoke cfg :thread-api/q false [repo [query q*]])))
(defn- query-blocks
[cfg repo text case-sensitive? tag]
(let [q* (if case-sensitive? text (string/lower-case text))
tag-name (some-> tag string/lower-case)
query (cond
(and case-sensitive? (seq tag-name))
'[:find ?e ?title ?uuid ?updated ?created
:in $ ?q ?tag-name
:where
[?e :block/title ?title]
[?e :block/page ?page]
[?e :block/uuid ?uuid]
[(get-else $ ?e :block/updated-at 0) ?updated]
[(get-else $ ?e :block/created-at 0) ?created]
[(clojure.string/includes? ?title ?q)]
[?tag :block/name ?tag-name]
[?e :block/tags ?tag]]
case-sensitive?
'[:find ?e ?title ?uuid ?updated ?created
:in $ ?q
:where
[?e :block/title ?title]
[?e :block/page ?page]
[?e :block/uuid ?uuid]
[(get-else $ ?e :block/updated-at 0) ?updated]
[(get-else $ ?e :block/created-at 0) ?created]
[(clojure.string/includes? ?title ?q)]]
(seq tag-name)
'[:find ?e ?title ?uuid ?updated ?created
:in $ ?tag-name
:where
[?e :block/title ?title]
[?e :block/page ?page]
[?e :block/uuid ?uuid]
[(get-else $ ?e :block/updated-at 0) ?updated]
[(get-else $ ?e :block/created-at 0) ?created]
[?tag :block/name ?tag-name]
[?e :block/tags ?tag]]
:else
'[:find ?e ?title ?uuid ?updated ?created
:where
[?e :block/title ?title]
[?e :block/page ?page]
[?e :block/uuid ?uuid]
[(get-else $ ?e :block/updated-at 0) ?updated]
[(get-else $ ?e :block/created-at 0) ?created]])
query-args (cond
(and case-sensitive? (seq tag-name))
[repo [query q* tag-name]]
case-sensitive?
[repo [query q*]]
(seq tag-name)
[repo [query tag-name]]
:else
[repo [query]])
matches-text? (fn [title]
(when (string? title)
(if case-sensitive?
(string/includes? title q*)
(string/includes? (string/lower-case title) q*))))]
(-> (p/let [rows (transport/invoke cfg :thread-api/q false query-args)]
(->> (or rows [])
(filter (fn [[_ title _ _ _]]
(matches-text? title)))
(mapv (fn [[id title uuid updated created]]
{:type "block"
:db/id id
:content title
:uuid (str uuid)
:updated-at updated
:created-at created}))))
(p/catch (fn [_]
[])))))
(defn- replace-uuid-refs-once
[value uuid->label]
(if (and (string? value) (seq uuid->label))
(string/replace value uuid-ref-pattern
(fn [[_ id]]
(if-let [label (get uuid->label (string/lower-case id))]
(str "[[" label "]]")
(str "[[" id "]]"))))
value))
(defn- replace-uuid-refs
[value uuid->label]
(loop [current value
remaining uuid-ref-max-depth]
(if (or (not (string? current)) (zero? remaining) (empty? uuid->label))
current
(let [next (replace-uuid-refs-once current uuid->label)]
(if (= next current)
current
(recur next (dec remaining)))))))
(defn- extract-uuid-refs
[value]
(->> (re-seq uuid-ref-pattern (or value ""))
(map second)
(filter common-util/uuid-string?)
(map string/lower-case)
distinct))
(defn- collect-uuid-refs
[results]
(->> results
(mapcat (fn [item] (keep item [:title :content])))
(remove string/blank?)
(mapcat extract-uuid-refs)
distinct
vec))
(defn- fetch-uuid-labels
[config repo uuid-strings]
(if (seq uuid-strings)
(p/let [blocks (p/all (map (fn [uuid-str]
(transport/invoke config :thread-api/pull false
[repo [:block/uuid :block/title :block/name]
[:block/uuid (uuid uuid-str)]]))
uuid-strings))]
(->> blocks
(remove nil?)
(map (fn [block]
(let [uuid-str (some-> (:block/uuid block) str)]
[(string/lower-case uuid-str)
(or (:block/title block) (:block/name block) uuid-str)])))
(into {})))
(p/resolved {})))
(defn- fetch-uuid-labels-recursive
[config repo uuid-strings]
(p/loop [pending (set (map string/lower-case uuid-strings))
seen #{}
labels {}
remaining uuid-ref-max-depth]
(if (or (empty? pending) (zero? remaining))
labels
(p/let [fetched (fetch-uuid-labels config repo pending)
next-labels (merge labels fetched)
next-seen (into seen (keys fetched))
nested-refs (->> (vals fetched)
(mapcat extract-uuid-refs)
(remove next-seen)
set)
next-pending (set/difference nested-refs next-seen)]
(p/recur next-pending next-seen next-labels (dec remaining))))))
(defn- resolve-uuid-refs-in-results
[results uuid->label]
(mapv (fn [item]
(cond-> item
(:title item) (update :title replace-uuid-refs uuid->label)
(:content item) (update :content replace-uuid-refs uuid->label)))
(or results [])))
(defn- normalize-search-types
[type]
(let [type (or type "all")]
(case type
"page" [:page]
"block" [:block]
"tag" [:tag]
"property" [:property]
[:page :block :tag :property])))
(defn- search-sort-key
[item sort-field]
(case sort-field
"updated-at" (:updated-at item)
"created-at" (:created-at item)
nil))
(defn execute-search
[action config]
(-> (p/let [cfg (cli-server/ensure-server! config (:repo action))
types (normalize-search-types (:search-type action))
case-sensitive? (boolean (:case-sensitive action))
text (:text action)
tag (:tag action)
page-results (when (some #{:page} types)
(p/let [rows (query-pages cfg (:repo action) text case-sensitive?)]
(mapv (fn [[id title uuid updated created]]
{:type "page"
:db/id id
:title title
:uuid (str uuid)
:updated-at updated
:created-at created})
rows)))
block-results (when (some #{:block} types)
(query-blocks cfg (:repo action) text case-sensitive? tag))
tag-results (when (some #{:tag} types)
(p/let [items (transport/invoke cfg :thread-api/api-list-tags false
[(:repo action) {:expand true :include-built-in true}])
q* (if case-sensitive? text (string/lower-case text))]
(->> items
(filter (fn [item]
(let [title (:block/title item)]
(if case-sensitive?
(string/includes? title q*)
(string/includes? (string/lower-case title) q*)))))
(mapv (fn [item]
{:type "tag"
:db/id (:db/id item)
:title (:block/title item)
:uuid (:block/uuid item)})))))
property-results (when (some #{:property} types)
(p/let [items (transport/invoke cfg :thread-api/api-list-properties false
[(:repo action) {:expand true :include-built-in true}])
q* (if case-sensitive? text (string/lower-case text))]
(->> items
(filter (fn [item]
(let [title (:block/title item)]
(if case-sensitive?
(string/includes? title q*)
(string/includes? (string/lower-case title) q*)))))
(mapv (fn [item]
{:type "property"
:db/id (:db/id item)
:title (:block/title item)
:uuid (:block/uuid item)})))))
results (->> (concat (or page-results [])
(or block-results [])
(or tag-results [])
(or property-results []))
(distinct)
vec)
sorted (if-let [sort-field (:sort action)]
(let [order (or (:order action) "desc")]
(->> results
(sort-by #(search-sort-key % sort-field))
(cond-> (= order "desc") reverse)
vec))
results)
uuid-refs (collect-uuid-refs sorted)
uuid->label (fetch-uuid-labels-recursive cfg (:repo action) uuid-refs)
resolved (resolve-uuid-refs-in-results sorted uuid->label)]
{:status :ok
:data {:results resolved}})))

View File

@@ -9,7 +9,6 @@
[logseq.cli.command.move :as move-command]
[logseq.cli.command.query :as query-command]
[logseq.cli.command.remove :as remove-command]
[logseq.cli.command.search :as search-command]
[logseq.cli.command.server :as server-command]
[logseq.cli.command.show :as show-command]
[logseq.cli.server :as cli-server]
@@ -83,13 +82,6 @@
:message "output is required"}
:summary summary})
(defn- missing-search-result
[summary]
{:ok? false
:error {:code :missing-search-text
:message "search text is required"}
:summary summary})
(defn- missing-query-result
[summary]
{:ok? false
@@ -108,7 +100,6 @@
add-command/entries
move-command/entries
remove-command/entries
search-command/entries
query-command/entries
show-command/entries)))
@@ -173,9 +164,6 @@
(and (= command :show) (> (count show-targets) 1))
(command-core/invalid-options-result summary "only one of --id, --uuid, or --page-name is allowed")
(and (= command :search) (not has-args?))
(missing-search-result summary)
(and (= command :query)
(not (seq (some-> (:query opts) string/trim)))
(not (seq (some-> (:name opts) string/trim))))
@@ -188,9 +176,6 @@
(and (= command :show) (show-command/invalid-options? opts))
(command-core/invalid-options-result summary (show-command/invalid-options? opts))
(and (= command :search) (search-command/invalid-options? opts))
(command-core/invalid-options-result summary (search-command/invalid-options? opts))
(and (= command :graph-export) (not (seq (graph-command/normalize-import-export-type (:type opts)))))
(missing-type-result summary)
@@ -350,9 +335,6 @@
:remove-page
(remove-command/build-remove-page-action options repo)
:search
(search-command/build-action options args repo)
:query
(query-command/build-action options repo config)
@@ -395,7 +377,6 @@
:move-block (move-command/execute-move action config)
:remove-block (remove-command/execute-remove action config)
:remove-page (remove-command/execute-remove action config)
:search (search-command/execute-search action config)
:query (query-command/execute-query action config)
:query-list (query-command/execute-query-list action config)
:show (show-command/execute-show action config)

View File

@@ -86,7 +86,6 @@
:missing-graph "Use --repo <name>"
:missing-repo "Use --repo <name>"
:missing-content "Use --content or pass content as args"
:missing-search-text "Provide search text as a positional argument"
:missing-query "Use --query <edn>"
:unknown-query "Use `logseq query list` to see available queries"
nil))
@@ -180,15 +179,6 @@
(:pid server)])
(or servers []))))
(defn- format-search-results
[results]
(format-counted-table
["ID" "TITLE"]
(mapv (fn [item]
[(:db/id item)
(or (:title item) (:content item))])
(or results []))))
(defn- format-query-results
[result]
(let [edn-str (pr-str result)
@@ -298,7 +288,6 @@
:move-block (format-move-block context)
:graph-export (format-graph-export context)
:graph-import (format-graph-import context)
:search (format-search-results (:results data))
:query (format-query-results (:result data))
:query-list (format-query-list (:queries data))
:show (or (:message data) (pr-str data))

View File

@@ -12,7 +12,7 @@
(string/join "\n"
["logseq <command> [options]"
""
"Commands: list page, list tag, list property, add block, add page, move, remove block, remove page, search, query, query list, show, graph list, graph create, graph switch, graph remove, graph validate, graph info, graph export, graph import, server list, server status, server start, server stop, server restart"
"Commands: list page, list tag, list property, add block, add page, move, remove block, remove page, query, query list, show, graph list, graph create, graph switch, graph remove, graph validate, graph info, graph export, graph import, server list, server status, server start, server stop, server restart"
""
"Options:"
summary]))

View File

@@ -18,7 +18,6 @@
(is (string/includes? summary "add"))
(is (string/includes? summary "remove"))
(is (string/includes? summary "move"))
(is (string/includes? summary "search"))
(is (string/includes? summary "query"))
(is (string/includes? summary "show"))
(is (string/includes? summary "graph"))
@@ -467,18 +466,7 @@
(is (= "def" (get-in result [:options :target-uuid])))
(is (= "last-child" (get-in result [:options :pos]))))))
(deftest test-verb-subcommand-parse-search-show
(testing "search requires text"
(let [result (commands/parse-args ["search"])]
(is (false? (:ok? result)))
(is (= :missing-search-text (get-in result [:error :code])))))
(testing "search parses with text"
(let [result (commands/parse-args ["search" "hello"])]
(is (true? (:ok? result)))
(is (= :search (:command result)))
(is (= ["hello"] (:args result)))))
(deftest test-verb-subcommand-parse-show
(testing "show requires target"
(let [result (commands/parse-args ["show"])]
(is (false? (:ok? result)))
@@ -574,22 +562,13 @@
["add" "block" "--wat"]
["remove" "block" "--wat"]
["move" "--wat"]
["search" "--wat"]
["show" "--wat"]]]
(let [result (commands/parse-args args)]
(is (false? (:ok? result)))
(is (= :invalid-options (get-in result [:error :code]))))))
(testing "search rejects deprecated flags"
(doseq [args [["search" "--limit" "10" "hello"]
["search" "--include-content" "hello"]
["search" "--text" "hello"]]]
(let [result (commands/parse-args args)]
(is (false? (:ok? result)))
(is (= :invalid-options (get-in result [:error :code]))))))
(testing "verb subcommands accept output option"
(let [result (commands/parse-args ["search" "--output" "json" "hello"])]
(let [result (commands/parse-args ["show" "--output" "json" "--page-name" "Home"])]
(is (true? (:ok? result)))
(is (= "json" (get-in result [:options :output]))))))
@@ -684,30 +663,6 @@
(is (false? (:ok? result)))
(is (= :missing-target (get-in result [:error :code])))))
(testing "search requires text"
(let [parsed {:ok? true :command :search :options {}}
result (commands/build-action parsed {:repo "demo"})]
(is (false? (:ok? result)))
(is (= :missing-search-text (get-in result [:error :code])))))
(testing "search defaults to all types"
(let [parsed {:ok? true :command :search :options {} :args ["hello"]}
result (commands/build-action parsed {:repo "demo"})]
(is (true? (:ok? result)))
(is (= "all" (get-in result [:action :search-type])))))
(testing "search uses config repo and ignores positional text for repo"
(let [parsed {:ok? true :command :search :options {} :args ["hello"]}
result (commands/build-action parsed {:repo "demo"})]
(is (true? (:ok? result)))
(is (= "logseq_db_demo" (get-in result [:action :repo])))))
(testing "search uses first positional argument"
(let [parsed {:ok? true :command :search :options {} :args ["hello" "world"]}
result (commands/build-action parsed {:repo "demo"})]
(is (true? (:ok? result)))
(is (= "hello" (get-in result [:action :text])))))
(testing "show requires target"
(let [parsed {:ok? true :command :show :options {}}
result (commands/build-action parsed {:repo "demo"})]
@@ -765,9 +720,8 @@
(with-redefs [cli-server/list-graphs (fn [_] [])
cli-server/ensure-server! (fn [_ _]
(throw (ex-info "should not start server" {})))]
(-> (p/let [result (commands/execute {:type :search
:repo "logseq_db_missing"
:text "hello"}
(-> (p/let [result (commands/execute {:type :list-page
:repo "logseq_db_missing"}
{})]
(is (= :error (:status result)))
(is (= :graph-not-exists (get-in result [:error :code])))

View File

@@ -159,40 +159,7 @@
"Host: 127.0.0.1 Port: 1234")
result)))))
(deftest test-human-output-search-and-show
(testing "search renders a table with count"
(let [result (format/format-result {:status :ok
:command :search
:data {:results [{:type "page"
:db/id 101
:title "Alpha"
:uuid "u1"
:updated-at 3
:created-at 1}
{:type "block"
:db/id 102
:content "Note line 1\nNote line 2"
:uuid "u2"
:updated-at 4
:created-at 2}
{:type "tag"
:db/id 103
:title "Taggy"
:uuid "u3"}
{:type "property"
:db/id 104
:title "Prop"
:uuid "u4"}]}}
{:output-format nil})]
(is (= (str "ID TITLE\n"
"101 Alpha\n"
"102 Note line 1\n"
" Note line 2\n"
"103 Taggy\n"
"104 Prop\n"
"Count: 4")
result))))
(deftest test-human-output-show
(testing "show renders text payloads directly"
(let [result (format/format-result {:status :ok
:command :show
@@ -231,14 +198,4 @@
{:output-format nil})]
(is (= (str "Error (missing-graph): graph name is required\n"
"Hint: Use --repo <name>")
result))))
(testing "missing search text hints use positional argument"
(let [result (format/format-result {:status :error
:command :search
:error {:code :missing-search-text
:message "search text is required"}}
{:output-format nil})]
(is (= (str "Error (missing-search-text): search text is required\n"
"Hint: Provide search text as a positional argument")
result)))))

View File

@@ -86,7 +86,7 @@
(is false (str "unexpected error: " e))
(done)))))))
(deftest test-cli-list-add-search-show-remove
(deftest test-cli-list-add-show-remove
(async done
(let [data-dir (node-helper/create-tmp-dir "db-worker")]
(-> (p/let [cfg-path (node-path/join (node-helper/create-tmp-dir "cli") "cli.edn")
@@ -103,8 +103,6 @@
add-block-result (run-cli ["--repo" "content-graph" "add" "block" "--target-page-name" "TestPage" "--content" "Test block"] data-dir cfg-path)
add-block-payload (parse-json-output add-block-result)
_ (p/delay 100)
search-result (run-cli ["--repo" "content-graph" "search" "t"] data-dir cfg-path)
search-payload (parse-json-output search-result)
show-result (run-cli ["--repo" "content-graph" "show" "--page-name" "TestPage" "--format" "json"] data-dir cfg-path)
show-payload (parse-json-output show-result)
remove-page-result (run-cli ["--repo" "content-graph" "remove" "page" "--page" "TestPage"] data-dir cfg-path)
@@ -120,13 +118,6 @@
(is (vector? (get-in list-tag-payload [:data :items])))
(is (= "ok" (:status list-property-payload)))
(is (vector? (get-in list-property-payload [:data :items])))
(is (= "ok" (:status search-payload)))
(is (vector? (get-in search-payload [:data :results])))
(let [types (set (map :type (get-in search-payload [:data :results])))]
(is (contains? types "page"))
(is (contains? types "block"))
(is (contains? types "tag"))
(is (contains? types "property")))
(is (= "ok" (:status show-payload)))
(is (contains? (get-in show-payload [:data :root]) :uuid))
(is (= "ok" (:status remove-page-payload)))
@@ -203,16 +194,15 @@
query-result (run-cli ["--repo" "task-query-graph"
"query"
"--name" "task-search"
"--inputs" "[:logseq.property/status.doing]"]
"--inputs" "[\"doing\"]"]
data-dir cfg-path)
query-payload (parse-json-output query-result)
query-nil-result (run-cli ["--repo" "task-query-graph"
"query"
"--name" "task-search"
"--inputs" "[:logseq.property/status.doing nil 1]"]
"--inputs" "[\"doing\" nil 1]"]
data-dir cfg-path)
query-nil-payload (parse-json-output query-nil-result)
_ (prn :xxxx query-payload)
result (get-in query-payload [:data :result])
nil-result (get-in query-nil-payload [:data :result])
stop-result (run-cli ["server" "stop" "--repo" "task-query-graph"] data-dir cfg-path)
@@ -237,7 +227,7 @@
(is false (str "unexpected error: " e))
(done)))))))
(deftest test-cli-show-search-resolve-nested-uuid-refs
(deftest test-cli-show-resolve-nested-uuid-refs
(async done
(let [data-dir (node-helper/create-tmp-dir "db-worker-nested-refs")]
(-> (p/let [cfg-path (node-path/join (node-helper/create-tmp-dir "cli") "cli.edn")
@@ -260,19 +250,12 @@
show-outer (run-cli ["--repo" "nested-refs" "show" "--page-name" "NestedPage" "--format" "json"] data-dir cfg-path)
show-outer-payload (parse-json-output show-outer)
outer-node (find-block-by-title (get-in show-outer-payload [:data :root]) "Outer [[See [[Inner]]]]")
search-result (run-cli ["--repo" "nested-refs" "search" "Outer"] data-dir cfg-path)
search-payload (parse-json-output search-result)
search-item (some (fn [item]
(when (and (string? (:content item))
(string/includes? (:content item) "Outer"))
item))
(get-in search-payload [:data :results]))
stop-result (run-cli ["server" "stop" "--repo" "nested-refs"] data-dir cfg-path)
stop-payload (parse-json-output stop-result)]
(is (some? inner-uuid))
(is (some? middle-uuid))
(is (some? outer-node))
(is (= "Outer [[See [[Inner]]]]" (:content search-item)))
(is (= "Outer [[See [[Inner]]]]" (node-title outer-node)))
(is (= "ok" (:status stop-payload)))
(done))
(p/catch (fn [e]
@@ -527,7 +510,7 @@
output (:output show-text-result)
idx-one (string/index-of output "Multi show one")
idx-two (string/index-of output "Multi show two")
idx-delim (string/index-of output "-----")
idx-delim (string/index-of output "================================================================")
show-json-result (run-cli ["--repo" "show-multi-id-graph" "show"
"--id" ids-edn
"--format" "json"]