|
| 1 | +(ns github.copilot-sdk.tool-set-test |
| 2 | + "Unit tests for github.copilot-sdk.tool-set — the source-qualified tool |
| 3 | + filter helpers introduced by upstream PR #1428." |
| 4 | + (:require [clojure.test :refer [deftest is testing]] |
| 5 | + [github.copilot-sdk.tool-set :as tool-set])) |
| 6 | + |
| 7 | +(deftest valid-name?-tests |
| 8 | + (testing "alphanumeric, underscore, hyphen are valid" |
| 9 | + (is (true? (tool-set/valid-name? "ask_user"))) |
| 10 | + (is (true? (tool-set/valid-name? "task-complete"))) |
| 11 | + (is (true? (tool-set/valid-name? "Tool123"))) |
| 12 | + (is (true? (tool-set/valid-name? "a")))) |
| 13 | + (testing "literal wildcard is valid" |
| 14 | + (is (true? (tool-set/valid-name? "*")))) |
| 15 | + (testing "wildcards in the middle of a name are invalid" |
| 16 | + (is (false? (tool-set/valid-name? "ask*")))) |
| 17 | + (testing "spaces, colons, dots, slashes are invalid" |
| 18 | + (is (false? (tool-set/valid-name? "ask user"))) |
| 19 | + (is (false? (tool-set/valid-name? "builtin:ask_user"))) |
| 20 | + (is (false? (tool-set/valid-name? "ask.user"))) |
| 21 | + (is (false? (tool-set/valid-name? "ask/user")))) |
| 22 | + (testing "empty string and non-strings are invalid" |
| 23 | + (is (false? (tool-set/valid-name? ""))) |
| 24 | + (is (false? (tool-set/valid-name? nil))) |
| 25 | + (is (false? (tool-set/valid-name? :ask_user))) |
| 26 | + (is (false? (tool-set/valid-name? 42))))) |
| 27 | + |
| 28 | +(deftest builtin-tests |
| 29 | + (testing "produces source-qualified pattern" |
| 30 | + (is (= "builtin:ask_user" (tool-set/builtin "ask_user"))) |
| 31 | + (is (= "builtin:*" (tool-set/builtin "*")))) |
| 32 | + (testing "rejects invalid name" |
| 33 | + (is (thrown-with-msg? clojure.lang.ExceptionInfo |
| 34 | + #"Invalid builtin tool name" |
| 35 | + (tool-set/builtin "bad name"))) |
| 36 | + (is (thrown-with-msg? clojure.lang.ExceptionInfo |
| 37 | + #"Invalid builtin tool name" |
| 38 | + (tool-set/builtin ""))))) |
| 39 | + |
| 40 | +(deftest mcp-tests |
| 41 | + (testing "produces source-qualified pattern" |
| 42 | + (is (= "mcp:my_server" (tool-set/mcp "my_server"))) |
| 43 | + (is (= "mcp:*" (tool-set/mcp "*")))) |
| 44 | + (testing "rejects invalid name" |
| 45 | + (is (thrown-with-msg? clojure.lang.ExceptionInfo |
| 46 | + #"Invalid mcp tool name" |
| 47 | + (tool-set/mcp "bad:name"))))) |
| 48 | + |
| 49 | +(deftest custom-tests |
| 50 | + (testing "produces source-qualified pattern" |
| 51 | + (is (= "custom:reviewer" (tool-set/custom "reviewer"))) |
| 52 | + (is (= "custom:*" (tool-set/custom "*")))) |
| 53 | + (testing "rejects invalid name" |
| 54 | + (is (thrown-with-msg? clojure.lang.ExceptionInfo |
| 55 | + #"Invalid custom tool name" |
| 56 | + (tool-set/custom "has space"))))) |
| 57 | + |
| 58 | +(deftest builtins-tests |
| 59 | + (testing "maps over names and returns a vector" |
| 60 | + (is (= ["builtin:task" "builtin:skill"] |
| 61 | + (tool-set/builtins ["task" "skill"]))) |
| 62 | + (is (vector? (tool-set/builtins ["task"])))) |
| 63 | + (testing "empty input yields empty vector" |
| 64 | + (is (= [] (tool-set/builtins [])))) |
| 65 | + (testing "throws on the first invalid entry" |
| 66 | + (is (thrown-with-msg? clojure.lang.ExceptionInfo |
| 67 | + #"Invalid builtin tool name" |
| 68 | + (tool-set/builtins ["ok" "bad name"]))))) |
| 69 | + |
| 70 | +(deftest isolated-builtins-tests |
| 71 | + (testing "matches upstream BuiltInTools.Isolated exactly" |
| 72 | + (is (= ["ask_user" |
| 73 | + "task_complete" |
| 74 | + "exit_plan_mode" |
| 75 | + "task" |
| 76 | + "read_agent" |
| 77 | + "write_agent" |
| 78 | + "list_agents" |
| 79 | + "send_inbox" |
| 80 | + "context_board" |
| 81 | + "skill"] |
| 82 | + tool-set/isolated-builtins)))) |
| 83 | + |
| 84 | +(deftest isolated-tests |
| 85 | + (testing "is the source-qualified form of isolated-builtins" |
| 86 | + (is (= (mapv #(str "builtin:" %) tool-set/isolated-builtins) |
| 87 | + tool-set/isolated))) |
| 88 | + (testing "every entry starts with builtin: prefix" |
| 89 | + (is (every? #(.startsWith ^String % "builtin:") tool-set/isolated)))) |
0 commit comments