|
| 1 | +(ns clojure-mcp.core-test |
| 2 | + (:require [clojure.test :refer [deftest is testing]] |
| 3 | + [clojure-mcp.config :as config] |
| 4 | + [clojure-mcp.core])) |
| 5 | + |
| 6 | +(def ^:private apply-cli-config-overrides |
| 7 | + @#'clojure-mcp.core/apply-cli-config-overrides) |
| 8 | + |
| 9 | +(defn- make-client [config] |
| 10 | + {::config/config config}) |
| 11 | + |
| 12 | +(deftest enable-tools-override-test |
| 13 | + (testing ":enable-tools from opts replaces config value" |
| 14 | + (let [client (make-client {:enable-tools [:foo :bar]}) |
| 15 | + result (apply-cli-config-overrides client {:enable-tools [:baz]})] |
| 16 | + (is (= [:baz] (get-in result [::config/config :enable-tools]))))) |
| 17 | + |
| 18 | + (testing ":disable-tools from opts replaces config value" |
| 19 | + (let [client (make-client {:disable-tools [:foo]}) |
| 20 | + result (apply-cli-config-overrides client {:disable-tools [:bar :baz]})] |
| 21 | + (is (= [:bar :baz] (get-in result [::config/config :disable-tools])))))) |
| 22 | + |
| 23 | +(deftest remove-tools-test |
| 24 | + (testing ":remove-tools adds to :disable-tools" |
| 25 | + (let [client (make-client {:disable-tools [:foo]}) |
| 26 | + result (apply-cli-config-overrides client {:remove-tools [:bar]})] |
| 27 | + (is (= [:foo :bar] (get-in result [::config/config :disable-tools]))))) |
| 28 | + |
| 29 | + (testing ":remove-tools removes from :enable-tools" |
| 30 | + (let [client (make-client {:enable-tools [:foo :bar :baz]}) |
| 31 | + result (apply-cli-config-overrides client {:remove-tools [:bar]})] |
| 32 | + (is (= [:foo :baz] (get-in result [::config/config :enable-tools]))))) |
| 33 | + |
| 34 | + (testing ":remove-tools with no existing :disable-tools" |
| 35 | + (let [client (make-client {}) |
| 36 | + result (apply-cli-config-overrides client {:remove-tools [:foo]})] |
| 37 | + (is (= [:foo] (get-in result [::config/config :disable-tools]))))) |
| 38 | + |
| 39 | + (testing ":remove-tools does not create :enable-tools when nil" |
| 40 | + (let [client (make-client {}) |
| 41 | + result (apply-cli-config-overrides client {:remove-tools [:foo]})] |
| 42 | + (is (nil? (get-in result [::config/config :enable-tools])))))) |
| 43 | + |
| 44 | +(deftest add-tools-test |
| 45 | + (testing ":add-tools removes from :disable-tools" |
| 46 | + (let [client (make-client {:disable-tools [:foo :bar :baz]}) |
| 47 | + result (apply-cli-config-overrides client {:add-tools [:bar]})] |
| 48 | + (is (= [:foo :baz] (get-in result [::config/config :disable-tools]))))) |
| 49 | + |
| 50 | + (testing ":add-tools adds to :enable-tools when set" |
| 51 | + (let [client (make-client {:enable-tools [:foo]}) |
| 52 | + result (apply-cli-config-overrides client {:add-tools [:bar]})] |
| 53 | + (is (= [:foo :bar] (get-in result [::config/config :enable-tools]))))) |
| 54 | + |
| 55 | + (testing ":add-tools does not create :enable-tools when nil" |
| 56 | + (let [client (make-client {}) |
| 57 | + result (apply-cli-config-overrides client {:add-tools [:bar]})] |
| 58 | + (is (nil? (get-in result [::config/config :enable-tools])))))) |
| 59 | + |
| 60 | +(deftest add-tools-wins-over-remove-tools-test |
| 61 | + (testing ":add-tools wins over :remove-tools on overlap" |
| 62 | + (let [client (make-client {:enable-tools [:foo] |
| 63 | + :disable-tools [:baz]}) |
| 64 | + result (apply-cli-config-overrides client {:remove-tools [:bar :qux] |
| 65 | + :add-tools [:bar]})] |
| 66 | + ;; :bar should NOT be in :disable-tools (add-tools removed it) |
| 67 | + ;; :qux should be in :disable-tools (remove-tools added it, add-tools didn't touch it) |
| 68 | + (is (not (some #{:bar} (get-in result [::config/config :disable-tools])))) |
| 69 | + (is (some #{:qux} (get-in result [::config/config :disable-tools]))) |
| 70 | + ;; :bar should be in :enable-tools (add-tools added it back) |
| 71 | + (is (some #{:bar} (get-in result [::config/config :enable-tools])))))) |
| 72 | + |
| 73 | +(deftest combination-with-config-profile-test |
| 74 | + (testing "cli-assist profile with :add-tools re-enables a tool" |
| 75 | + ;; Simulate cli-assist having a limited enable-tools list |
| 76 | + (let [client (make-client {:enable-tools [:clojure_eval :read_file] |
| 77 | + :disable-tools []}) |
| 78 | + result (apply-cli-config-overrides client {:add-tools [:my_custom_agent]})] |
| 79 | + (is (some #{:my_custom_agent} (get-in result [::config/config :enable-tools]))))) |
| 80 | + |
| 81 | + (testing "cli-assist profile with :remove-tools disables a tool" |
| 82 | + (let [client (make-client {:enable-tools [:clojure_eval :read_file :bash] |
| 83 | + :disable-tools []}) |
| 84 | + result (apply-cli-config-overrides client {:remove-tools [:clojure_eval]})] |
| 85 | + (is (not (some #{:clojure_eval} (get-in result [::config/config :enable-tools])))) |
| 86 | + (is (some #{:clojure_eval} (get-in result [::config/config :disable-tools])))))) |
| 87 | + |
| 88 | +(deftest no-ops-test |
| 89 | + (testing "no opts produces no changes" |
| 90 | + (let [client (make-client {:enable-tools [:foo] :disable-tools [:bar]})] |
| 91 | + (is (= client (apply-cli-config-overrides client {}))))) |
| 92 | + |
| 93 | + (testing "string tool names are converted to keywords" |
| 94 | + (let [client (make-client {:disable-tools [:foo]}) |
| 95 | + result (apply-cli-config-overrides client {:remove-tools ["bar"]})] |
| 96 | + (is (= [:foo :bar] (get-in result [::config/config :disable-tools])))))) |
0 commit comments