enhance(cli-e2e): update spec :cmd -> :cmds

This commit is contained in:
rcmerci
2026-03-24 16:39:57 +08:00
parent 4263123e83
commit bad48702e8
5 changed files with 97 additions and 72 deletions

View File

@@ -6,16 +6,16 @@
(def sample-cases
[{:id "global-help"
:cmd "node static/logseq-cli.js --help"
:cmds ["node static/logseq-cli.js --help"]
:covers {:options {:global ["--help"]}}
:tags [:global :smoke]}
{:id "graph-create"
:cmd "node static/logseq-cli.js graph create --graph demo"
:cmds ["node static/logseq-cli.js graph create --graph demo"]
:covers {:commands ["graph create"]
:options {:graph ["--type"]}}
:tags [:graph]}
{:id "graph-list"
:cmd "node static/logseq-cli.js graph list"
:cmds ["node static/logseq-cli.js graph list"]
:covers {:commands ["graph list"]
:options {:graph ["--file"]}}
:tags [:graph :smoke]}])
@@ -41,7 +41,7 @@
#"Missing coverage"
(main/run! {:inventory complete-inventory
:cases [{:id "global-help"
:cmd "node static/logseq-cli.js --help"
:cmds ["node static/logseq-cli.js --help"]
:covers {:options {:global ["--help"]}}}]
:skip-build true
:run-command (fn [_]
@@ -54,14 +54,14 @@
(deftest run-succeeds-when-coverage-is-complete
(let [result (main/run! {:inventory complete-inventory
:cases [{:id "global-help"
:cmd "node static/logseq-cli.js --help"
:cmds ["node static/logseq-cli.js --help"]
:covers {:options {:global ["--help"]}}}
{:id "graph-create"
:cmd "node static/logseq-cli.js graph create --type markdown"
:cmds ["node static/logseq-cli.js graph create --type markdown"]
:covers {:commands ["graph create"]
:options {:graph ["--type"]}}}
{:id "graph-list"
:cmd "node static/logseq-cli.js graph list --file demo.edn"
:cmds ["node static/logseq-cli.js graph list --file demo.edn"]
:covers {:commands ["graph list"]
:options {:graph ["--file"]}}}]
:skip-build true
@@ -76,10 +76,10 @@
(let [executed (atom [])]
(let [result (main/run! {:inventory complete-inventory
:cases [{:id "global-help"
:cmd "node static/logseq-cli.js --help"
:cmds ["node static/logseq-cli.js --help"]
:covers {:options {:global ["--help"]}}}
{:id "graph-create"
:cmd "node static/logseq-cli.js graph create --graph demo"
:cmds ["node static/logseq-cli.js graph create --graph demo"]
:covers {:commands ["graph create"]
:options {:graph ["--type"]}}}]
:case "global-help"
@@ -131,7 +131,7 @@
:run-case (fn [case _opts]
{:id (:id case)
:status :ok
:cmd (:cmd case)})}))]
:cmd (last (:cmds case))})}))]
(is (string/includes? output "==> Running cli-e2e cases"))
(is (string/includes? output "==> Build preflight: running..."))
(is (string/includes? output "==> Build preflight: skipped (--skip-build)"))
@@ -169,7 +169,7 @@
output (with-out-str
(main/test! {:inventory complete-inventory
:cases [{:id "global-help"
:cmd "node static/logseq-cli.js --help"
:cmds ["node static/logseq-cli.js --help"]
:covers {:options {:global ["--help"]}}}]
:case "global-help"
:skip-build true
@@ -180,7 +180,7 @@
:out "ok"
:err ""})
:run-case (fn [case {:keys [run-command]}]
(let [result (run-command {:cmd (:cmd case)
(let [result (run-command {:cmd (first (:cmds case))
:phase :main
:step-index 1
:step-total 1})]
@@ -188,7 +188,7 @@
:status :ok
:cmd (:cmd result)}) )}))]
(is (string/includes? output "==> Detailed case logging enabled (--case global-help)"))
(is (string/includes? output " [main] $ node static/logseq-cli.js --help"))
(is (string/includes? output " [main 1/1] $ node static/logseq-cli.js --help"))
(is (true? (:stream-output? @command-opts)))))
(deftest cleanup-help-prints-usage

View File

@@ -6,14 +6,14 @@
(let [rendered (runner/render-case
{:id "graph-create"
:setup ["{{cli}} --graph {{graph-arg}}"]
:cmd "{{cli}} graph info --graph {{graph-arg}}"
:cmds ["{{cli}} graph info --graph {{graph-arg}}"]
:expect {:stdout-json-paths {[:data :graph] "{{graph}}"
[:status] "ok"}}}
{:cli "node /tmp/logseq-cli.js"
:graph "demo"
:graph-arg "'demo'"})]
(is (= ["node /tmp/logseq-cli.js --graph 'demo'"] (:setup rendered)))
(is (= "node /tmp/logseq-cli.js graph info --graph 'demo'" (:cmd rendered)))
(is (= ["node /tmp/logseq-cli.js graph info --graph 'demo'"] (:cmds rendered)))
(is (= "demo" (get-in rendered [:expect :stdout-json-paths [:data :graph]])))))
(deftest run-case-executes-setup-before-main-command
@@ -21,7 +21,7 @@
result (runner/run-case!
{:id "graph-info"
:setup ["setup one" "setup two"]
:cmd "main command"
:cmds ["main command one" "main command two"]
:expect {:exit 0}}
{:context {}
:run-command (fn [{:keys [cmd]}]
@@ -30,16 +30,16 @@
:exit 0
:out ""
:err ""})})]
(is (= ["setup one" "setup two" "main command"] @calls))
(is (= ["setup one" "setup two" "main command one" "main command two"] @calls))
(is (= "graph-info" (:id result)))
(is (= "main command" (get-in result [:result :cmd])))))
(is (= "main command two" (get-in result [:result :cmd])))))
(deftest run-case-includes-command-phase-metadata-when-detailed
(let [calls (atom [])]
(runner/run-case!
{:id "graph-info"
:setup ["setup one" "setup two"]
:cmd "main command"
:cmds ["main command one" "main command two"]
:cleanup ["cleanup one"]
:expect {:exit 0}}
{:context {}
@@ -52,14 +52,15 @@
:err ""})})
(is (= [{:cmd "setup one" :phase :setup :step-index 1 :step-total 2 :case-id "graph-info" :throw? true}
{:cmd "setup two" :phase :setup :step-index 2 :step-total 2 :case-id "graph-info" :throw? true}
{:cmd "main command" :phase :main :step-index 1 :step-total 1 :case-id "graph-info" :throw? false}
{:cmd "main command one" :phase :main :step-index 1 :step-total 2 :case-id "graph-info" :throw? true}
{:cmd "main command two" :phase :main :step-index 2 :step-total 2 :case-id "graph-info" :throw? false}
{:cmd "cleanup one" :phase :cleanup :step-index 1 :step-total 1 :case-id "graph-info" :throw? false}]
@calls))))
(deftest run-case-validates-json-paths-and-nonzero-exit
(let [result (runner/run-case!
{:id "invalid-shell"
:cmd "node static/logseq-cli.js completion fish"
:cmds ["node static/logseq-cli.js completion fish"]
:expect {:exit 1
:stdout-json-paths {[:status] "error"
[:error :code] "invalid-options"}}}