|
19 | 19 | :content (str (h/file-path "/foo/qux") " is not a valid path")}]} |
20 | 20 | (with-redefs [fs/canonicalize (constantly (h/file-path "/foo/qux")) |
21 | 21 | fs/exists? (constantly false)] |
22 | | - ((get-in f.tools.filesystem/definitions ["list_directory" :handler]) |
| 22 | + ((get-in f.tools.filesystem/definitions ["eca_list_directory" :handler]) |
23 | 23 | {"path" (h/file-path "/foo/qux")} |
24 | 24 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
25 | 25 | (testing "Unallowed dir" |
|
31 | 31 | (h/file-path "/foo/bar/baz"))}]} |
32 | 32 | (with-redefs [fs/canonicalize (constantly (h/file-path "/foo/qux")) |
33 | 33 | fs/exists? (constantly true)] |
34 | | - ((get-in f.tools.filesystem/definitions ["list_directory" :handler]) |
| 34 | + ((get-in f.tools.filesystem/definitions ["eca_list_directory" :handler]) |
35 | 35 | {"path" (h/file-path "/foo/qux")} |
36 | 36 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
37 | 37 | (testing "allowed dir" |
|
48 | 48 | (fs/path (h/file-path "/foo/bar/baz/qux"))]) |
49 | 49 | fs/directory? (fn [path] (not (string/ends-with? (str path) ".clj"))) |
50 | 50 | fs/canonicalize (constantly (h/file-path "/foo/bar/baz"))] |
51 | | - ((get-in f.tools.filesystem/definitions ["list_directory" :handler]) |
| 51 | + ((get-in f.tools.filesystem/definitions ["eca_list_directory" :handler]) |
52 | 52 | {"path" (h/file-path "/foo/bar/baz")} |
53 | 53 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}})))))) |
54 | 54 |
|
|
61 | 61 | (with-redefs [fs/exists? (constantly true) |
62 | 62 | fs/readable? (constantly false) |
63 | 63 | f.tools.filesystem/allowed-path? (constantly true)] |
64 | | - ((get-in f.tools.filesystem/definitions ["read_file" :handler]) |
| 64 | + ((get-in f.tools.filesystem/definitions ["eca_read_file" :handler]) |
65 | 65 | {"path" (h/file-path "/foo/qux")} |
66 | 66 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
67 | 67 | (testing "Readable path" |
|
73 | 73 | fs/exists? (constantly true) |
74 | 74 | fs/readable? (constantly true) |
75 | 75 | f.tools.filesystem/allowed-path? (constantly true)] |
76 | | - ((get-in f.tools.filesystem/definitions ["read_file" :handler]) |
| 76 | + ((get-in f.tools.filesystem/definitions ["eca_read_file" :handler]) |
77 | 77 | {"path" (h/file-path "/foo/qux")} |
78 | 78 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
79 | 79 | (testing "heading a file" |
|
85 | 85 | fs/exists? (constantly true) |
86 | 86 | fs/readable? (constantly true) |
87 | 87 | f.tools.filesystem/allowed-path? (constantly true)] |
88 | | - ((get-in f.tools.filesystem/definitions ["read_file" :handler]) |
| 88 | + ((get-in f.tools.filesystem/definitions ["eca_read_file" :handler]) |
89 | 89 | {"path" (h/file-path "/foo/qux") |
90 | 90 | "head" 2} |
91 | 91 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
|
98 | 98 | fs/exists? (constantly true) |
99 | 99 | fs/readable? (constantly true) |
100 | 100 | f.tools.filesystem/allowed-path? (constantly true)] |
101 | | - ((get-in f.tools.filesystem/definitions ["read_file" :handler]) |
| 101 | + ((get-in f.tools.filesystem/definitions ["eca_read_file" :handler]) |
102 | 102 | {"path" (h/file-path "/foo/qux") |
103 | 103 | "tail" 2} |
104 | 104 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}})))))) |
|
112 | 112 | (h/file-path "/foo/qux/new_file.clj") |
113 | 113 | (h/file-path "/foo/bar"))}]} |
114 | 114 | (with-redefs [f.tools.filesystem/allowed-path? (constantly false)] |
115 | | - ((get-in f.tools.filesystem/definitions ["write_file" :handler]) |
| 115 | + ((get-in f.tools.filesystem/definitions ["eca_write_file" :handler]) |
116 | 116 | {"path" (h/file-path "/foo/qux/new_file.clj")} |
117 | 117 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "bar"}]}})))))) |
118 | 118 |
|
|
123 | 123 | :error true |
124 | 124 | :content "Invalid glob pattern ' '"}]} |
125 | 125 | (with-redefs [fs/exists? (constantly true)] |
126 | | - ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
| 126 | + ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
127 | 127 | {"path" (h/file-path "/project/foo") |
128 | 128 | "pattern" " "} |
129 | 129 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
|
134 | 134 | :content "No matches found"}]} |
135 | 135 | (with-redefs [fs/exists? (constantly true) |
136 | 136 | fs/glob (constantly [])] |
137 | | - ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
| 137 | + ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
138 | 138 | {"path" (h/file-path "/project/foo") |
139 | 139 | "pattern" "foo"} |
140 | 140 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
|
149 | 149 | fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
150 | 150 | (fs/path (h/file-path "/project/foo/qux.txt")) |
151 | 151 | (fs/path (h/file-path "/project/foo/qux.clj"))])] |
152 | | - ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
| 152 | + ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
153 | 153 | {"path" (h/file-path "/project/foo") |
154 | 154 | "pattern" "**"} |
155 | 155 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
|
162 | 162 | (with-redefs [fs/exists? (constantly true) |
163 | 163 | fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
164 | 164 | (fs/path (h/file-path "/project/foo/qux.txt"))])] |
165 | | - ((get-in f.tools.filesystem/definitions ["search_files" :handler]) |
| 165 | + ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
166 | 166 | {"path" (h/file-path "/project/foo") |
167 | 167 | "pattern" ".txt"} |
168 | 168 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}})))))) |
|
175 | 175 | :content "Invalid content regex pattern ' '"}]} |
176 | 176 | (with-redefs [fs/exists? (constantly true) |
177 | 177 | fs/readable? (constantly true)] |
178 | | - ((get-in f.tools.filesystem/definitions ["grep" :handler]) |
| 178 | + ((get-in f.tools.filesystem/definitions ["eca_grep" :handler]) |
179 | 179 | {"path" (h/file-path "/project/foo") |
180 | 180 | "pattern" " "} |
181 | 181 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
|
186 | 186 | :content "Invalid file pattern ' '"}]} |
187 | 187 | (with-redefs [fs/exists? (constantly true) |
188 | 188 | fs/readable? (constantly true)] |
189 | | - ((get-in f.tools.filesystem/definitions ["grep" :handler]) |
| 189 | + ((get-in f.tools.filesystem/definitions ["eca_grep" :handler]) |
190 | 190 | {"path" (h/file-path "/project/foo") |
191 | 191 | "pattern" ".*" |
192 | 192 | "include" " "} |
|
200 | 200 | fs/readable? (constantly true) |
201 | 201 | tools.util/command-available? (fn [command & _args] (= "rg" command)) |
202 | 202 | shell/sh (constantly {:out ""})] |
203 | | - ((get-in f.tools.filesystem/definitions ["grep" :handler]) |
| 203 | + ((get-in f.tools.filesystem/definitions ["eca_grep" :handler]) |
204 | 204 | {"path" (h/file-path "/project/foo") |
205 | 205 | "pattern" ".*"} |
206 | 206 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
|
213 | 213 | fs/readable? (constantly true) |
214 | 214 | tools.util/command-available? (fn [command & _args] (= "rg" command)) |
215 | 215 | shell/sh (constantly {:out "/project/foo/bla.txt\n/project/foo/qux.txt"})] |
216 | | - ((get-in f.tools.filesystem/definitions ["grep" :handler]) |
| 216 | + ((get-in f.tools.filesystem/definitions ["eca_grep" :handler]) |
217 | 217 | {"path" (h/file-path "/project/foo") |
218 | 218 | "pattern" "some-cool-content"} |
219 | 219 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
|
226 | 226 | fs/readable? (constantly true) |
227 | 227 | tools.util/command-available? (fn [command & _args] (= "grep" command)) |
228 | 228 | shell/sh (constantly {:out "/project/foo/bla.txt\n/project/foo/qux.txt"})] |
229 | | - ((get-in f.tools.filesystem/definitions ["grep" :handler]) |
| 229 | + ((get-in f.tools.filesystem/definitions ["eca_grep" :handler]) |
230 | 230 | {"path" (h/file-path "/project/foo") |
231 | 231 | "pattern" "some-cool-content"} |
232 | 232 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
|
244 | 244 | fs/directory? (constantly false) |
245 | 245 | fs/hidden? (constantly false) |
246 | 246 | fs/file (constantly (ByteArrayInputStream. (.getBytes "some-cool-content")))] |
247 | | - ((get-in f.tools.filesystem/definitions ["grep" :handler]) |
| 247 | + ((get-in f.tools.filesystem/definitions ["eca_grep" :handler]) |
248 | 248 | {"path" (h/file-path "/project/foo") |
249 | 249 | "pattern" "some-cool-content"} |
250 | 250 | {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}})))))) |
|
258 | 258 | (with-redefs [fs/exists? (constantly true) |
259 | 259 | fs/readable? (constantly false) |
260 | 260 | f.tools.filesystem/allowed-path? (constantly true)] |
261 | | - ((get-in f.tools.filesystem/definitions ["replace_in_file" :handler]) |
| 261 | + ((get-in f.tools.filesystem/definitions ["eca_replace_in_file" :handler]) |
262 | 262 | {"path" (h/file-path "/foo/qux") |
263 | 263 | "original_content" "some-cool-text" |
264 | 264 | "new_content" "another-boring-text"} |
|
272 | 272 | fs/readable? (constantly true) |
273 | 273 | f.tools.filesystem/allowed-path? (constantly true) |
274 | 274 | slurp (constantly "Hey, here is some-cool-text in this file!")] |
275 | | - ((get-in f.tools.filesystem/definitions ["replace_in_file" :handler]) |
| 275 | + ((get-in f.tools.filesystem/definitions ["eca_replace_in_file" :handler]) |
276 | 276 | {"path" (h/file-path "/project/foo/my-file.txt") |
277 | 277 | "original_content" "other-cool-text" |
278 | 278 | "new_content" "another-boring-text"} |
|
288 | 288 | f.tools.filesystem/allowed-path? (constantly true) |
289 | 289 | slurp (constantly "Hey, here is some-cool-text in this file! here as well: some-cool-text") |
290 | 290 | spit (fn [f content] (swap! file-content* assoc f content))] |
291 | | - ((get-in f.tools.filesystem/definitions ["replace_in_file" :handler]) |
| 291 | + ((get-in f.tools.filesystem/definitions ["eca_replace_in_file" :handler]) |
292 | 292 | {"path" (h/file-path "/project/foo/my-file.txt") |
293 | 293 | "original_content" "some-cool-text" |
294 | 294 | "new_content" "another-boring-text"} |
|
307 | 307 | f.tools.filesystem/allowed-path? (constantly true) |
308 | 308 | slurp (constantly "Hey, here is some-cool-text in this file! here as well: some-cool-text") |
309 | 309 | spit (fn [f content] (swap! file-content* assoc f content))] |
310 | | - ((get-in f.tools.filesystem/definitions ["replace_in_file" :handler]) |
| 310 | + ((get-in f.tools.filesystem/definitions ["eca_replace_in_file" :handler]) |
311 | 311 | {"path" (h/file-path "/project/foo/my-file.txt") |
312 | 312 | "original_content" "some-cool-text" |
313 | 313 | "new_content" "another-boring-text" |
|
325 | 325 | :content (format "%s is not a valid path" (h/file-path "/foo/qux"))}]} |
326 | 326 | (with-redefs [fs/exists? (constantly false) |
327 | 327 | f.tools.filesystem/allowed-path? (constantly true)] |
328 | | - ((get-in f.tools.filesystem/definitions ["move_file" :handler]) |
| 328 | + ((get-in f.tools.filesystem/definitions ["eca_move_file" :handler]) |
329 | 329 | {"source" (h/file-path "/foo/qux")} |
330 | 330 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
331 | 331 | (testing "Destination already exists" |
|
335 | 335 | :content (format "Path %s already exists" (h/file-path "/foo/bar/other_file.clj"))}]} |
336 | 336 | (with-redefs [fs/exists? (constantly true) |
337 | 337 | f.tools.filesystem/allowed-path? (constantly true)] |
338 | | - ((get-in f.tools.filesystem/definitions ["move_file" :handler]) |
| 338 | + ((get-in f.tools.filesystem/definitions ["eca_move_file" :handler]) |
339 | 339 | {"source" (h/file-path "/foo/bar/some_file.clj") |
340 | 340 | "destination" (h/file-path "/foo/bar/other_file.clj")} |
341 | 341 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}}))))) |
|
349 | 349 | (with-redefs [fs/exists? (fn [path] (not (string/includes? path "other_file.clj"))) |
350 | 350 | f.tools.filesystem/allowed-path? (constantly true) |
351 | 351 | fs/move (constantly true)] |
352 | | - ((get-in f.tools.filesystem/definitions ["move_file" :handler]) |
| 352 | + ((get-in f.tools.filesystem/definitions ["eca_move_file" :handler]) |
353 | 353 | {"source" (h/file-path "/foo/bar/some_file.clj") |
354 | 354 | "destination" (h/file-path "/foo/bar/other_file.clj")} |
355 | 355 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))))) |
0 commit comments