|
5 | 5 | [clojure.test :refer [deftest is testing]] |
6 | 6 | [eca.features.commands :as f.commands] |
7 | 7 | [eca.features.rules :as f.rules] |
| 8 | + [eca.shared :as shared] |
8 | 9 | [eca.test-helper :as h])) |
9 | 10 |
|
10 | 11 | (h/reset-components-before-test) |
|
116 | 117 | (finally |
117 | 118 | (fs/delete-tree tmp-dir))))) |
118 | 119 |
|
| 120 | +(deftest command-arguments-test |
| 121 | + (let [tmp-dir (fs/create-temp-dir)] |
| 122 | + (try |
| 123 | + (testing "command with $ARG1 placeholder detects arguments" |
| 124 | + (let [cmd-file (fs/file tmp-dir "greet.md")] |
| 125 | + (spit cmd-file "Greet $ARG1!") |
| 126 | + (let [config {:pureConfig true :commands [{:path (str cmd-file)}]} |
| 127 | + result (vec (#'f.commands/custom-commands config []))] |
| 128 | + (is (= 1 (count result))) |
| 129 | + (is (= "greet" (:name (first result)))) |
| 130 | + (is (= [{:name "arg1" :required true}] |
| 131 | + (:arguments (first result))))))) |
| 132 | + |
| 133 | + (testing "command without placeholders has empty arguments" |
| 134 | + (let [cmd-file (fs/file tmp-dir "simple.md")] |
| 135 | + (spit cmd-file "Simple body") |
| 136 | + (let [config {:pureConfig true :commands [{:path (str cmd-file)}]} |
| 137 | + result (vec (#'f.commands/custom-commands config []))] |
| 138 | + (is (= [] (:arguments (first result))))))) |
| 139 | + |
| 140 | + (finally |
| 141 | + (fs/delete-tree tmp-dir))))) |
| 142 | + |
119 | 143 | (deftest all-commands-include-model-command-test |
120 | 144 | (let [commands (f.commands/all-commands {:workspace-folders []} {})] |
121 | 145 | (is (some #(= {:name "model" |
|
305 | 329 | :metrics (h/metrics)}) |
306 | 330 | text (get-in result [:chats "chat-1" :messages 0 :content 0 :text])] |
307 | 331 | (is (= "No rules available for the current agent and model." text)))))) |
| 332 | + |
| 333 | +(deftest extract-args-from-content-test |
| 334 | + (testing "detects $ARG1 placeholder" |
| 335 | + (is (= [{:name "arg1" :required true}] |
| 336 | + (shared/extract-args-from-content "Respond with $ARG1")))) |
| 337 | + |
| 338 | + (testing "detects multiple $ARGn placeholders" |
| 339 | + (is (= [{:name "arg1" :required true} |
| 340 | + {:name "arg2" :required true} |
| 341 | + {:name "arg3" :required true}] |
| 342 | + (shared/extract-args-from-content "First:$ARG1 Second:$ARG2 Third:$ARG3")))) |
| 343 | + |
| 344 | + (testing "detects $ARGS without $ARGn" |
| 345 | + (is (= [{:name "arg1" :required true}] |
| 346 | + (shared/extract-args-from-content "Use all args: $ARGS")))) |
| 347 | + |
| 348 | + (testing "detects $ARGUMENTS without $ARGn" |
| 349 | + (is (= [{:name "arg1" :required true}] |
| 350 | + (shared/extract-args-from-content "Process $ARGUMENTS here")))) |
| 351 | + |
| 352 | + (testing "detects Claude Code style $1 and $2" |
| 353 | + (is (= [{:name "arg1" :required true} |
| 354 | + {:name "arg2" :required true}] |
| 355 | + (shared/extract-args-from-content "First:$1 Second:$2")))) |
| 356 | + |
| 357 | + (testing "uses max of all placeholder styles" |
| 358 | + (is (= [{:name "arg1" :required true}] |
| 359 | + (shared/extract-args-from-content "$ARG1 $1")))) |
| 360 | + |
| 361 | + (testing "returns empty vector when no placeholders present" |
| 362 | + (is (= [] |
| 363 | + (shared/extract-args-from-content "No placeholders here")))) |
| 364 | + |
| 365 | + (testing "returns empty vector for nil/blank content" |
| 366 | + (is (= [] (shared/extract-args-from-content nil))) |
| 367 | + (is (= [] (shared/extract-args-from-content "")))) |
| 368 | + |
| 369 | + (testing "$ARGn takes precedence over $ARGS for argument count" |
| 370 | + (is (= [{:name "arg1" :required true}] |
| 371 | + (shared/extract-args-from-content "Single:$ARG1 All:$ARGS")))) |
| 372 | + |
| 373 | + (testing "detects $ARG10 and declares all args up to 10" |
| 374 | + (let [result (shared/extract-args-from-content "Use $ARG10")] |
| 375 | + (is (= 10 (count result))) |
| 376 | + (is (= {:name "arg1" :required true} (first result))) |
| 377 | + (is (= {:name "arg10" :required true} (last result)))))) |
0 commit comments