Skip to content

Commit 0831977

Browse files
committed
Fix tests
1 parent 56883c1 commit 0831977

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/eca/features/tools/filesystem.clj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@
4848
(defn ^:private read-file [arguments db]
4949
(or (invalid-arguments arguments (concat (path-validations db)
5050
[["path" fs/readable? "File $path is not readable"]]))
51-
(single-text-content (slurp (fs/file (fs/canonicalize (get arguments "path")))))))
51+
(let [head (get arguments "head")
52+
tail (get arguments "tail")
53+
content (cond-> (slurp (fs/file (fs/canonicalize (get arguments "path"))))
54+
head (->> (string/split-lines)
55+
(take head)
56+
(string/join "\n"))
57+
tail (->> (string/split-lines)
58+
(take-last tail)
59+
(string/join "\n")))]
60+
(single-text-content content))))
5261

5362
(def definitions
5463
{"list_allowed_directories"

src/eca/llm_providers/anthropic.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"tool_call_output"
7171
{:role "user"
7272
:content [{:type "tool_result"
73-
:tool-use-id (:id content)
73+
:tool_use_id (:id content)
7474
:content (llm-util/stringfy-tool-result content)}]}
7575
msg))
7676
past-messages)

test/eca/features/tools/filesystem_test.clj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,30 @@
7979
f.tools.filesystem/allowed-path? (constantly true)]
8080
((get-in f.tools.filesystem/definitions ["read_file" :handler])
8181
{"path" (h/file-path "/foo/qux")}
82+
{:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "baz"}]})))))
83+
(testing "heading a file"
84+
(is (match?
85+
{:contents [{:type :text
86+
:error false
87+
:content "fooo\nbar"}]}
88+
(with-redefs [slurp (constantly "fooo\nbar\nbaz")
89+
fs/exists? (constantly true)
90+
fs/readable? (constantly true)
91+
f.tools.filesystem/allowed-path? (constantly true)]
92+
((get-in f.tools.filesystem/definitions ["read_file" :handler])
93+
{"path" (h/file-path "/foo/qux")
94+
"head" 2}
95+
{:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "baz"}]})))))
96+
(testing "tailling a file"
97+
(is (match?
98+
{:contents [{:type :text
99+
:error false
100+
:content "bar\nbaz"}]}
101+
(with-redefs [slurp (constantly "fooo\nbar\nbaz")
102+
fs/exists? (constantly true)
103+
fs/readable? (constantly true)
104+
f.tools.filesystem/allowed-path? (constantly true)]
105+
((get-in f.tools.filesystem/definitions ["read_file" :handler])
106+
{"path" (h/file-path "/foo/qux")
107+
"tail" 2}
82108
{:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "baz"}]}))))))

test/eca/llm_providers/anthropic_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
:name "list_allowed_directories"
2828
:input {}}]}
2929
{:role "user" :content [{:type "tool_result"
30-
:tool-use-id "call-1"
30+
:tool_use_id "call-1"
3131
:content "Allowed directories: /foo/bar\n"}]}
3232
{:role "assistant" :content "I see /foo/bar"}
3333
{:role "user" :content [{:type :text :text "Thanks" :cache_control {:type "ephemeral"}}]}]

0 commit comments

Comments
 (0)