|
103 | 103 | "tail" 2} |
104 | 104 | {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]})))))) |
105 | 105 |
|
106 | | -(deftest search-files-test |
107 | | - (testing "invalid pattern" |
| 106 | +(deftest write-file-test |
| 107 | + (testing "Not allowed path" |
108 | 108 | (is (match? |
109 | 109 | {:contents [{:type :text |
110 | 110 | :error true |
111 | | - :content "Invalid glob pattern ' '"}]} |
112 | | - (with-redefs [fs/exists? (constantly true)] |
113 | | - ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
114 | | - {"path" (h/file-path "/project/foo") |
115 | | - "pattern" " "} |
116 | | - {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}))))) |
| 111 | + :content (format "Access denied - path %s outside allowed directories: %s" |
| 112 | + (h/file-path "/foo/qux/new_file.clj") |
| 113 | + (h/file-path "/foo/bar"))}]} |
| 114 | + (with-redefs [f.tools.filesystem/allowed-path? (constantly false)] |
| 115 | + ((get-in f.tools.filesystem/definitions ["write_file" :handler]) |
| 116 | + {"path" (h/file-path "/foo/qux/new_file.clj")} |
| 117 | + {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "bar"}]})))))) |
| 118 | + |
| 119 | +(deftest search-files-test |
| 120 | + (testing "invalid pattern" |
| 121 | + (is (match? |
| 122 | + {:contents [{:type :text |
| 123 | + :error true |
| 124 | + :content "Invalid glob pattern ' '"}]} |
| 125 | + (with-redefs [fs/exists? (constantly true)] |
| 126 | + ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
| 127 | + {"path" (h/file-path "/project/foo") |
| 128 | + "pattern" " "} |
| 129 | + {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}))))) |
117 | 130 | (testing "no matches" |
118 | 131 | (is (match? |
119 | | - {:contents [{:type :text |
120 | | - :error false |
121 | | - :content "No matches found"}]} |
122 | | - (with-redefs [fs/exists? (constantly true) |
123 | | - fs/glob (constantly [])] |
124 | | - ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
125 | | - {"path" (h/file-path "/project/foo") |
126 | | - "pattern" "foo"} |
127 | | - {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}))))) |
| 132 | + {:contents [{:type :text |
| 133 | + :error false |
| 134 | + :content "No matches found"}]} |
| 135 | + (with-redefs [fs/exists? (constantly true) |
| 136 | + fs/glob (constantly [])] |
| 137 | + ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
| 138 | + {"path" (h/file-path "/project/foo") |
| 139 | + "pattern" "foo"} |
| 140 | + {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}))))) |
128 | 141 | (testing "matches with wildcard" |
129 | 142 | (is (match? |
130 | | - {:contents [{:type :text |
131 | | - :error false |
132 | | - :content (str (h/file-path "/project/foo/bar/baz.txt") "\n" |
133 | | - (h/file-path "/project/foo/qux.txt") "\n" |
134 | | - (h/file-path "/project/foo/qux.clj"))}]} |
135 | | - (with-redefs [fs/exists? (constantly true) |
136 | | - fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
137 | | - (fs/path (h/file-path "/project/foo/qux.txt")) |
138 | | - (fs/path (h/file-path "/project/foo/qux.clj"))])] |
139 | | - ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
140 | | - {"path" (h/file-path "/project/foo") |
141 | | - "pattern" "**"} |
142 | | - {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}))))) |
| 143 | + {:contents [{:type :text |
| 144 | + :error false |
| 145 | + :content (str (h/file-path "/project/foo/bar/baz.txt") "\n" |
| 146 | + (h/file-path "/project/foo/qux.txt") "\n" |
| 147 | + (h/file-path "/project/foo/qux.clj"))}]} |
| 148 | + (with-redefs [fs/exists? (constantly true) |
| 149 | + fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
| 150 | + (fs/path (h/file-path "/project/foo/qux.txt")) |
| 151 | + (fs/path (h/file-path "/project/foo/qux.clj"))])] |
| 152 | + ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
| 153 | + {"path" (h/file-path "/project/foo") |
| 154 | + "pattern" "**"} |
| 155 | + {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}))))) |
143 | 156 | (testing "matches without wildcard" |
144 | 157 | (is (match? |
145 | | - {:contents [{:type :text |
146 | | - :error false |
147 | | - :content (str (h/file-path "/project/foo/bar/baz.txt") "\n" |
148 | | - (h/file-path "/project/foo/qux.txt"))}]} |
149 | | - (with-redefs [fs/exists? (constantly true) |
150 | | - fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
151 | | - (fs/path (h/file-path "/project/foo/qux.txt"))])] |
152 | | - ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
153 | | - {"path" (h/file-path "/project/foo") |
154 | | - "pattern" ".txt"} |
155 | | - {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]})))))) |
| 158 | + {:contents [{:type :text |
| 159 | + :error false |
| 160 | + :content (str (h/file-path "/project/foo/bar/baz.txt") "\n" |
| 161 | + (h/file-path "/project/foo/qux.txt"))}]} |
| 162 | + (with-redefs [fs/exists? (constantly true) |
| 163 | + fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
| 164 | + (fs/path (h/file-path "/project/foo/qux.txt"))])] |
| 165 | + ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
| 166 | + {"path" (h/file-path "/project/foo") |
| 167 | + "pattern" ".txt"} |
| 168 | + {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]})))))) |
156 | 169 |
|
157 | 170 | (deftest grep-test |
158 | 171 | (testing "invalid pattern" |
|
0 commit comments