|
| 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