Skip to content

Commit 0d9191f

Browse files
authored
Merge pull request #189 from lukaszkorecki/tweak-login-prompt-copy
Make it more clear how to use /login command and provide clear instructions
2 parents 966e325 + 7c148f5 commit 0d9191f

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Updated instructions for `/login` command and invalid input handling.
6+
57
## 0.75.4
68

79
- Fix 0.75.3 regression on custom openai-chat providers.

src/eca/features/login.clj

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
;; No provider selected
1515
(defmethod login-step [nil :login/start] [{:keys [db* chat-id input send-msg!] :as ctx}]
1616
(let [provider (string/trim input)
17-
providers (->> @db* :auth keys sort)]
17+
providers (->> @db* :auth keys sort)
18+
provider-list-str (reduce (fn [s p] (str s "- " p "\n")) "" providers)]
1819
(if (get-in @db* [:auth provider])
19-
(do (swap! db* assoc-in [:chats chat-id :login-provider] provider)
20-
(swap! db* assoc-in [:auth provider] {:step :login/start})
21-
(login-step (assoc ctx :provider provider)))
22-
(send-msg! (reduce
23-
(fn [s provider]
24-
(str s "- " provider "\n"))
25-
"Choose a provider:\n"
26-
providers)))))
20+
(do
21+
(swap! db* assoc-in [:chats chat-id :login-provider] provider)
22+
(swap! db* assoc-in [:auth provider] {:step :login/start})
23+
(login-step (assoc ctx :provider provider)))
24+
(if (string/blank? provider)
25+
(send-msg! (str "Please type the name of your chosen provider and press Enter:\n" provider-list-str))
26+
(send-msg! (str "Sorry, \"" provider "\" is not a valid provider.\n"
27+
"Please type the name of your chosen provider and press Enter:\n"
28+
provider-list-str))))))
2729

2830
(defn handle-step [{:keys [message chat-id]} db* messenger config metrics]
2931
(let [provider (get-in @db* [:chats chat-id :login-provider])

test/eca/features/login_test.clj

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
(ns eca.features.login-test
2+
(:require [clojure.test :refer [deftest is testing]]
3+
[eca.features.login :as login]
4+
[matcher-combinators.test :refer [match?]]))
5+
6+
(deftest test-login-step
7+
(let [msg-log (atom [])
8+
send-msg! (fn [msg] (swap! msg-log conj msg))
9+
10+
db* (atom {:auth {"google" {}
11+
"github-copilot" {}}
12+
:chats {1 {}}})]
13+
14+
(testing "user just typed /login for the first time"
15+
(login/login-step {:provider nil
16+
:step :login/start
17+
:chat-id 0
18+
:input ""
19+
:db* db*
20+
:send-msg! send-msg!})
21+
22+
(testing "should ask to choose a provider"
23+
(is (= "Please type the name of your chosen provider and press Enter:\n- github-copilot\n- google\n"
24+
(last @msg-log)))))
25+
26+
(testing "user is confused"
27+
(login/login-step {:provider nil
28+
:step :login/start
29+
:chat-id 0
30+
:input "/login github"
31+
:db* db*
32+
:send-msg! send-msg!})
33+
34+
(testing "should ask to choose a provider and provide instructions"
35+
(is (= "Sorry, \"/login github\" is not a valid provider.\nPlease type the name of your chosen provider and press Enter:\n- github-copilot\n- google\n"
36+
(last @msg-log)))
37+
38+
(testing "state didn't change"
39+
(is (= {:auth {"github-copilot" {}
40+
"google" {}}
41+
:chats {1 {}}}
42+
@db*)))))
43+
44+
(testing "valid input is provided"
45+
46+
(login/login-step {:provider nil
47+
:step :login/start
48+
:chat-id 0
49+
:input "github-copilot"
50+
:db* db*
51+
:send-msg! send-msg!})
52+
53+
(testing "should proceed to the next step"
54+
(is (re-find #"(?m)Open your browser at `https://github.com/login/device` and authenticate using the code: `.+`\nThen type anything in the chat and send it to continue the authentication."
55+
(last @msg-log)))
56+
57+
(testing "state is update to reflect in-progress login"
58+
(is (match? {:auth {"github-copilot" {;; skipping :device-code attr
59+
:step :login/waiting-user-confirmation}
60+
"google" {}}
61+
:chats {0 {:login-provider "github-copilot"}
62+
1 {}}}
63+
64+
@db*)))))))

0 commit comments

Comments
 (0)