Skip to content

The agent that grows with you

fix(setup): a name typed in the composer is the name answer

alt-glitchf9bbee247f1c
diff --git a/tests/tools/test_setup_choose_name_card.py b/tests/tools/test_setup_choose_name_card.py
index a61f012188a..0bd73061f4c 100644
--- a/tests/tools/test_setup_choose_name_card.py
+++ b/tests/tools/test_setup_choose_name_card.py
@@ -9,7 +9,7 @@ from tools.setup_choose_tool import setup_choose_tool
NAME = "Ada Lovelace"
-def _ask(monkeypatch, reply):
+def _ask(monkeypatch, reply, session_id=None):
monkeypatch.setattr(initiate_setup_facts, "suggested_name", lambda: NAME)
shown = []
@@ -17,7 +17,8 @@ def _ask(monkeypatch, reply):
shown.append(payload)
return reply
- result = setup_choose_tool(kind="question", question=NAME_QUESTION, options=[], callback=callback)
+ result = setup_choose_tool(kind="question", question=NAME_QUESTION, options=[], callback=callback,
+ session_id=session_id)
return shown[0], json.loads(result)
@@ -39,3 +40,16 @@ def test_facts_and_the_scripted_card_leave_the_name_out(monkeypatch):
assert NAME not in json.dumps(card)
line, _tool, _card = opening.send(json.dumps({"outcome": "submitted", "picked": "suggested", "label": NAME}))
assert line == f"Good to meet you, {NAME}."
+
+
+def test_a_name_typed_in_the_composer_is_the_name_answer(monkeypatch):
+ from hermes_cli.setup_profile import read_cards
+
+ _, typed = _ask(monkeypatch, {"said": "Ada"}, session_id="setup-typed-name")
+ assert (typed["outcome"], typed["picked"]) == ("submitted", "Ada")
+ assert read_cards("setup-typed-name")["picks"]["name"] == "Ada"
+
+ opening = _opening(set(), {})
+ next(opening)
+ line, _tool, card = opening.send(json.dumps(typed))
+ assert (line, card["kind"]) == ("Good to meet you, Ada.", "accent")
diff --git a/tools/setup_choose_tool.py b/tools/setup_choose_tool.py
index 09521c844c8..3717fcb79cc 100644
--- a/tools/setup_choose_tool.py
+++ b/tools/setup_choose_tool.py
@@ -267,6 +267,9 @@ def setup_choose_tool(kind: str = "", question: str = "", options=None, multi_se
payload.update(options=_name_rows(), multi_select=False)
reply = callback(payload)
result = _result(reply, payload["options"])
+ if kind == "question" and text == NAME_QUESTION and result["outcome"] == "typed":
+ # The composer answers the name card like its free-text field: the words are the name, not a missed row.
+ result = {"outcome": "submitted", "picked": result["said"]}
extra, state = _follow_up(kind, card, result, payload["options"], cards)
state = _remember(kind, text, result, state)
if session_id and state != cards: