Skip to content

Commit 76cc499

Browse files
committed
Add integration tests
1 parent 0e35719 commit 76cc499

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

integration-test/entrypoint.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
integration.chat.ollama-test
1515
integration.chat.custom-provider-test
1616
integration.chat.commands-test
17-
])
17+
integration.rewrite.openai-test])
1818

1919
(defn timeout [timeout-ms callback]
2020
(let [fut (future (callback))

integration-test/integration/fixture.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
:key "foo-key"
1919
:keyEnv "FOO"}
2020
"google" {:url (str base-llm-mock-url "/google")
21-
:key "foo-key"
22-
:keyEnv "FOO"}})
21+
:key "foo-key"
22+
:keyEnv "FOO"}})
2323

2424
(def default-init-options {:pureConfig true
2525
:env "test"
@@ -53,3 +53,6 @@
5353

5454
(defn chat-query-commands-request [params]
5555
[:chat/queryCommands params])
56+
57+
(defn rewrite-prompt-request [params]
58+
[:rewrite/prompt params])

integration-test/integration/helper.clj

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
;; Do a better escape considering more chars
4444
(cond-> (string/replace uri "::" "%3A%3A")
4545
windows?
46-
(string/replace #"/([a-zA-Z]):/" "/$1%3A/")))
46+
(string/replace #"/([a-zA-Z]):/" "/$1%3A/")))
4747

4848
(defn json-escape-path
4949
"Escapes the filesystem PATH string for safe use in JSON and returns the
@@ -66,7 +66,13 @@
6666

6767
(defn match-content [chat-id role content]
6868
(is (match?
69-
{:chatId chat-id
70-
:role role
71-
:content content}
72-
(eca/client-awaits-server-notification :chat/contentReceived))))
69+
{:chatId chat-id
70+
:role role
71+
:content content}
72+
(eca/client-awaits-server-notification :chat/contentReceived))))
73+
74+
(defn match-rewrite-content [rewrite-id content]
75+
(is (match?
76+
{:rewriteId rewrite-id
77+
:content content}
78+
(eca/client-awaits-server-notification :rewrite/contentReceived))))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(ns integration.rewrite.openai-test
2+
(:require
3+
[clojure.test :refer [deftest is testing]]
4+
[integration.eca :as eca]
5+
[integration.fixture :as fixture]
6+
[integration.helper :refer [match-rewrite-content]]
7+
[llm-mock.mocks :as llm.mocks]
8+
[matcher-combinators.matchers :as m]
9+
[matcher-combinators.test :refer [match?]]))
10+
11+
(eca/clean-after-test)
12+
13+
(deftest basic-rewrite-openai
14+
(eca/start-process!)
15+
16+
;; initialize server with rewrite model set to openai to hit the openai mock
17+
(let [init-opts (assoc-in fixture/default-init-options [:rewrite :model] "openai/gpt-4.1")]
18+
(eca/request! (fixture/initialize-request {:initializationOptions init-opts
19+
:capabilities {:codeAssistant {:chat {}}}})))
20+
(eca/notify! (fixture/initialized-notification))
21+
22+
(testing "Rewrite streams text and finishes, and body contains user prompt input"
23+
(llm.mocks/set-case! :simple-text-0)
24+
(let [resp (eca/request! (fixture/rewrite-prompt-request
25+
{:id "rw-1"
26+
:prompt "Please rewrite"
27+
:text "Original text"
28+
:range {:start {:line 1 :character 0}
29+
:end {:line 1 :character 13}}}))]
30+
(is (match?
31+
{:model "openai/gpt-4.1"
32+
:status "prompting"}
33+
resp))
34+
35+
;; rewrite/contentReceived notifications
36+
(match-rewrite-content "rw-1" {:type "started"})
37+
(match-rewrite-content "rw-1" {:type "text" :text "Knock"})
38+
(match-rewrite-content "rw-1" {:type "text" :text " knock!"})
39+
(match-rewrite-content "rw-1" {:type "finished" :totalTimeMs (m/pred number?)})
40+
41+
;; Verify request body sent to mock: user input contains the prompt we sent
42+
(is (match?
43+
{:input [{:role "user"
44+
:content [{:type "input_text" :text "Please rewrite"}]}]
45+
:instructions (m/pred string?)}
46+
(llm.mocks/get-req-body :simple-text-0))))))

0 commit comments

Comments
 (0)