Skip to content

Commit d03450b

Browse files
committed
Fix tests and shell output
1 parent 25c3707 commit d03450b

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

src/eca/features/tools/shell.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
{:error true
4242
:contents (remove nil?
4343
(concat [{:type :text
44-
:content (str "Exit code " (:exit result))}]
44+
:text (str "Exit code " (:exit result))}]
4545
(when-not (string/blank? err)
4646
[{:type :text
47-
:content (str "Stderr:\n" err)}])
47+
:text (str "Stderr:\n" err)}])
4848
(when-not (string/blank? out)
4949
[{:type :text
50-
:content (str "Stdout:\n" out)}])))})))))
50+
:text (str "Stdout:\n" out)}])))})))))
5151

5252
(def definitions
5353
{"eca_shell_command"

test/eca/features/tools/filesystem_test.clj

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(is (match?
1717
{:error true
1818
:contents [{:type :text
19-
:content (str (h/file-path "/foo/qux") " is not a valid path")}]}
19+
:text (str (h/file-path "/foo/qux") " is not a valid path")}]}
2020
(with-redefs [fs/canonicalize (constantly (h/file-path "/foo/qux"))
2121
fs/exists? (constantly false)]
2222
((get-in f.tools.filesystem/definitions ["eca_list_directory" :handler])
@@ -26,7 +26,7 @@
2626
(is (match?
2727
{:error true
2828
:contents [{:type :text
29-
:content (format "Access denied - path %s outside allowed directories: %s"
29+
:text (format "Access denied - path %s outside allowed directories: %s"
3030
(h/file-path "/foo/qux")
3131
(h/file-path "/foo/bar/baz"))}]}
3232
(with-redefs [fs/canonicalize (constantly (h/file-path "/foo/qux"))
@@ -38,7 +38,7 @@
3838
(is (match?
3939
{:error false
4040
:contents [{:type :text
41-
:content (format (str "[FILE] %s\n"
41+
:text (format (str "[FILE] %s\n"
4242
"[DIR] %s\n")
4343
(h/file-path "/foo/bar/baz/some.clj")
4444
(h/file-path "/foo/bar/baz/qux"))}]}
@@ -57,7 +57,7 @@
5757
(is (match?
5858
{:error true
5959
:contents [{:type :text
60-
:content (format "File %s is not readable" (h/file-path "/foo/qux"))}]}
60+
:text (format "File %s is not readable" (h/file-path "/foo/qux"))}]}
6161
(with-redefs [fs/exists? (constantly true)
6262
fs/readable? (constantly false)
6363
f.tools.filesystem/allowed-path? (constantly true)]
@@ -68,7 +68,7 @@
6868
(is (match?
6969
{:error false
7070
:contents [{:type :text
71-
:content "fooo"}]}
71+
:text "fooo"}]}
7272
(with-redefs [slurp (constantly "fooo")
7373
fs/exists? (constantly true)
7474
fs/readable? (constantly true)
@@ -80,7 +80,7 @@
8080
(is (match?
8181
{:error false
8282
:contents [{:type :text
83-
:content "line3\nline4\nline5"}]}
83+
:text "line3\nline4\nline5"}]}
8484
(with-redefs [slurp (constantly "line1\nline2\nline3\nline4\nline5")
8585
fs/exists? (constantly true)
8686
fs/readable? (constantly true)
@@ -92,7 +92,7 @@
9292
(is (match?
9393
{:error false
9494
:contents [{:type :text
95-
:content "line1\nline2"}]}
95+
:text "line1\nline2"}]}
9696
(with-redefs [slurp (constantly "line1\nline2\nline3\nline4\nline5")
9797
fs/exists? (constantly true)
9898
fs/readable? (constantly true)
@@ -104,7 +104,7 @@
104104
(is (match?
105105
{:error false
106106
:contents [{:type :text
107-
:content "line3\nline4"}]}
107+
:text "line3\nline4"}]}
108108
(with-redefs [slurp (constantly "line1\nline2\nline3\nline4\nline5")
109109
fs/exists? (constantly true)
110110
fs/readable? (constantly true)
@@ -118,7 +118,7 @@
118118
(is (match?
119119
{:error true
120120
:contents [{:type :text
121-
:content (format "Access denied - path %s outside allowed directories: %s"
121+
:text (format "Access denied - path %s outside allowed directories: %s"
122122
(h/file-path "/foo/qux/new_file.clj")
123123
(h/file-path "/foo/bar"))}]}
124124
(with-redefs [f.tools.filesystem/allowed-path? (constantly false)]
@@ -131,7 +131,7 @@
131131
(is (match?
132132
{:error true
133133
:contents [{:type :text
134-
:content "Invalid glob pattern ' '"}]}
134+
:text "Invalid glob pattern ' '"}]}
135135
(with-redefs [fs/exists? (constantly true)]
136136
((get-in f.tools.filesystem/definitions ["eca_search_files" :handler])
137137
{"path" (h/file-path "/project/foo")
@@ -141,7 +141,7 @@
141141
(is (match?
142142
{:error true
143143
:contents [{:type :text
144-
:content "No matches found"}]}
144+
:text "No matches found"}]}
145145
(with-redefs [fs/exists? (constantly true)
146146
fs/glob (constantly [])]
147147
((get-in f.tools.filesystem/definitions ["eca_search_files" :handler])
@@ -152,7 +152,7 @@
152152
(is (match?
153153
{:error false
154154
:contents [{:type :text
155-
:content (str (h/file-path "/project/foo/bar/baz.txt") "\n"
155+
:text (str (h/file-path "/project/foo/bar/baz.txt") "\n"
156156
(h/file-path "/project/foo/qux.txt") "\n"
157157
(h/file-path "/project/foo/qux.clj"))}]}
158158
(with-redefs [fs/exists? (constantly true)
@@ -167,7 +167,7 @@
167167
(is (match?
168168
{:error false
169169
:contents [{:type :text
170-
:content (str (h/file-path "/project/foo/bar/baz.txt") "\n"
170+
:text (str (h/file-path "/project/foo/bar/baz.txt") "\n"
171171
(h/file-path "/project/foo/qux.txt"))}]}
172172
(with-redefs [fs/exists? (constantly true)
173173
fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt"))
@@ -182,7 +182,7 @@
182182
(is (match?
183183
{:error true
184184
:contents [{:type :text
185-
:content "Invalid content regex pattern ' '"}]}
185+
:text "Invalid content regex pattern ' '"}]}
186186
(with-redefs [fs/exists? (constantly true)
187187
fs/readable? (constantly true)]
188188
((get-in f.tools.filesystem/definitions ["eca_grep" :handler])
@@ -193,7 +193,7 @@
193193
(is (match?
194194
{:error true
195195
:contents [{:type :text
196-
:content "Invalid file pattern ' '"}]}
196+
:text "Invalid file pattern ' '"}]}
197197
(with-redefs [fs/exists? (constantly true)
198198
fs/readable? (constantly true)]
199199
((get-in f.tools.filesystem/definitions ["eca_grep" :handler])
@@ -205,7 +205,7 @@
205205
(is (match?
206206
{:error true
207207
:contents [{:type :text
208-
:content "No files found for given pattern"}]}
208+
:text "No files found for given pattern"}]}
209209
(with-redefs [fs/exists? (constantly true)
210210
fs/readable? (constantly true)
211211
tools.util/command-available? (fn [command & _args] (= "rg" command))
@@ -218,7 +218,7 @@
218218
(is (match?
219219
{:error false
220220
:contents [{:type :text
221-
:content "/project/foo/bla.txt\n/project/foo/qux.txt"}]}
221+
:text "/project/foo/bla.txt\n/project/foo/qux.txt"}]}
222222
(with-redefs [fs/exists? (constantly true)
223223
fs/readable? (constantly true)
224224
tools.util/command-available? (fn [command & _args] (= "rg" command))
@@ -231,7 +231,7 @@
231231
(is (match?
232232
{:error false
233233
:contents [{:type :text
234-
:content "/project/foo/bla.txt\n/project/foo/qux.txt"}]}
234+
:text "/project/foo/bla.txt\n/project/foo/qux.txt"}]}
235235
(with-redefs [fs/exists? (constantly true)
236236
fs/readable? (constantly true)
237237
tools.util/command-available? (fn [command & _args] (= "grep" command))
@@ -244,7 +244,7 @@
244244
(is (match?
245245
{:error false
246246
:contents [{:type :text
247-
:content (h/file-path "/project/foo/bla.txt")}]}
247+
:text (h/file-path "/project/foo/bla.txt")}]}
248248
(with-redefs [fs/exists? (constantly true)
249249
fs/readable? (constantly true)
250250
tools.util/command-available? (constantly false)
@@ -264,7 +264,7 @@
264264
(is (match?
265265
{:error true
266266
:contents [{:type :text
267-
:content (format "File %s is not readable" (h/file-path "/foo/qux"))}]}
267+
:text (format "File %s is not readable" (h/file-path "/foo/qux"))}]}
268268
(with-redefs [fs/exists? (constantly true)
269269
fs/readable? (constantly false)
270270
f.tools.filesystem/allowed-path? (constantly true)]
@@ -277,7 +277,7 @@
277277
(is (match?
278278
{:error true
279279
:contents [{:type :text
280-
:content (format "Original content not found in %s" (h/file-path "/project/foo/my-file.txt"))}]}
280+
:text (format "Original content not found in %s" (h/file-path "/project/foo/my-file.txt"))}]}
281281
(with-redefs [fs/exists? (constantly true)
282282
fs/readable? (constantly true)
283283
f.tools.filesystem/allowed-path? (constantly true)
@@ -292,7 +292,7 @@
292292
(is (match?
293293
{:error false
294294
:contents [{:type :text
295-
:content (format "Successfully replaced content in %s." (h/file-path "/project/foo/my-file.txt"))}]}
295+
:text (format "Successfully replaced content in %s." (h/file-path "/project/foo/my-file.txt"))}]}
296296
(with-redefs [fs/exists? (constantly true)
297297
fs/readable? (constantly true)
298298
f.tools.filesystem/allowed-path? (constantly true)
@@ -311,7 +311,7 @@
311311
(is (match?
312312
{:error false
313313
:contents [{:type :text
314-
:content (format "Successfully replaced content in %s." (h/file-path "/project/foo/my-file.txt"))}]}
314+
:text (format "Successfully replaced content in %s." (h/file-path "/project/foo/my-file.txt"))}]}
315315
(with-redefs [fs/exists? (constantly true)
316316
fs/readable? (constantly true)
317317
f.tools.filesystem/allowed-path? (constantly true)
@@ -332,7 +332,7 @@
332332
(is (match?
333333
{:error true
334334
:contents [{:type :text
335-
:content (format "%s is not a valid path" (h/file-path "/foo/qux"))}]}
335+
:text (format "%s is not a valid path" (h/file-path "/foo/qux"))}]}
336336
(with-redefs [fs/exists? (constantly false)
337337
f.tools.filesystem/allowed-path? (constantly true)]
338338
((get-in f.tools.filesystem/definitions ["eca_move_file" :handler])
@@ -342,7 +342,7 @@
342342
(is (match?
343343
{:error true
344344
:contents [{:type :text
345-
:content (format "Path %s already exists" (h/file-path "/foo/bar/other_file.clj"))}]}
345+
:text (format "Path %s already exists" (h/file-path "/foo/bar/other_file.clj"))}]}
346346
(with-redefs [fs/exists? (constantly true)
347347
f.tools.filesystem/allowed-path? (constantly true)]
348348
((get-in f.tools.filesystem/definitions ["eca_move_file" :handler])
@@ -353,7 +353,7 @@
353353
(is (match?
354354
{:error false
355355
:contents [{:type :text
356-
:content (format "Successfully moved %s to %s"
356+
:text (format "Successfully moved %s to %s"
357357
(h/file-path "/foo/bar/some_file.clj")
358358
(h/file-path "/foo/bar/other_file.clj"))}]}
359359
(with-redefs [fs/exists? (fn [path] (not (string/includes? path "other_file.clj")))

test/eca/features/tools/shell_test.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(is (match?
1313
{:error true
1414
:contents [{:type :text
15-
:content (format "working directory %s does not exist" (h/file-path "/baz"))}]}
15+
:text (format "working directory %s does not exist" (h/file-path "/baz"))}]}
1616
(with-redefs [fs/exists? (constantly false)]
1717
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
1818
{"command" "ls -lh"
@@ -22,9 +22,9 @@
2222
(is (match?
2323
{:error true
2424
:contents [{:type :text
25-
:content "Exit code 1"}
25+
:text "Exit code 1"}
2626
{:type :text
27-
:content "Stderr:\nSome error"}]}
27+
:text "Stderr:\nSome error"}]}
2828
(with-redefs [fs/exists? (constantly true)
2929
shell/sh (constantly {:exit 1 :err "Some error"})]
3030
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
@@ -34,7 +34,7 @@
3434
(is (match?
3535
{:error false
3636
:contents [{:type :text
37-
:content "Some text"}]}
37+
:text "Some text"}]}
3838
(with-redefs [fs/exists? (constantly true)
3939
shell/sh (constantly {:exit 0 :out "Some text" :err "Other text"})]
4040
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
@@ -44,7 +44,7 @@
4444
(is (match?
4545
{:error false
4646
:contents [{:type :text
47-
:content "Some text"}]}
47+
:text "Some text"}]}
4848
(with-redefs [fs/exists? (constantly true)
4949
shell/sh (constantly {:exit 0 :out "Some text" :err "Other text"})]
5050
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
@@ -55,7 +55,7 @@
5555
(is (match?
5656
{:error false
5757
:contents [{:type :text
58-
:content "Some text"}]}
58+
:text "Some text"}]}
5959
(with-redefs [fs/exists? (constantly true)
6060
shell/sh (constantly {:exit 0 :out "Some text" :err "Other text"})]
6161
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
@@ -67,7 +67,7 @@
6767
(is (match?
6868
{:error true
6969
:contents [{:type :text
70-
:content "Cannot run command 'rm' because it is excluded by eca config."}]}
70+
:text "Cannot run command 'rm' because it is excluded by eca config."}]}
7171
(with-redefs [fs/exists? (constantly true)]
7272
((get-in f.tools.shell/definitions ["eca_shell_command" :handler])
7373
{"command" "rm -r /project/foo/src"}

0 commit comments

Comments
 (0)