|
1 | | -(ns eca.features.completion-test) |
| 1 | +(ns eca.features.completion-test |
| 2 | + (:require |
| 3 | + [clojure.test :refer [deftest is testing]] |
| 4 | + [eca.db :as db] |
| 5 | + [eca.features.completion :as f.completion] |
| 6 | + [eca.features.login :as f.login] |
| 7 | + [eca.llm-api :as llm-api] |
| 8 | + [eca.test-helper :as h])) |
| 9 | + |
| 10 | +(h/reset-components-before-test) |
| 11 | + |
| 12 | +(deftest complete-renews-expired-auth-test |
| 13 | + (testing "Renews expired auth before requesting inline completion" |
| 14 | + (h/reset-components!) |
| 15 | + (h/config! {:env "test" |
| 16 | + :completion {:model "github-copilot/gpt-4o" |
| 17 | + :systemPrompt "Complete the code."}}) |
| 18 | + (swap! (h/db*) assoc |
| 19 | + :models {"github-copilot/gpt-4o" {:reason? true |
| 20 | + :tools true |
| 21 | + :web-search true}}) |
| 22 | + (swap! (h/db*) assoc-in [:auth "github-copilot"] {:api-key "expired" |
| 23 | + :expires-at 1}) |
| 24 | + (let [login-ctx* (atom nil) |
| 25 | + api-opts* (atom nil) |
| 26 | + result (with-redefs [db/update-global-cache! (fn [& _] nil) |
| 27 | + f.login/login-step |
| 28 | + (fn [{:keys [db*] :as ctx}] |
| 29 | + (reset! login-ctx* ctx) |
| 30 | + (swap! db* assoc-in [:auth "github-copilot"] {:api-key "renewed" |
| 31 | + :expires-at 9999999999})) |
| 32 | + llm-api/sync-prompt! |
| 33 | + (fn [opts] |
| 34 | + (reset! api-opts* opts) |
| 35 | + {:output-text "completion"})] |
| 36 | + (f.completion/complete {:doc-text "abc" |
| 37 | + :doc-version 3 |
| 38 | + :position {:line 1 :character 4}} |
| 39 | + (h/db*) (h/config) (h/messenger) (h/metrics)))] |
| 40 | + (is (= "github-copilot" (:provider @login-ctx*))) |
| 41 | + (is (= :login/renew-token (:step @login-ctx*))) |
| 42 | + (is (= "github-copilot" (:provider @api-opts*))) |
| 43 | + (is (= "gpt-4o" (:model @api-opts*))) |
| 44 | + (is (= {:api-key "renewed" :expires-at 9999999999} (:provider-auth @api-opts*))) |
| 45 | + (is (= {:items [{:text "completion" |
| 46 | + :doc-version 3 |
| 47 | + :range {:start {:line 1 :character 4} |
| 48 | + :end {:line 1 :character 4}}}]} |
| 49 | + result))))) |
0 commit comments