diff --git a/ovos_core/intent_services/converse_service.py b/ovos_core/intent_services/converse_service.py index 5051bab16e4..3bbec657c7c 100644 --- a/ovos_core/intent_services/converse_service.py +++ b/ovos_core/intent_services/converse_service.py @@ -219,6 +219,9 @@ def _collect_converse_skills(self, message): active_skills = self.get_active_skills() + if not active_skills: + return want_converse + event = Event() def handle_ack(msg): @@ -240,7 +243,10 @@ def handle_ack(msg): self.bus.on("skill.converse.pong", handle_ack) - self.bus.emit(message.forward("skill.converse.ping")) + # ask skills if they want to converse + for skill_id in active_skills: + self.bus.emit(message.forward(f"{skill_id}.converse.ping", + {"skill_id": skill_id})) # wait for all skills to acknowledge they want to converse event.wait(timeout=0.5) @@ -275,17 +281,15 @@ def converse(self, utterances, skill_id, lang, message): state = session.utterance_states.get(skill_id, UtteranceState.INTENT) if state == UtteranceState.RESPONSE: - converse_msg = message.reply("skill.converse.get_response", - {"skill_id": skill_id, - "utterances": utterances, + converse_msg = message.reply(f"{skill_id}.converse.get_response", + {"utterances": utterances, "lang": lang}) self.bus.emit(converse_msg) return True if self._converse_allowed(skill_id): - converse_msg = message.reply("skill.converse.request", - {"skill_id": skill_id, - "utterances": utterances, + converse_msg = message.reply(f"{skill_id}.converse.request", + {"utterances": utterances, "lang": lang}) result = self.bus.wait_for_response(converse_msg, 'skill.converse.response') diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 2f4b44252bd..91ece75063f 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -12,7 +12,7 @@ ovos-plugin-manager<0.1.0, >=0.0.24a9 ovos-config~=0.0,>=0.0.11a13 ovos-lingua-franca>=0.4.7 ovos-backend-client>=0.1.0a12 -ovos-workshop<0.1.0, >=0.0.13a10 +ovos-workshop<0.1.0, >=0.0.13a16 # provides plugins and classic machine learning framework ovos-classifiers<0.1.0, >=0.0.0a37 diff --git a/test/end2end/session/test_complete_failure.py b/test/end2end/session/test_complete_failure.py index 313c6cbf6f2..760fbe8908a 100644 --- a/test/end2end/session/test_complete_failure.py +++ b/test/end2end/session/test_complete_failure.py @@ -17,6 +17,7 @@ def test_complete_failure(self): SessionManager.sessions = {} SessionManager.default_session = SessionManager.sessions["default"] = Session("default") SessionManager.default_session.lang = "en-us" + SessionManager.default_session.active_skills = [(self.skill_id, time.time())] messages = [] def new_msg(msg): @@ -46,7 +47,7 @@ def wait_for_n_messages(n): expected_messages = [ "recognizer_loop:utterance", # Converse - "skill.converse.ping", + f"{self.skill_id}.converse.ping", "skill.converse.pong", # FallbackV1 "mycroft.skills.fallback", @@ -81,7 +82,7 @@ def wait_for_n_messages(n): self.assertEqual(m.context["session"]["session_id"], "default") # verify ping/pong answer from hello world skill - self.assertEqual(messages[1].msg_type, "skill.converse.ping") + self.assertEqual(messages[1].msg_type, f"{self.skill_id}.converse.ping") self.assertEqual(messages[2].msg_type, "skill.converse.pong") self.assertEqual(messages[2].data["skill_id"], self.skill_id) self.assertEqual(messages[2].context["skill_id"], self.skill_id) @@ -131,6 +132,7 @@ def test_complete_failure_lang_detect(self): SessionManager.sessions = {} SessionManager.default_session = SessionManager.sessions["default"] = Session("default") SessionManager.default_session.lang = "en-us" + SessionManager.default_session.active_skills = [(self.skill_id, time.time())] stt_lang_detect = "pt-pt" @@ -167,7 +169,7 @@ def wait_for_n_messages(n): expected_messages = [ "recognizer_loop:utterance", "ovos.session.update_default", # language changed - "skill.converse.ping", + f"{self.skill_id}.converse.ping", "skill.converse.pong", "mycroft.skills.fallback", "mycroft.skill.handler.start", @@ -205,7 +207,7 @@ def wait_for_n_messages(n): self.assertEqual(messages[1].data["session_data"]["lang"], stt_lang_detect) # verify ping/pong answer from hello world skill - self.assertEqual(messages[2].msg_type, "skill.converse.ping") + self.assertEqual(messages[2].msg_type, f"{self.skill_id}.converse.ping") self.assertEqual(messages[3].msg_type, "skill.converse.pong") self.assertEqual(messages[3].data["skill_id"], self.skill_id) self.assertEqual(messages[3].context["skill_id"], self.skill_id) diff --git a/test/end2end/session/test_converse.py b/test/end2end/session/test_converse.py index 984a7273c69..5b3742c2435 100644 --- a/test/end2end/session/test_converse.py +++ b/test/end2end/session/test_converse.py @@ -39,7 +39,8 @@ def wait_for_n_messages(n): self.core.bus.on("message", new_msg) - # triggers intent from test skill to make it active + # triggers intent from converse test skill to make it active + # no converse ping pong as no skill is active # verify active skills list (test) def skill_converse_no(): @@ -52,9 +53,6 @@ def skill_converse_no(): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected - "skill.converse.pong", - "skill.converse.pong", # skill selected "intent.service.skills.activated", f"{self.skill_id}.activate", @@ -79,65 +77,48 @@ def skill_converse_no(): # (missing in utterance message) and kept in all messages for m in messages[1:]: self.assertEqual(m.context["session"]["session_id"], "default") - - # verify that "lang" is injected by converse.ping - # (missing in utterance message) and kept in all messages - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - for m in messages[1:]: self.assertEqual(m.context["lang"], "en-us") - # verify "pong" answer from both skills - self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"],messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) - # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[4].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[1].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[1].data["skill_id"], self.skill_id) + self.assertEqual(messages[2].msg_type, f"{self.skill_id}.activate") # verify intent triggers - self.assertEqual(messages[6].msg_type, f"{self.skill_id}:converse_off.intent") + self.assertEqual(messages[3].msg_type, f"{self.skill_id}:converse_off.intent") # verify skill_id is now present in every message.context - for m in messages[6:]: + for m in messages[3:]: self.assertEqual(m.context["skill_id"], self.skill_id) # verify intent execution - self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[4].data["name"], "TestAbortSkill.handle_converse_off") + self.assertEqual(messages[5].msg_type, "enclosure.active_skill") + self.assertEqual(messages[5].data["skill_id"], self.skill_id) + self.assertEqual(messages[6].msg_type, "speak") + self.assertEqual(messages[6].data["lang"], "en-us") + self.assertFalse(messages[6].data["expect_response"]) + self.assertEqual(messages[6].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.complete") self.assertEqual(messages[7].data["name"], "TestAbortSkill.handle_converse_off") - self.assertEqual(messages[8].msg_type, "enclosure.active_skill") - self.assertEqual(messages[8].data["skill_id"], self.skill_id) - self.assertEqual(messages[9].msg_type, "speak") - self.assertEqual(messages[9].data["lang"], "en-us") - self.assertFalse(messages[9].data["expect_response"]) - self.assertEqual(messages[9].data["meta"]["skill"], self.skill_id) - self.assertEqual(messages[10].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[10].data["name"], "TestAbortSkill.handle_converse_off") # verify default session is now updated - self.assertEqual(messages[11].msg_type, "ovos.session.update_default") - self.assertEqual(messages[11].data["session_data"]["session_id"], "default") + self.assertEqual(messages[8].msg_type, "ovos.session.update_default") + self.assertEqual(messages[8].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[11].data["session_data"]) + sess = Session.deserialize(messages[8].data["session_data"]) self.assertEqual(sess.session_id, "default") # test that active skills list has been updated self.assertEqual(sess.active_skills[0][0], self.skill_id) - self.assertEqual(messages[11].data["session_data"]["active_skills"][0][0], self.skill_id) + self.assertEqual(messages[8].data["session_data"]["active_skills"][0][0], self.skill_id) messages = [] skill_converse_no() - # test hello world skill triggers, test skill says it does not want to converse + # converse test skill is now active + # test hello world skill triggers, converse test skill says it does not want to converse # verify active skills list (hello, test) def hello_world(): nonlocal messages @@ -148,10 +129,9 @@ def hello_world(): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected - "skill.converse.pong", + f"{self.skill_id}.converse.ping", # default session injected "skill.converse.pong", - "skill.converse.request", + f"{self.skill_id}.converse.request", "skill.converse.response", # does not want to converse # skill selected "intent.service.skills.activated", @@ -165,6 +145,7 @@ def hello_world(): # session updated "ovos.session.update_default" ] + wait_for_n_messages(len(expected_messages)) self.assertEqual(len(expected_messages), len(messages)) @@ -177,73 +158,64 @@ def hello_world(): # (missing in utterance message) and kept in all messages for m in messages[1:]: self.assertEqual(m.context["session"]["session_id"], "default") + self.assertEqual(m.context["lang"], "en-us") # verify that "lang" is injected by converse.ping # (missing in utterance message) and kept in all messages - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - for m in messages[1:]: - self.assertEqual(m.context["lang"], "en-us") + self.assertEqual(messages[1].msg_type, f"{self.skill_id}.converse.ping") - # verify "pong" answer from both skills + # verify "pong" answer from converse test skill self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) + self.assertTrue(messages[2].data["can_handle"]) # verify answer from skill that it does not want to converse - self.assertEqual(messages[4].msg_type, "skill.converse.request") + self.assertEqual(messages[3].msg_type, f"{self.skill_id}.converse.request") + self.assertEqual(messages[4].msg_type, "skill.converse.response") self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, "skill.converse.response") - self.assertEqual(messages[5].data["skill_id"], self.skill_id) - self.assertFalse(messages[5].data["result"]) # does not want to converse + self.assertFalse(messages[4].data["result"]) # does not want to converse # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[6].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[6].data["skill_id"], self.other_skill_id) - self.assertEqual(messages[7].msg_type, f"{self.other_skill_id}.activate") + self.assertEqual(messages[5].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[5].data["skill_id"], self.other_skill_id) + self.assertEqual(messages[6].msg_type, f"{self.other_skill_id}.activate") # verify intent triggers - self.assertEqual(messages[8].msg_type, f"{self.other_skill_id}:HelloWorldIntent") + self.assertEqual(messages[7].msg_type, f"{self.other_skill_id}:HelloWorldIntent") # verify skill_id is now present in every message.context - for m in messages[8:]: + for m in messages[7:]: self.assertEqual(m.context["skill_id"], self.other_skill_id) # verify intent execution - self.assertEqual(messages[9].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[9].data["name"], "HelloWorldSkill.handle_hello_world_intent") - self.assertEqual(messages[10].msg_type, "enclosure.active_skill") - self.assertEqual(messages[10].data["skill_id"], self.other_skill_id) - self.assertEqual(messages[11].msg_type, "speak") - self.assertEqual(messages[11].data["lang"], "en-us") - self.assertFalse(messages[11].data["expect_response"]) - self.assertEqual(messages[11].data["meta"]["skill"], self.other_skill_id) - self.assertEqual(messages[12].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[12].data["name"], "HelloWorldSkill.handle_hello_world_intent") + self.assertEqual(messages[8].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[8].data["name"], "HelloWorldSkill.handle_hello_world_intent") + self.assertEqual(messages[9].msg_type, "enclosure.active_skill") + self.assertEqual(messages[9].data["skill_id"], self.other_skill_id) + self.assertEqual(messages[10].msg_type, "speak") + self.assertEqual(messages[10].data["lang"], "en-us") + self.assertFalse(messages[10].data["expect_response"]) + self.assertEqual(messages[10].data["meta"]["skill"], self.other_skill_id) + self.assertEqual(messages[11].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[11].data["name"], "HelloWorldSkill.handle_hello_world_intent") # verify default session is now updated - self.assertEqual(messages[13].msg_type, "ovos.session.update_default") - self.assertEqual(messages[13].data["session_data"]["session_id"], "default") + self.assertEqual(messages[12].msg_type, "ovos.session.update_default") + self.assertEqual(messages[12].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[13].data["session_data"]) + sess = Session.deserialize(messages[12].data["session_data"]) self.assertEqual(sess.session_id, "default") # test that active skills list has been updated self.assertEqual(sess.active_skills[0][0], self.other_skill_id) self.assertEqual(sess.active_skills[1][0], self.skill_id) - self.assertEqual(messages[13].data["session_data"]["active_skills"][0][0], self.other_skill_id) - self.assertEqual(messages[13].data["session_data"]["active_skills"][1][0], self.skill_id) + self.assertEqual(messages[12].data["session_data"]["active_skills"][0][0], self.other_skill_id) + self.assertEqual(messages[12].data["session_data"]["active_skills"][1][0], self.skill_id) messages = [] hello_world() + # both skills are now active # trigger skill intent that makes it return True in next converse # verify active skills list gets swapped (test, hello) def skill_converse_yes(): @@ -256,10 +228,11 @@ def skill_converse_yes(): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected + f"{self.skill_id}.converse.ping", # default session injected + f"{self.other_skill_id}.converse.ping", "skill.converse.pong", "skill.converse.pong", - "skill.converse.request", + f"{self.skill_id}.converse.request", "skill.converse.response", # does not want to converse # skill selected "intent.service.skills.activated", @@ -281,72 +254,63 @@ def skill_converse_yes(): for m in expected_messages: self.assertTrue(m in mtypes) - # verify that "session" is injected + # verify that "session" and "lang" is injected # (missing in utterance message) and kept in all messages for m in messages[1:]: self.assertEqual(m.context["session"]["session_id"], "default") - - # verify that "lang" is injected by converse.ping - # (missing in utterance message) and kept in all messages - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - for m in messages[1:]: self.assertEqual(m.context["lang"], "en-us") - # verify "pong" answer from both skills + # converse + self.assertEqual(messages[1].msg_type, f"{self.other_skill_id}.converse.ping") self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") self.assertEqual(messages[2].data["skill_id"],messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) + self.assertFalse(messages[2].data["can_handle"]) + self.assertEqual(messages[3].msg_type, f"{self.skill_id}.converse.ping") + self.assertEqual(messages[4].msg_type, "skill.converse.pong") + self.assertEqual(messages[4].data["skill_id"], messages[4].context["skill_id"]) + self.assertTrue(messages[4].data["can_handle"]) # verify answer from skill that it does not want to converse - self.assertEqual(messages[4].msg_type, "skill.converse.request") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, "skill.converse.response") - self.assertEqual(messages[5].data["skill_id"], self.skill_id) - self.assertFalse(messages[5].data["result"]) # do not want to converse + self.assertEqual(messages[5].msg_type, f"{self.skill_id}.converse.request") + self.assertEqual(messages[6].msg_type, "skill.converse.response") + self.assertEqual(messages[6].data["skill_id"], self.skill_id) + self.assertFalse(messages[6].data["result"]) # do not want to converse # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[6].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[6].data["skill_id"], self.skill_id) - self.assertEqual(messages[7].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[7].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[7].data["skill_id"], self.skill_id) + self.assertEqual(messages[8].msg_type, f"{self.skill_id}.activate") # verify intent triggers - self.assertEqual(messages[8].msg_type, f"{self.skill_id}:converse_on.intent") + self.assertEqual(messages[9].msg_type, f"{self.skill_id}:converse_on.intent") # verify skill_id is now present in every message.context - for m in messages[8:]: + for m in messages[9:]: self.assertEqual(m.context["skill_id"], self.skill_id) # verify intent execution - self.assertEqual(messages[9].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[9].data["name"], "TestAbortSkill.handle_converse_on") - self.assertEqual(messages[10].msg_type, "enclosure.active_skill") - self.assertEqual(messages[10].data["skill_id"], self.skill_id) - self.assertEqual(messages[11].msg_type, "speak") - self.assertEqual(messages[11].data["lang"], "en-us") - self.assertFalse(messages[11].data["expect_response"]) - self.assertEqual(messages[11].data["meta"]["skill"], self.skill_id) - self.assertEqual(messages[12].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[12].data["name"], "TestAbortSkill.handle_converse_on") + self.assertEqual(messages[10].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[10].data["name"], "TestAbortSkill.handle_converse_on") + self.assertEqual(messages[11].msg_type, "enclosure.active_skill") + self.assertEqual(messages[11].data["skill_id"], self.skill_id) + self.assertEqual(messages[12].msg_type, "speak") + self.assertEqual(messages[12].data["lang"], "en-us") + self.assertFalse(messages[12].data["expect_response"]) + self.assertEqual(messages[12].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[13].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[13].data["name"], "TestAbortSkill.handle_converse_on") # verify default session is now updated - self.assertEqual(messages[13].msg_type, "ovos.session.update_default") - self.assertEqual(messages[13].data["session_data"]["session_id"], "default") + self.assertEqual(messages[14].msg_type, "ovos.session.update_default") + self.assertEqual(messages[14].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[13].data["session_data"]) + sess = Session.deserialize(messages[14].data["session_data"]) self.assertEqual(sess.session_id, "default") # test that active skills list has been updated self.assertEqual(sess.active_skills[0][0], self.skill_id) self.assertEqual(sess.active_skills[1][0], self.other_skill_id) - self.assertEqual(messages[13].data["session_data"]["active_skills"][0][0], self.skill_id) - self.assertEqual(messages[13].data["session_data"]["active_skills"][1][0], self.other_skill_id) + self.assertEqual(messages[14].data["session_data"]["active_skills"][0][0], self.skill_id) + self.assertEqual(messages[14].data["session_data"]["active_skills"][1][0], self.other_skill_id) messages = [] @@ -362,10 +326,11 @@ def converse_capture(): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected + f"{self.skill_id}.converse.ping", # default session injected + f"{self.other_skill_id}.converse.ping", "skill.converse.pong", "skill.converse.pong", - "skill.converse.request", + f"{self.skill_id}.converse.request", "skill.converse.response", # CONVERSED # skill selected "intent.service.skills.activated", @@ -382,54 +347,45 @@ def converse_capture(): print(m) self.assertTrue(m in mtypes) - # verify that "session" is injected + # verify that "session" and "lang" is injected # (missing in utterance message) and kept in all messages for m in messages[1:]: self.assertEqual(m.context["session"]["session_id"], "default") - - # verify that "lang" is injected by converse.ping - # (missing in utterance message) and kept in all messages - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - for m in messages[1:]: self.assertEqual(m.context["lang"], "en-us") - # verify "pong" answer from both skills + # converse + self.assertEqual(messages[1].msg_type, f"{self.skill_id}.converse.ping") self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) + self.assertEqual(messages[2].data["skill_id"],messages[2].context["skill_id"]) + self.assertTrue(messages[2].data["can_handle"]) + self.assertEqual(messages[3].msg_type, f"{self.other_skill_id}.converse.ping") + self.assertEqual(messages[4].msg_type, "skill.converse.pong") + self.assertEqual(messages[4].data["skill_id"], messages[4].context["skill_id"]) + self.assertFalse(messages[4].data["can_handle"]) # verify answer from skill that it does not want to converse - self.assertEqual(messages[4].msg_type, "skill.converse.request") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, "skill.converse.response") - self.assertEqual(messages[5].data["skill_id"], self.skill_id) - self.assertTrue(messages[5].data["result"]) # CONVERSED + self.assertEqual(messages[5].msg_type, f"{self.skill_id}.converse.request") + self.assertEqual(messages[6].msg_type, "skill.converse.response") + self.assertEqual(messages[6].data["skill_id"], self.skill_id) + self.assertTrue(messages[6].data["result"]) # CONVERSED # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[6].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[6].data["skill_id"], self.skill_id) - self.assertEqual(messages[7].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[7].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[7].data["skill_id"], self.skill_id) + self.assertEqual(messages[8].msg_type, f"{self.skill_id}.activate") # verify default session is now updated - self.assertEqual(messages[8].msg_type, "ovos.session.update_default") - self.assertEqual(messages[8].data["session_data"]["session_id"], "default") + self.assertEqual(messages[9].msg_type, "ovos.session.update_default") + self.assertEqual(messages[9].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[8].data["session_data"]) + sess = Session.deserialize(messages[9].data["session_data"]) self.assertEqual(sess.session_id, "default") # test that active skills list has been updated self.assertEqual(sess.active_skills[0][0], self.skill_id) self.assertEqual(sess.active_skills[1][0], self.other_skill_id) - self.assertEqual(messages[8].data["session_data"]["active_skills"][0][0], self.skill_id) - self.assertEqual(messages[8].data["session_data"]["active_skills"][1][0], self.other_skill_id) + self.assertEqual(messages[9].data["session_data"]["active_skills"][0][0], self.skill_id) + self.assertEqual(messages[9].data["session_data"]["active_skills"][1][0], self.other_skill_id) messages = [] diff --git a/test/end2end/session/test_fallback.py b/test/end2end/session/test_fallback.py index 48f4d342fb6..44c485efaea 100644 --- a/test/end2end/session/test_fallback.py +++ b/test/end2end/session/test_fallback.py @@ -46,9 +46,6 @@ def wait_for_n_messages(n): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", - # Converse - "skill.converse.ping", - "skill.converse.pong", # FallbackV2 "ovos.skills.fallback.ping", "ovos.skills.fallback.pong", @@ -76,51 +73,46 @@ def wait_for_n_messages(n): self.assertEqual(m.context["session"]["session_id"], "default") self.assertEqual(m.context["x"], "xx") # verify active skills is empty until "intent.service.skills.activated" - for m in messages[:10]: + for m in messages[:8]: self.assertEqual(m.context["session"]["session_id"], "default") self.assertEqual(m.context["session"]["active_skills"], []) - # verify converse ping/pong answer from skill - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - self.assertEqual(messages[2].msg_type, "skill.converse.pong") + # verify fallback ping/pong answer from skill + self.assertEqual(messages[1].msg_type, "ovos.skills.fallback.ping") + self.assertEqual(messages[2].msg_type, "ovos.skills.fallback.pong") self.assertEqual(messages[2].data["skill_id"], self.skill_id) self.assertEqual(messages[2].context["skill_id"], self.skill_id) - self.assertFalse(messages[2].data["can_handle"]) - - # verify fallback ping/pong answer from skill - self.assertEqual(messages[3].msg_type, "ovos.skills.fallback.ping") - self.assertEqual(messages[4].msg_type, "ovos.skills.fallback.pong") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[4].context["skill_id"], self.skill_id) - self.assertTrue(messages[4].data["can_handle"]) + self.assertTrue(messages[2].data["can_handle"]) # verify skill executes - self.assertEqual(messages[5].msg_type, f"ovos.skills.fallback.{self.skill_id}.request") + self.assertEqual(messages[3].msg_type, f"ovos.skills.fallback.{self.skill_id}.request") + self.assertEqual(messages[3].data["skill_id"], self.skill_id) + self.assertEqual(messages[4].msg_type, f"ovos.skills.fallback.{self.skill_id}.start") + self.assertEqual(messages[5].msg_type, "enclosure.active_skill") self.assertEqual(messages[5].data["skill_id"], self.skill_id) - self.assertEqual(messages[6].msg_type, f"ovos.skills.fallback.{self.skill_id}.start") - self.assertEqual(messages[7].msg_type, "enclosure.active_skill") - self.assertEqual(messages[7].data["skill_id"], self.skill_id) - self.assertEqual(messages[8].msg_type, "speak") - self.assertEqual(messages[8].data["meta"]["dialog"], "unknown") - self.assertEqual(messages[8].data["meta"]["skill"], self.skill_id) - self.assertEqual(messages[9].msg_type, f"ovos.skills.fallback.{self.skill_id}.response") - self.assertTrue(messages[9].data["result"]) - self.assertEqual(messages[9].data["fallback_handler"], "UnknownSkill.handle_fallback") + self.assertEqual(messages[6].msg_type, "speak") + self.assertEqual(messages[6].data["meta"]["dialog"], "unknown") + self.assertEqual(messages[6].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[7].msg_type, f"ovos.skills.fallback.{self.skill_id}.response") + self.assertTrue(messages[7].data["result"]) + self.assertEqual(messages[7].data["fallback_handler"], "UnknownSkill.handle_fallback") # verify skill is activated - self.assertEqual(messages[10].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[10].data["skill_id"], self.skill_id) - self.assertEqual(messages[11].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[8].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[8].data["skill_id"], self.skill_id) + self.assertEqual(messages[9].msg_type, f"{self.skill_id}.activate") # verify default session is now updated - self.assertEqual(messages[12].msg_type, "ovos.session.update_default") - self.assertEqual(messages[12].data["session_data"]["session_id"], "default") + self.assertEqual(messages[10].msg_type, "ovos.session.update_default") + self.assertEqual(messages[10].data["session_data"]["session_id"], "default") # test second message with no session resumes default active skills messages = [] utt = Message("recognizer_loop:utterance", {"utterances": ["invalid"]}) self.core.bus.emit(utt) + # converse ping/pong due being active + expected_messages.extend([f"{self.skill_id}.converse.ping", "skill.converse.pong"]) wait_for_n_messages(len(expected_messages)) self.assertEqual(len(expected_messages), len(messages)) @@ -164,9 +156,6 @@ def wait_for_n_messages(n): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", - # Converse - "skill.converse.ping", - "skill.converse.pong", # FallbackV2 "ovos.skills.fallback.ping", "ovos.skills.fallback.pong", @@ -193,37 +182,30 @@ def wait_for_n_messages(n): self.assertEqual(m.context["session"]["session_id"], sess.session_id) self.assertEqual(m.context["x"], "xx") - # verify converse ping/pong answer from skill - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - self.assertEqual(messages[2].msg_type, "skill.converse.pong") + # verify fallback ping/pong answer from skill + self.assertEqual(messages[1].msg_type, "ovos.skills.fallback.ping") + self.assertEqual(messages[2].msg_type, "ovos.skills.fallback.pong") self.assertEqual(messages[2].data["skill_id"], self.skill_id) self.assertEqual(messages[2].context["skill_id"], self.skill_id) - self.assertFalse(messages[2].data["can_handle"]) - - # verify fallback ping/pong answer from skill - self.assertEqual(messages[3].msg_type, "ovos.skills.fallback.ping") - self.assertEqual(messages[4].msg_type, "ovos.skills.fallback.pong") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[4].context["skill_id"], self.skill_id) - self.assertTrue(messages[4].data["can_handle"]) + self.assertTrue(messages[2].data["can_handle"]) # verify skill executes - self.assertEqual(messages[5].msg_type, f"ovos.skills.fallback.{self.skill_id}.request") + self.assertEqual(messages[3].msg_type, f"ovos.skills.fallback.{self.skill_id}.request") + self.assertEqual(messages[3].data["skill_id"], self.skill_id) + self.assertEqual(messages[4].msg_type, f"ovos.skills.fallback.{self.skill_id}.start") + self.assertEqual(messages[5].msg_type, "enclosure.active_skill") self.assertEqual(messages[5].data["skill_id"], self.skill_id) - self.assertEqual(messages[6].msg_type, f"ovos.skills.fallback.{self.skill_id}.start") - self.assertEqual(messages[7].msg_type, "enclosure.active_skill") - self.assertEqual(messages[7].data["skill_id"], self.skill_id) - self.assertEqual(messages[8].msg_type, "speak") - self.assertEqual(messages[8].data["meta"]["dialog"], "unknown") - self.assertEqual(messages[8].data["meta"]["skill"], self.skill_id) - self.assertEqual(messages[9].msg_type, f"ovos.skills.fallback.{self.skill_id}.response") - self.assertTrue(messages[9].data["result"]) - self.assertEqual(messages[9].data["fallback_handler"], "UnknownSkill.handle_fallback") + self.assertEqual(messages[6].msg_type, "speak") + self.assertEqual(messages[6].data["meta"]["dialog"], "unknown") + self.assertEqual(messages[6].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[7].msg_type, f"ovos.skills.fallback.{self.skill_id}.response") + self.assertTrue(messages[7].data["result"]) + self.assertEqual(messages[7].data["fallback_handler"], "UnknownSkill.handle_fallback") # verify skill is activated - self.assertEqual(messages[10].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[10].data["skill_id"], self.skill_id) - self.assertEqual(messages[11].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[8].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[8].data["skill_id"], self.skill_id) + self.assertEqual(messages[9].msg_type, f"{self.skill_id}.activate") # test that active skills list has been updated sess = SessionManager.sessions[sess.session_id] diff --git a/test/end2end/session/test_fallback_v1.py b/test/end2end/session/test_fallback_v1.py index 853ab1e4bfc..37538583b36 100644 --- a/test/end2end/session/test_fallback_v1.py +++ b/test/end2end/session/test_fallback_v1.py @@ -46,9 +46,6 @@ def wait_for_n_messages(n): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", - # Converse - "skill.converse.ping", - "skill.converse.pong", # FallbackV1 - high prio "mycroft.skills.fallback", "mycroft.skill.handler.start", @@ -93,80 +90,75 @@ def wait_for_n_messages(n): self.assertEqual(m.context["session"]["session_id"], "default") self.assertEqual(m.context["x"], "xx") # verify active skills is empty until "intent.service.skills.activated" - for m in messages[:16]: + for m in messages[:14]: self.assertEqual(m.context["session"]["session_id"], "default") self.assertEqual(m.context["session"]["active_skills"], []) - # verify converse ping/pong answer from skill - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], self.skill_id) - self.assertEqual(messages[2].context["skill_id"], self.skill_id) - self.assertFalse(messages[2].data["can_handle"]) - # high prio fallback - self.assertEqual(messages[3].msg_type, "mycroft.skills.fallback") - self.assertEqual(messages[3].data["fallback_range"], [0, 5]) - self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[4].data["handler"], "fallback") - self.assertEqual(messages[5].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[5].data["handler"], "fallback") - self.assertEqual(messages[6].msg_type, "mycroft.skills.fallback.response") - self.assertFalse(messages[6].data["handled"]) + self.assertEqual(messages[1].msg_type, "mycroft.skills.fallback") + self.assertEqual(messages[1].data["fallback_range"], [0, 5]) + self.assertEqual(messages[2].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[2].data["handler"], "fallback") + self.assertEqual(messages[3].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[3].data["handler"], "fallback") + self.assertEqual(messages[4].msg_type, "mycroft.skills.fallback.response") + self.assertFalse(messages[4].data["handled"]) # medium prio fallback - self.assertEqual(messages[7].msg_type, "mycroft.skills.fallback") - self.assertEqual(messages[7].data["fallback_range"], [5, 90]) - self.assertEqual(messages[8].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[8].data["handler"], "fallback") - self.assertEqual(messages[9].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[9].data["handler"], "fallback") - self.assertEqual(messages[10].msg_type, "mycroft.skills.fallback.response") - self.assertFalse(messages[10].data["handled"]) + self.assertEqual(messages[5].msg_type, "mycroft.skills.fallback") + self.assertEqual(messages[5].data["fallback_range"], [5, 90]) + self.assertEqual(messages[6].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[6].data["handler"], "fallback") + self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[7].data["handler"], "fallback") + self.assertEqual(messages[8].msg_type, "mycroft.skills.fallback.response") + self.assertFalse(messages[8].data["handled"]) # low prio fallback - self.assertEqual(messages[11].msg_type, "mycroft.skills.fallback") - self.assertEqual(messages[11].data["fallback_range"], [90, 101]) - self.assertEqual(messages[12].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[12].data["handler"], "fallback") + self.assertEqual(messages[9].msg_type, "mycroft.skills.fallback") + self.assertEqual(messages[9].data["fallback_range"], [90, 101]) + self.assertEqual(messages[10].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[10].data["handler"], "fallback") # skill execution - self.assertEqual(messages[13].msg_type, "enclosure.active_skill") - self.assertEqual(messages[13].data["skill_id"], self.skill_id) - self.assertEqual(messages[14].msg_type, "speak") - self.assertEqual(messages[14].data["meta"]["dialog"], "unknown") - self.assertEqual(messages[14].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[11].msg_type, "enclosure.active_skill") + self.assertEqual(messages[11].data["skill_id"], self.skill_id) + self.assertEqual(messages[12].msg_type, "speak") + self.assertEqual(messages[12].data["meta"]["dialog"], "unknown") + self.assertEqual(messages[12].data["meta"]["skill"], self.skill_id) # skill making itself active - self.assertEqual(messages[15].msg_type, "intent.service.skills.activate") - self.assertEqual(messages[15].data["skill_id"], self.skill_id) - self.assertEqual(messages[16].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[16].data["skill_id"], self.skill_id) - self.assertEqual(messages[17].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[18].msg_type, 'ovos.session.update_default') + self.assertEqual(messages[13].msg_type, "intent.service.skills.activate") + self.assertEqual(messages[13].data["skill_id"], self.skill_id) + self.assertEqual(messages[14].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[14].data["skill_id"], self.skill_id) + self.assertEqual(messages[15].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[16].msg_type, 'ovos.session.update_default') # skill making itself active again - backwards compat namespace - self.assertEqual(messages[19].msg_type, "active_skill_request") - self.assertEqual(messages[19].data["skill_id"], self.skill_id) - self.assertEqual(messages[20].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[20].data["skill_id"], self.skill_id) - self.assertEqual(messages[21].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[22].msg_type, 'ovos.session.update_default') + self.assertEqual(messages[17].msg_type, "active_skill_request") + self.assertEqual(messages[17].data["skill_id"], self.skill_id) + self.assertEqual(messages[18].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[18].data["skill_id"], self.skill_id) + self.assertEqual(messages[19].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[20].msg_type, 'ovos.session.update_default') # fallback execution response - self.assertEqual(messages[23].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[23].data["handler"], "fallback") - self.assertEqual(messages[24].msg_type, "mycroft.skills.fallback.response") - self.assertTrue(messages[24].data["handled"]) + self.assertEqual(messages[21].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[21].data["handler"], "fallback") + self.assertEqual(messages[22].msg_type, "mycroft.skills.fallback.response") + self.assertTrue(messages[22].data["handled"]) # verify default session is now updated - self.assertEqual(messages[25].msg_type, "ovos.session.update_default") - self.assertEqual(messages[25].data["session_data"]["session_id"], "default") + self.assertEqual(messages[23].msg_type, "ovos.session.update_default") + self.assertEqual(messages[23].data["session_data"]["session_id"], "default") # test second message with no session resumes default active skills messages = [] utt = Message("recognizer_loop:utterance", {"utterances": ["invalid"]}) self.core.bus.emit(utt) + # converse ping/pong due being active + expected_messages.extend([f"{self.skill_id}.converse.ping", "skill.converse.pong"]) wait_for_n_messages(len(expected_messages)) self.assertEqual(len(expected_messages), len(messages)) diff --git a/test/end2end/session/test_get_response.py b/test/end2end/session/test_get_response.py index b7b950c47cb..e7ffeefa22c 100644 --- a/test/end2end/session/test_get_response.py +++ b/test/end2end/session/test_get_response.py @@ -4,6 +4,7 @@ from ovos_bus_client.message import Message from ovos_bus_client.session import SessionManager, Session +from ovos_utils.log import LOG from .minicroft import get_minicroft @@ -53,12 +54,9 @@ def on_speak(msg): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected - "skill.converse.pong", # test skill - "skill.converse.pong", # hello world skill # skill selected - "intent.service.skills.activated", + "intent.service.skills.activated", # default session injected f"{self.skill_id}.activate", f"{self.skill_id}:test_get_response.intent", @@ -97,81 +95,63 @@ def on_speak(msg): for m in messages[1:]: print(m.msg_type, m.context["session"]["session_id"]) self.assertEqual(m.context["session"]["session_id"], "default") - - # verify that "lang" is injected by converse.ping - # (missing in utterance message) and kept in all messages - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - for m in messages[1:]: - self.assertEqual(m.context["lang"], "en-us") - - # verify "pong" answer from both skills - self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) + self.assertEqual(m.context["lang"], "en-us") # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[4].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[1].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[1].data["skill_id"], self.skill_id) + self.assertEqual(messages[2].msg_type, f"{self.skill_id}.activate") # verify intent triggers - self.assertEqual(messages[6].msg_type, f"{self.skill_id}:test_get_response.intent") + self.assertEqual(messages[3].msg_type, f"{self.skill_id}:test_get_response.intent") # verify skill_id is now present in every message.context - for m in messages[6:]: + for m in messages[3:]: self.assertEqual(m.context["skill_id"], self.skill_id) # verify intent execution - self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[7].data["name"], "TestAbortSkill.handle_test_get_response") + self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[4].data["name"], "TestAbortSkill.handle_test_get_response") # enable get_response for this session - self.assertEqual(messages[8].msg_type, "skill.converse.get_response.enable") - self.assertEqual(messages[9].msg_type, "ovos.session.update_default") + self.assertEqual(messages[5].msg_type, "skill.converse.get_response.enable") + self.assertEqual(messages[6].msg_type, "ovos.session.update_default") # question dialog - self.assertEqual(messages[10].msg_type, "enclosure.active_skill") - self.assertEqual(messages[10].data["skill_id"], self.skill_id) - self.assertEqual(messages[11].msg_type, "speak") - self.assertEqual(messages[11].data["lang"], "en-us") - self.assertTrue(messages[11].data["expect_response"]) # listen after dialog - self.assertEqual(messages[11].data["meta"]["skill"], self.skill_id) - self.assertEqual(messages[12].msg_type, "recognizer_loop:audio_output_start") - self.assertEqual(messages[13].msg_type, "recognizer_loop:audio_output_end") + self.assertEqual(messages[7].msg_type, "enclosure.active_skill") + self.assertEqual(messages[7].data["skill_id"], self.skill_id) + self.assertEqual(messages[8].msg_type, "speak") + self.assertEqual(messages[8].data["lang"], "en-us") + self.assertTrue(messages[8].data["expect_response"]) # listen after dialog + self.assertEqual(messages[8].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[9].msg_type, "recognizer_loop:audio_output_start") + self.assertEqual(messages[10].msg_type, "recognizer_loop:audio_output_end") # user response would be here # disable get_response for this session - self.assertEqual(messages[14].msg_type, "skill.converse.get_response.disable") - self.assertEqual(messages[15].msg_type, "ovos.session.update_default") + self.assertEqual(messages[11].msg_type, "skill.converse.get_response.disable") + self.assertEqual(messages[12].msg_type, "ovos.session.update_default") # post self.get_response intent code - self.assertEqual(messages[16].msg_type, "enclosure.active_skill") - self.assertEqual(messages[16].data["skill_id"], self.skill_id) - self.assertEqual(messages[17].msg_type, "speak") - self.assertEqual(messages[17].data["lang"], "en-us") - self.assertFalse(messages[17].data["expect_response"]) - self.assertEqual(messages[17].data["utterance"], "ERROR") - self.assertEqual(messages[17].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[13].msg_type, "enclosure.active_skill") + self.assertEqual(messages[13].data["skill_id"], self.skill_id) + self.assertEqual(messages[14].msg_type, "speak") + self.assertEqual(messages[14].data["lang"], "en-us") + self.assertFalse(messages[14].data["expect_response"]) + self.assertEqual(messages[14].data["utterance"], "ERROR") + self.assertEqual(messages[14].data["meta"]["skill"], self.skill_id) - self.assertEqual(messages[18].msg_type, "recognizer_loop:audio_output_start") - self.assertEqual(messages[19].msg_type, "recognizer_loop:audio_output_end") + self.assertEqual(messages[15].msg_type, "recognizer_loop:audio_output_start") + self.assertEqual(messages[16].msg_type, "recognizer_loop:audio_output_end") - self.assertEqual(messages[20].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[20].data["name"], "TestAbortSkill.handle_test_get_response") + self.assertEqual(messages[17].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[17].data["name"], "TestAbortSkill.handle_test_get_response") # verify default session is now updated - self.assertEqual(messages[21].msg_type, "ovos.session.update_default") - self.assertEqual(messages[21].data["session_data"]["session_id"], "default") + self.assertEqual(messages[18].msg_type, "ovos.session.update_default") + self.assertEqual(messages[18].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[21].data["session_data"]) + sess = Session.deserialize(messages[18].data["session_data"]) self.assertEqual(sess.session_id, "default") def test_with_response(self): @@ -220,9 +200,6 @@ def answer_get_response(msg): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected - "skill.converse.pong", # test skill - "skill.converse.pong", # hello world skill # skill selected "intent.service.skills.activated", @@ -240,10 +217,9 @@ def answer_get_response(msg): "recognizer_loop:utterance", # answer to get_response from user, # converse pipeline start - "skill.converse.ping", - "skill.converse.pong", + f"{self.skill_id}.converse.ping", "skill.converse.pong", - "skill.converse.get_response", # returning user utterance to running intent self.get_response + f"{self.skill_id}.converse.get_response", # returning user utterance to running intent self.get_response # skill selected by converse pipeline "intent.service.skills.activated", f"{self.skill_id}.activate", @@ -277,87 +253,71 @@ def answer_get_response(msg): print(m.msg_type, m.context["session"]["session_id"]) self.assertEqual(m.context["session"]["session_id"], "default") - # converse intent pipeline - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) - # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[4].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[1].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[1].data["skill_id"], self.skill_id) + self.assertEqual(messages[2].msg_type, f"{self.skill_id}.activate") # verify intent triggers - self.assertEqual(messages[6].msg_type, f"{self.skill_id}:test_get_response.intent") + self.assertEqual(messages[3].msg_type, f"{self.skill_id}:test_get_response.intent") # verify intent execution - self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[7].data["name"], "TestAbortSkill.handle_test_get_response") + self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[4].data["name"], "TestAbortSkill.handle_test_get_response") # enable get_response for this session - self.assertEqual(messages[8].msg_type, "skill.converse.get_response.enable") - self.assertEqual(messages[9].msg_type, "ovos.session.update_default") - - self.assertEqual(messages[10].msg_type, "enclosure.active_skill") - self.assertEqual(messages[10].data["skill_id"], self.skill_id) - self.assertEqual(messages[11].msg_type, "speak") - self.assertEqual(messages[11].data["utterance"], "give me an answer", ) - self.assertEqual(messages[11].data["lang"], "en-us") - self.assertTrue(messages[11].data["expect_response"]) # listen after dialog - self.assertEqual(messages[11].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[5].msg_type, "skill.converse.get_response.enable") + self.assertEqual(messages[6].msg_type, "ovos.session.update_default") + + self.assertEqual(messages[7].msg_type, "enclosure.active_skill") + self.assertEqual(messages[7].data["skill_id"], self.skill_id) + self.assertEqual(messages[8].msg_type, "speak") + self.assertEqual(messages[8].data["utterance"], "give me an answer", ) + self.assertEqual(messages[8].data["lang"], "en-us") + self.assertTrue(messages[8].data["expect_response"]) # listen after dialog + self.assertEqual(messages[8].data["meta"]["skill"], self.skill_id) # ovos-audio speak execution (simulated) - self.assertEqual(messages[12].msg_type, "recognizer_loop:audio_output_start") - self.assertEqual(messages[13].msg_type, "recognizer_loop:audio_output_end") + self.assertEqual(messages[9].msg_type, "recognizer_loop:audio_output_start") + self.assertEqual(messages[10].msg_type, "recognizer_loop:audio_output_end") # check utterance goes through converse cycle - self.assertEqual(messages[14].msg_type, "recognizer_loop:utterance") - self.assertEqual(messages[15].msg_type, "skill.converse.ping") - self.assertEqual(messages[16].msg_type, "skill.converse.pong") - self.assertEqual(messages[17].msg_type, "skill.converse.pong") + self.assertEqual(messages[11].msg_type, "recognizer_loop:utterance") + self.assertEqual(messages[12].msg_type, f"{self.skill_id}.converse.ping") + self.assertEqual(messages[13].msg_type, "skill.converse.pong") # captured utterance sent to get_response handler that is waiting - self.assertEqual(messages[18].msg_type, "skill.converse.get_response") - self.assertEqual(messages[18].data["skill_id"], self.skill_id) - self.assertEqual(messages[18].data["utterances"], ["ok"]) + self.assertEqual(messages[14].msg_type, f"{self.skill_id}.converse.get_response") + self.assertEqual(messages[14].data["utterances"], ["ok"]) # converse pipeline activates the skill last_used timestamp - self.assertEqual(messages[19].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[20].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[21].msg_type, "ovos.session.update_default") + self.assertEqual(messages[15].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[16].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[17].msg_type, "ovos.session.update_default") # disable get_response for this session - self.assertEqual(messages[22].msg_type, "skill.converse.get_response.disable") - self.assertEqual(messages[23].msg_type, "ovos.session.update_default") + self.assertEqual(messages[18].msg_type, "skill.converse.get_response.disable") + self.assertEqual(messages[19].msg_type, "ovos.session.update_default") # post self.get_response intent code - self.assertEqual(messages[24].msg_type, "enclosure.active_skill") - self.assertEqual(messages[24].data["skill_id"], self.skill_id) - self.assertEqual(messages[25].msg_type, "speak") - self.assertEqual(messages[25].data["lang"], "en-us") - self.assertFalse(messages[25].data["expect_response"]) - self.assertEqual(messages[25].data["utterance"], "ok") - self.assertEqual(messages[25].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[20].msg_type, "enclosure.active_skill") + self.assertEqual(messages[20].data["skill_id"], self.skill_id) + self.assertEqual(messages[21].msg_type, "speak") + self.assertEqual(messages[21].data["lang"], "en-us") + self.assertFalse(messages[21].data["expect_response"]) + self.assertEqual(messages[21].data["utterance"], "ok") + self.assertEqual(messages[21].data["meta"]["skill"], self.skill_id) # ovos-audio speak execution (simulated) - self.assertEqual(messages[26].msg_type, "recognizer_loop:audio_output_start") - self.assertEqual(messages[27].msg_type, "recognizer_loop:audio_output_end") + self.assertEqual(messages[22].msg_type, "recognizer_loop:audio_output_start") + self.assertEqual(messages[23].msg_type, "recognizer_loop:audio_output_end") - self.assertEqual(messages[28].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[28].data["name"], "TestAbortSkill.handle_test_get_response") + self.assertEqual(messages[24].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[24].data["name"], "TestAbortSkill.handle_test_get_response") # verify default session is now updated - self.assertEqual(messages[29].msg_type, "ovos.session.update_default") - self.assertEqual(messages[29].data["session_data"]["session_id"], "default") + self.assertEqual(messages[25].msg_type, "ovos.session.update_default") + self.assertEqual(messages[25].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[29].data["session_data"]) + sess = Session.deserialize(messages[25].data["session_data"]) self.assertEqual(sess.session_id, "default") def test_cancel_response(self): @@ -406,9 +366,6 @@ def answer_get_response(msg): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected - "skill.converse.pong", # test skill - "skill.converse.pong", # hello world skill # skill selected "intent.service.skills.activated", @@ -426,10 +383,9 @@ def answer_get_response(msg): "recognizer_loop:utterance", # answer to get_response from user, # converse pipeline start - "skill.converse.ping", - "skill.converse.pong", + f"{self.skill_id}.converse.ping", "skill.converse.pong", - "skill.converse.get_response", # returning user utterance to running intent self.get_response + f"{self.skill_id}.converse.get_response", # returning user utterance to running intent self.get_response # skill selected by converse pipeline "intent.service.skills.activated", f"{self.skill_id}.activate", @@ -463,87 +419,71 @@ def answer_get_response(msg): print(m.msg_type, m.context["session"]["session_id"]) self.assertEqual(m.context["session"]["session_id"], "default") - # converse intent pipeline - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) - # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[4].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[1].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[1].data["skill_id"], self.skill_id) + self.assertEqual(messages[2].msg_type, f"{self.skill_id}.activate") # verify intent triggers - self.assertEqual(messages[6].msg_type, f"{self.skill_id}:test_get_response.intent") + self.assertEqual(messages[3].msg_type, f"{self.skill_id}:test_get_response.intent") # verify intent execution - self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[7].data["name"], "TestAbortSkill.handle_test_get_response") + self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[4].data["name"], "TestAbortSkill.handle_test_get_response") # enable get_response for this session - self.assertEqual(messages[8].msg_type, "skill.converse.get_response.enable") - self.assertEqual(messages[9].msg_type, "ovos.session.update_default") - - self.assertEqual(messages[10].msg_type, "enclosure.active_skill") - self.assertEqual(messages[10].data["skill_id"], self.skill_id) - self.assertEqual(messages[11].msg_type, "speak") - self.assertEqual(messages[11].data["utterance"], "give me an answer", ) - self.assertEqual(messages[11].data["lang"], "en-us") - self.assertTrue(messages[11].data["expect_response"]) # listen after dialog - self.assertEqual(messages[11].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[5].msg_type, "skill.converse.get_response.enable") + self.assertEqual(messages[6].msg_type, "ovos.session.update_default") + + self.assertEqual(messages[7].msg_type, "enclosure.active_skill") + self.assertEqual(messages[7].data["skill_id"], self.skill_id) + self.assertEqual(messages[8].msg_type, "speak") + self.assertEqual(messages[8].data["utterance"], "give me an answer", ) + self.assertEqual(messages[8].data["lang"], "en-us") + self.assertTrue(messages[8].data["expect_response"]) # listen after dialog + self.assertEqual(messages[8].data["meta"]["skill"], self.skill_id) # ovos-audio speak execution (simulated) - self.assertEqual(messages[12].msg_type, "recognizer_loop:audio_output_start") - self.assertEqual(messages[13].msg_type, "recognizer_loop:audio_output_end") + self.assertEqual(messages[9].msg_type, "recognizer_loop:audio_output_start") + self.assertEqual(messages[10].msg_type, "recognizer_loop:audio_output_end") # check utterance goes through converse cycle - self.assertEqual(messages[14].msg_type, "recognizer_loop:utterance") - self.assertEqual(messages[15].msg_type, "skill.converse.ping") - self.assertEqual(messages[16].msg_type, "skill.converse.pong") - self.assertEqual(messages[17].msg_type, "skill.converse.pong") + self.assertEqual(messages[11].msg_type, "recognizer_loop:utterance") + self.assertEqual(messages[12].msg_type, f"{self.skill_id}.converse.ping") + self.assertEqual(messages[13].msg_type, "skill.converse.pong") # captured utterance sent to get_response handler that is waiting - self.assertEqual(messages[18].msg_type, "skill.converse.get_response") - self.assertEqual(messages[18].data["skill_id"], self.skill_id) - self.assertEqual(messages[18].data["utterances"], ["cancel"]) # was canceled by user, returned None + self.assertEqual(messages[14].msg_type, f"{self.skill_id}.converse.get_response") + self.assertEqual(messages[14].data["utterances"], ["cancel"]) # was canceled by user, returned None # converse pipeline activates the skill last_used timestamp - self.assertEqual(messages[19].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[20].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[21].msg_type, "ovos.session.update_default") + self.assertEqual(messages[15].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[16].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[17].msg_type, "ovos.session.update_default") # disable get_response for this session - self.assertEqual(messages[22].msg_type, "skill.converse.get_response.disable") - self.assertEqual(messages[23].msg_type, "ovos.session.update_default") + self.assertEqual(messages[18].msg_type, "skill.converse.get_response.disable") + self.assertEqual(messages[19].msg_type, "ovos.session.update_default") # post self.get_response intent code - self.assertEqual(messages[24].msg_type, "enclosure.active_skill") - self.assertEqual(messages[24].data["skill_id"], self.skill_id) - self.assertEqual(messages[25].msg_type, "speak") - self.assertEqual(messages[25].data["lang"], "en-us") - self.assertFalse(messages[25].data["expect_response"]) - self.assertEqual(messages[25].data["utterance"], "ERROR") - self.assertEqual(messages[25].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[20].msg_type, "enclosure.active_skill") + self.assertEqual(messages[20].data["skill_id"], self.skill_id) + self.assertEqual(messages[21].msg_type, "speak") + self.assertEqual(messages[21].data["lang"], "en-us") + self.assertFalse(messages[21].data["expect_response"]) + self.assertEqual(messages[21].data["utterance"], "ERROR") + self.assertEqual(messages[21].data["meta"]["skill"], self.skill_id) # ovos-audio speak execution (simulated) - self.assertEqual(messages[26].msg_type, "recognizer_loop:audio_output_start") - self.assertEqual(messages[27].msg_type, "recognizer_loop:audio_output_end") + self.assertEqual(messages[22].msg_type, "recognizer_loop:audio_output_start") + self.assertEqual(messages[23].msg_type, "recognizer_loop:audio_output_end") - self.assertEqual(messages[28].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[28].data["name"], "TestAbortSkill.handle_test_get_response") + self.assertEqual(messages[24].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[24].data["name"], "TestAbortSkill.handle_test_get_response") # verify default session is now updated - self.assertEqual(messages[29].msg_type, "ovos.session.update_default") - self.assertEqual(messages[29].data["session_data"]["session_id"], "default") + self.assertEqual(messages[25].msg_type, "ovos.session.update_default") + self.assertEqual(messages[25].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[29].data["session_data"]) + sess = Session.deserialize(messages[25].data["session_data"]) self.assertEqual(sess.session_id, "default") def test_with_reprompt(self): @@ -593,9 +533,6 @@ def answer_get_response(msg): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected - "skill.converse.pong", # test skill - "skill.converse.pong", # hello world skill # skill selected "intent.service.skills.activated", @@ -612,10 +549,9 @@ def answer_get_response(msg): "recognizer_loop:utterance", # answer to get_response from user, # converse pipeline start - "skill.converse.ping", + f"{self.skill_id}.converse.ping", "skill.converse.pong", - "skill.converse.pong", - "skill.converse.get_response", # returning user utterance to running intent self.get_response + f"{self.skill_id}.converse.get_response", # returning user utterance to running intent self.get_response # skill selected by converse pipeline "intent.service.skills.activated", f"{self.skill_id}.activate", @@ -647,78 +583,62 @@ def answer_get_response(msg): print(m.msg_type, m.context["session"]["session_id"]) self.assertEqual(m.context["session"]["session_id"], "default") - # converse intent pipeline - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) - # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[4].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[1].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[1].data["skill_id"], self.skill_id) + self.assertEqual(messages[2].msg_type, f"{self.skill_id}.activate") # verify intent triggers - self.assertEqual(messages[6].msg_type, f"{self.skill_id}:test_get_response3.intent") + self.assertEqual(messages[3].msg_type, f"{self.skill_id}:test_get_response3.intent") # verify intent execution - self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[7].data["name"], "TestAbortSkill.handle_test_get_response3") + self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[4].data["name"], "TestAbortSkill.handle_test_get_response3") # enable get_response for this session - self.assertEqual(messages[8].msg_type, "skill.converse.get_response.enable") - self.assertEqual(messages[9].msg_type, "ovos.session.update_default") + self.assertEqual(messages[5].msg_type, "skill.converse.get_response.enable") + self.assertEqual(messages[6].msg_type, "ovos.session.update_default") # 3 sound prompts (no dialog in this test) - self.assertEqual(messages[10].msg_type, "mycroft.mic.listen") - self.assertEqual(messages[11].msg_type, "mycroft.mic.listen") - self.assertEqual(messages[12].msg_type, "mycroft.mic.listen") + self.assertEqual(messages[7].msg_type, "mycroft.mic.listen") + self.assertEqual(messages[8].msg_type, "mycroft.mic.listen") + self.assertEqual(messages[9].msg_type, "mycroft.mic.listen") # check utterance goes through converse cycle - self.assertEqual(messages[13].msg_type, "recognizer_loop:utterance") - self.assertEqual(messages[14].msg_type, "skill.converse.ping") - self.assertEqual(messages[15].msg_type, "skill.converse.pong") - self.assertEqual(messages[16].msg_type, "skill.converse.pong") + self.assertEqual(messages[10].msg_type, "recognizer_loop:utterance") + self.assertEqual(messages[11].msg_type, f"{self.skill_id}.converse.ping") + self.assertEqual(messages[12].msg_type, "skill.converse.pong") # captured utterance sent to get_response handler that is waiting - self.assertEqual(messages[17].msg_type, "skill.converse.get_response") - self.assertEqual(messages[17].data["skill_id"], self.skill_id) - self.assertEqual(messages[17].data["utterances"], ["ok"]) + self.assertEqual(messages[13].msg_type, f"{self.skill_id}.converse.get_response") + self.assertEqual(messages[13].data["utterances"], ["ok"]) # converse pipeline activates the skill last_used timestamp - self.assertEqual(messages[18].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[19].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[20].msg_type, "ovos.session.update_default") + self.assertEqual(messages[14].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[15].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[16].msg_type, "ovos.session.update_default") # disable get_response for this session - self.assertEqual(messages[21].msg_type, "skill.converse.get_response.disable") - self.assertEqual(messages[22].msg_type, "ovos.session.update_default") + self.assertEqual(messages[17].msg_type, "skill.converse.get_response.disable") + self.assertEqual(messages[18].msg_type, "ovos.session.update_default") # post self.get_response intent code - self.assertEqual(messages[23].msg_type, "enclosure.active_skill") - self.assertEqual(messages[23].data["skill_id"], self.skill_id) - self.assertEqual(messages[24].msg_type, "speak") - self.assertEqual(messages[24].data["lang"], "en-us") - self.assertFalse(messages[24].data["expect_response"]) - self.assertEqual(messages[24].data["utterance"], "ok") - self.assertEqual(messages[24].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[19].msg_type, "enclosure.active_skill") + self.assertEqual(messages[19].data["skill_id"], self.skill_id) + self.assertEqual(messages[20].msg_type, "speak") + self.assertEqual(messages[20].data["lang"], "en-us") + self.assertFalse(messages[20].data["expect_response"]) + self.assertEqual(messages[20].data["utterance"], "ok") + self.assertEqual(messages[20].data["meta"]["skill"], self.skill_id) - self.assertEqual(messages[25].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[25].data["name"], "TestAbortSkill.handle_test_get_response3") + self.assertEqual(messages[21].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[21].data["name"], "TestAbortSkill.handle_test_get_response3") # verify default session is now updated - self.assertEqual(messages[26].msg_type, "ovos.session.update_default") - self.assertEqual(messages[26].data["session_data"]["session_id"], "default") + self.assertEqual(messages[22].msg_type, "ovos.session.update_default") + self.assertEqual(messages[22].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[26].data["session_data"]) + sess = Session.deserialize(messages[22].data["session_data"]) self.assertEqual(sess.session_id, "default") def test_nested(self): @@ -772,12 +692,9 @@ def answer_get_response(msg): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected - "skill.converse.pong", # test skill - "skill.converse.pong", # hello world skill # skill selected - "intent.service.skills.activated", + "intent.service.skills.activated", # default session injected f"{self.skill_id}.activate", f"{self.skill_id}:test_get_response_cascade.intent", @@ -791,10 +708,9 @@ def answer_get_response(msg): "ovos.session.update_default", # sync get_response status "mycroft.mic.listen", # no dialog in self.get_response "recognizer_loop:utterance", # A - "skill.converse.ping", + f"{self.skill_id}.converse.ping", "skill.converse.pong", - "skill.converse.pong", - "skill.converse.get_response", # A + f"{self.skill_id}.converse.get_response", # A "intent.service.skills.activated", f"{self.skill_id}.activate", "ovos.session.update_default", # sync skill trigger @@ -806,10 +722,9 @@ def answer_get_response(msg): "ovos.session.update_default", # sync get_response status "mycroft.mic.listen", # no dialog in self.get_response "recognizer_loop:utterance", # B - "skill.converse.ping", - "skill.converse.pong", + f"{self.skill_id}.converse.ping", "skill.converse.pong", - "skill.converse.get_response", # B + f"{self.skill_id}.converse.get_response", # B "intent.service.skills.activated", f"{self.skill_id}.activate", "ovos.session.update_default", # sync skill trigger @@ -821,10 +736,9 @@ def answer_get_response(msg): "ovos.session.update_default", # sync get_response status "mycroft.mic.listen", # no dialog in self.get_response "recognizer_loop:utterance", # C - "skill.converse.ping", + f"{self.skill_id}.converse.ping", "skill.converse.pong", - "skill.converse.pong", - "skill.converse.get_response", # C + f"{self.skill_id}.converse.get_response", # C "intent.service.skills.activated", f"{self.skill_id}.activate", "ovos.session.update_default", # sync skill trigger @@ -836,10 +750,9 @@ def answer_get_response(msg): "ovos.session.update_default", # sync get_response status "mycroft.mic.listen", # no dialog in self.get_response "recognizer_loop:utterance", # cancel - "skill.converse.ping", - "skill.converse.pong", + f"{self.skill_id}.converse.ping", "skill.converse.pong", - "skill.converse.get_response", # cancel + f"{self.skill_id}.converse.get_response", # cancel "intent.service.skills.activated", f"{self.skill_id}.activate", "ovos.session.update_default", # sync skill trigger @@ -868,185 +781,61 @@ def answer_get_response(msg): print(m.msg_type, m.context["session"]["session_id"]) self.assertEqual(m.context["session"]["session_id"], "default") - # converse intent pipeline - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[3].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], messages[2].context["skill_id"]) - self.assertEqual(messages[3].data["skill_id"], messages[3].context["skill_id"]) - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[2].data["can_handle"]) - self.assertFalse(messages[3].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[3].data["can_handle"]) - self.assertFalse(messages[2].data["can_handle"]) - # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[4].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[4].data["skill_id"], self.skill_id) - self.assertEqual(messages[5].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[1].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[1].data["skill_id"], self.skill_id) + self.assertEqual(messages[2].msg_type, f"{self.skill_id}.activate") # verify intent triggers - self.assertEqual(messages[6].msg_type, f"{self.skill_id}:test_get_response_cascade.intent") + self.assertEqual(messages[3].msg_type, f"{self.skill_id}:test_get_response_cascade.intent") # verify intent execution - self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[7].data["name"], "TestAbortSkill.handle_test_get_response_cascade") + self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[4].data["name"], "TestAbortSkill.handle_test_get_response_cascade") # post self.get_response intent code - self.assertEqual(messages[8].msg_type, "enclosure.active_skill") - self.assertEqual(messages[8].data["skill_id"], self.skill_id) - self.assertEqual(messages[9].msg_type, "speak") - self.assertEqual(messages[9].data["lang"], "en-us") - self.assertFalse(messages[9].data["expect_response"]) - self.assertEqual(messages[9].data["utterance"], "give me items") - self.assertEqual(messages[9].data["meta"]["skill"], self.skill_id) - - # enable get_response for this session - self.assertEqual(messages[10].msg_type, "skill.converse.get_response.enable") - self.assertEqual(messages[11].msg_type, "ovos.session.update_default") - - # 3 sound prompts (no dialog in this test) - self.assertEqual(messages[12].msg_type, "mycroft.mic.listen") - - # check utterance goes through converse cycle - self.assertEqual(messages[13].msg_type, "recognizer_loop:utterance") - self.assertEqual(messages[14].msg_type, "skill.converse.ping") - - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[15].data["can_handle"]) - self.assertFalse(messages[16].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[16].data["can_handle"]) - self.assertFalse(messages[15].data["can_handle"]) - - # captured utterance sent to get_response handler that is waiting - self.assertEqual(messages[17].msg_type, "skill.converse.get_response") - self.assertEqual(messages[17].data["skill_id"], self.skill_id) - self.assertEqual(messages[17].data["utterances"], ["A"]) - - # converse pipeline activates the skill last_used timestamp - self.assertEqual(messages[18].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[19].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[20].msg_type, "ovos.session.update_default") - - # disable get_response for this session - self.assertEqual(messages[21].msg_type, "skill.converse.get_response.disable") - self.assertEqual(messages[22].msg_type, "ovos.session.update_default") - - ## response 2 - - # enable get_response for this session - self.assertEqual(messages[23].msg_type, "skill.converse.get_response.enable") - self.assertEqual(messages[24].msg_type, "ovos.session.update_default") - - # 3 sound prompts (no dialog in this test) - self.assertEqual(messages[25].msg_type, "mycroft.mic.listen") - - # check utterance goes through converse cycle - self.assertEqual(messages[26].msg_type, "recognizer_loop:utterance") - self.assertEqual(messages[27].msg_type, "skill.converse.ping") - - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[28].data["can_handle"]) - self.assertFalse(messages[29].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[29].data["can_handle"]) - self.assertFalse(messages[28].data["can_handle"]) - - # captured utterance sent to get_response handler that is waiting - self.assertEqual(messages[30].msg_type, "skill.converse.get_response") - self.assertEqual(messages[30].data["skill_id"], self.skill_id) - self.assertEqual(messages[30].data["utterances"], ["B"]) - - # converse pipeline activates the skill last_used timestamp - self.assertEqual(messages[31].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[32].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[33].msg_type, "ovos.session.update_default") - - # disable get_response for this session - self.assertEqual(messages[34].msg_type, "skill.converse.get_response.disable") - self.assertEqual(messages[35].msg_type, "ovos.session.update_default") - - ## response 3 - - # enable get_response for this session - self.assertEqual(messages[36].msg_type, "skill.converse.get_response.enable") - self.assertEqual(messages[37].msg_type, "ovos.session.update_default") - - # 3 sound prompts (no dialog in this test) - self.assertEqual(messages[38].msg_type, "mycroft.mic.listen") - - # check utterance goes through converse cycle - self.assertEqual(messages[39].msg_type, "recognizer_loop:utterance") - self.assertEqual(messages[40].msg_type, "skill.converse.ping") - - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[41].data["can_handle"]) - self.assertFalse(messages[42].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[42].data["can_handle"]) - self.assertFalse(messages[41].data["can_handle"]) - - # captured utterance sent to get_response handler that is waiting - self.assertEqual(messages[43].msg_type, "skill.converse.get_response") - self.assertEqual(messages[43].data["skill_id"], self.skill_id) - self.assertEqual(messages[43].data["utterances"], ["C"]) - - # converse pipeline activates the skill last_used timestamp - self.assertEqual(messages[44].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[45].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[46].msg_type, "ovos.session.update_default") - - # disable get_response for this session - self.assertEqual(messages[47].msg_type, "skill.converse.get_response.disable") - self.assertEqual(messages[48].msg_type, "ovos.session.update_default") - - ## response 3 - - # enable get_response for this session - self.assertEqual(messages[49].msg_type, "skill.converse.get_response.enable") - self.assertEqual(messages[50].msg_type, "ovos.session.update_default") - - # 3 sound prompts (no dialog in this test) - self.assertEqual(messages[51].msg_type, "mycroft.mic.listen") - - # check utterance goes through converse cycle - self.assertEqual(messages[52].msg_type, "recognizer_loop:utterance") - self.assertEqual(messages[53].msg_type, "skill.converse.ping") - - # assert it reports converse method has been implemented by skill - if messages[2].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[54].data["can_handle"]) - self.assertFalse(messages[55].data["can_handle"]) - if messages[3].data["skill_id"] == self.skill_id: # we dont know order of pong responses - self.assertTrue(messages[55].data["can_handle"]) - self.assertFalse(messages[54].data["can_handle"]) - - # captured utterance sent to get_response handler that is waiting - self.assertEqual(messages[56].msg_type, "skill.converse.get_response") - self.assertEqual(messages[56].data["skill_id"], self.skill_id) - self.assertEqual(messages[56].data["utterances"], ["cancel"]) - - # converse pipeline activates the skill last_used timestamp - self.assertEqual(messages[57].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[58].msg_type, f"{self.skill_id}.activate") - self.assertEqual(messages[59].msg_type, "ovos.session.update_default") - - # disable get_response for this session - self.assertEqual(messages[60].msg_type, "skill.converse.get_response.disable") - self.assertEqual(messages[61].msg_type, "ovos.session.update_default") + self.assertEqual(messages[5].msg_type, "enclosure.active_skill") + self.assertEqual(messages[5].data["skill_id"], self.skill_id) + self.assertEqual(messages[6].msg_type, "speak") + self.assertEqual(messages[6].data["lang"], "en-us") + self.assertFalse(messages[6].data["expect_response"]) + self.assertEqual(messages[6].data["utterance"], "give me items") + self.assertEqual(messages[6].data["meta"]["skill"], self.skill_id) + + responses = ["A", "B", "C", "cancel"] + for response in responses: + i = 6 + responses.index(response) * 12 + # enable get_response for this session + self.assertEqual(messages[i+1].msg_type, "skill.converse.get_response.enable") + self.assertEqual(messages[i+2].msg_type, "ovos.session.update_default") + + # 3 sound prompts (no dialog in this test) + self.assertEqual(messages[i+3].msg_type, "mycroft.mic.listen") + + # check utterance goes through converse cycle + self.assertEqual(messages[i+4].msg_type, "recognizer_loop:utterance") + self.assertEqual(messages[i+5].msg_type, f"{self.skill_id}.converse.ping") + self.assertEqual(messages[i+6].msg_type, "skill.converse.pong") + + # captured utterance sent to get_response handler that is waiting + self.assertEqual(messages[i+7].msg_type, f"{self.skill_id}.converse.get_response") + self.assertEqual(messages[i+7].data["utterances"], [response]) + + # converse pipeline activates the skill last_used timestamp + self.assertEqual(messages[i+8].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[i+9].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[i+10].msg_type, "ovos.session.update_default") + + # disable get_response for this session + self.assertEqual(messages[i+11].msg_type, "skill.converse.get_response.disable") + self.assertEqual(messages[i+12].msg_type, "ovos.session.update_default") # intent return - self.assertEqual(messages[62].msg_type, "skill_items") - self.assertEqual(messages[62].data, {"items": ["A", "B", "C"]}) + self.assertEqual(messages[55].msg_type, "skill_items") + self.assertEqual(messages[55].data, {"items": ["A", "B", "C"]}) # report handler complete - self.assertEqual(messages[63].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[63].data["name"], "TestAbortSkill.handle_test_get_response_cascade") + self.assertEqual(messages[56].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[56].data["name"], "TestAbortSkill.handle_test_get_response_cascade") - self.assertEqual(messages[64].msg_type, "ovos.session.update_default") + self.assertEqual(messages[57].msg_type, "ovos.session.update_default") diff --git a/test/end2end/session/test_session.py b/test/end2end/session/test_session.py index 30a349e6006..148ab83ae48 100644 --- a/test/end2end/session/test_session.py +++ b/test/end2end/session/test_session.py @@ -45,9 +45,7 @@ def wait_for_n_messages(n): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", # no session - "skill.converse.ping", # default session injected - "skill.converse.pong", - "intent.service.skills.activated", + "intent.service.skills.activated", # default session injected f"{self.skill_id}.activate", f"{self.skill_id}:HelloWorldIntent", "mycroft.skill.handler.start", @@ -64,63 +62,54 @@ def wait_for_n_messages(n): for m in expected_messages: self.assertTrue(m in mtypes) - # verify that "session" is injected + # verify that "session" and "lang" is injected # (missing in utterance message) and kept in all messages for m in messages[1:]: self.assertEqual(m.context["session"]["session_id"], "default") - - # verify that "lang" is injected by converse.ping - # (missing in utterance message) and kept in all messages - self.assertEqual(messages[1].msg_type, "skill.converse.ping") - for m in messages[1:]: self.assertEqual(m.context["lang"], "en-us") - # verify "pong" answer from hello world skill - self.assertEqual(messages[2].msg_type, "skill.converse.pong") - self.assertEqual(messages[2].data["skill_id"], self.skill_id) - self.assertEqual(messages[2].context["skill_id"], self.skill_id) - self.assertFalse(messages[2].data["can_handle"]) - # verify skill is activated by intent service (intent pipeline matched) - self.assertEqual(messages[3].msg_type, "intent.service.skills.activated") - self.assertEqual(messages[3].data["skill_id"], self.skill_id) - self.assertEqual(messages[4].msg_type, f"{self.skill_id}.activate") + self.assertEqual(messages[1].msg_type, "intent.service.skills.activated") + self.assertEqual(messages[1].data["skill_id"], self.skill_id) + self.assertEqual(messages[2].msg_type, f"{self.skill_id}.activate") # verify intent triggers - self.assertEqual(messages[5].msg_type, f"{self.skill_id}:HelloWorldIntent") - self.assertEqual(messages[5].data["intent_type"], f"{self.skill_id}:HelloWorldIntent") + self.assertEqual(messages[3].msg_type, f"{self.skill_id}:HelloWorldIntent") + self.assertEqual(messages[3].data["intent_type"], f"{self.skill_id}:HelloWorldIntent") # verify skill_id is now present in every message.context - for m in messages[5:]: + for m in messages[3:]: self.assertEqual(m.context["skill_id"], self.skill_id) # verify intent execution - self.assertEqual(messages[6].msg_type, "mycroft.skill.handler.start") - self.assertEqual(messages[6].data["name"], "HelloWorldSkill.handle_hello_world_intent") - self.assertEqual(messages[7].msg_type, "enclosure.active_skill") - self.assertEqual(messages[7].data["skill_id"], self.skill_id) - self.assertEqual(messages[8].msg_type, "speak") - self.assertEqual(messages[8].data["lang"], "en-us") - self.assertFalse(messages[8].data["expect_response"]) - self.assertEqual(messages[8].data["meta"]["dialog"], "hello.world") - self.assertEqual(messages[8].data["meta"]["skill"], self.skill_id) - self.assertEqual(messages[9].msg_type, "mycroft.skill.handler.complete") - self.assertEqual(messages[9].data["name"], "HelloWorldSkill.handle_hello_world_intent") + self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start") + self.assertEqual(messages[4].data["name"], "HelloWorldSkill.handle_hello_world_intent") + self.assertEqual(messages[5].msg_type, "enclosure.active_skill") + self.assertEqual(messages[5].data["skill_id"], self.skill_id) + self.assertEqual(messages[6].msg_type, "speak") + self.assertEqual(messages[6].data["lang"], "en-us") + self.assertFalse(messages[6].data["expect_response"]) + self.assertEqual(messages[6].data["meta"]["dialog"], "hello.world") + self.assertEqual(messages[6].data["meta"]["skill"], self.skill_id) + self.assertEqual(messages[7].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[7].data["name"], "HelloWorldSkill.handle_hello_world_intent") # verify default session is now updated - self.assertEqual(messages[10].msg_type, "ovos.session.update_default") - self.assertEqual(messages[10].data["session_data"]["session_id"], "default") + self.assertEqual(messages[8].msg_type, "ovos.session.update_default") + self.assertEqual(messages[8].data["session_data"]["session_id"], "default") # test deserialization of payload - sess = Session.deserialize(messages[10].data["session_data"]) + sess = Session.deserialize(messages[8].data["session_data"]) self.assertEqual(sess.session_id, "default") # test that active skills list has been updated self.assertEqual(sess.active_skills[0][0], self.skill_id) - self.assertEqual(messages[10].data["session_data"]["active_skills"][0][0], self.skill_id) + self.assertEqual(messages[8].data["session_data"]["active_skills"][0][0], self.skill_id) def test_explicit_default_session(self): SessionManager.sessions = {} SessionManager.default_session = SessionManager.sessions["default"] = Session("default") SessionManager.default_session.lang = "en-us" + now = time.time() + SessionManager.default_session.active_skills = [(self.skill_id, now)] messages = [] @@ -151,7 +140,7 @@ def wait_for_n_messages(n): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", - "skill.converse.ping", + f"{self.skill_id}.converse.ping", "skill.converse.pong", "intent.service.skills.activated", f"{self.skill_id}.activate", @@ -176,7 +165,7 @@ def wait_for_n_messages(n): self.assertEqual(m.context["xxx"], "not-valid") # verify ping/pong answer from hello world skill - self.assertEqual(messages[1].msg_type, "skill.converse.ping") + self.assertEqual(messages[1].msg_type, f"{self.skill_id}.converse.ping") self.assertEqual(messages[2].msg_type, "skill.converse.pong") self.assertEqual(messages[2].data["skill_id"], self.skill_id) self.assertEqual(messages[2].context["skill_id"], self.skill_id) @@ -219,6 +208,7 @@ def wait_for_n_messages(n): # test that active skills list has been updated self.assertEqual(messages[10].data["session_data"]["active_skills"][0][0], self.skill_id) self.assertEqual(sess.active_skills[0][0], self.skill_id) + self.assertNotEqual(sess.active_skills[0][1], now) def test_explicit_session(self): SessionManager.sessions = {} @@ -245,7 +235,9 @@ def wait_for_n_messages(n): self.core.bus.on("message", new_msg) - sess = Session() + sess = Session("test-session") + now = time.time() + sess.active_skills = [(self.skill_id, now)] utt = Message("recognizer_loop:utterance", {"utterances": ["hello world"]}, {"session": sess.serialize(), # explicit @@ -255,7 +247,7 @@ def wait_for_n_messages(n): # confirm all expected messages are sent expected_messages = [ "recognizer_loop:utterance", - "skill.converse.ping", + f"{self.skill_id}.converse.ping", "skill.converse.pong", "intent.service.skills.activated", f"{self.skill_id}.activate", @@ -279,7 +271,7 @@ def wait_for_n_messages(n): self.assertEqual(m.context["xxx"], "not-valid") # verify ping/pong answer from hello world skill - self.assertEqual(messages[1].msg_type, "skill.converse.ping") + self.assertEqual(messages[1].msg_type, f"{self.skill_id}.converse.ping") self.assertEqual(messages[2].msg_type, "skill.converse.pong") self.assertEqual(messages[2].data["skill_id"], self.skill_id) self.assertEqual(messages[2].context["skill_id"], self.skill_id) @@ -313,6 +305,7 @@ def wait_for_n_messages(n): # test that active skills list has been updated sess = SessionManager.sessions[sess.session_id] self.assertEqual(sess.active_skills[0][0], self.skill_id) + self.assertNotEqual(sess.active_skills[0][1], now) # test that default session remains unchanged self.assertEqual(SessionManager.default_session.active_skills, []) diff --git a/test/integrationtests/test_workshop.py b/test/integrationtests/test_workshop.py index 8660b366ea5..fc5e469497a 100644 --- a/test/integrationtests/test_workshop.py +++ b/test/integrationtests/test_workshop.py @@ -67,8 +67,8 @@ def test_registered_events(self): self.assertTrue(event in registered_events) # base skill class events exclusive to ovos-core - default_ovos = ["skill.converse.ping", - "skill.converse.request", + default_ovos = [f"{self.skill.skill_id}.converse.ping", + f"{self.skill.skill_id}.converse.request", "intent.service.skills.activated", "intent.service.skills.deactivated", f"{self.skill.skill_id}.activate", diff --git a/test/unittests/common_query/test_skill.py b/test/unittests/common_query/test_skill.py index 2891eb8d3dc..aa6d9efdf89 100644 --- a/test/unittests/common_query/test_skill.py +++ b/test/unittests/common_query/test_skill.py @@ -65,8 +65,8 @@ def test_registered_events(self): self.assertTrue(event in registered_events) # base skill class events exclusive to ovos-core - default_ovos = ["skill.converse.ping", - "skill.converse.request", + default_ovos = [f"{self.skill.skill_id}.converse.ping", + f"{self.skill.skill_id}.converse.request", f"{self.skill.skill_id}.activate", f"{self.skill.skill_id}.deactivate"] for event in default_ovos: diff --git a/test/unittests/skills/test_intent_service.py b/test/unittests/skills/test_intent_service.py index 80b23873471..a6862e9e9fe 100644 --- a/test/unittests/skills/test_intent_service.py +++ b/test/unittests/skills/test_intent_service.py @@ -13,6 +13,7 @@ # limitations under the License. # from unittest import TestCase, mock +import time from adapt.intent import IntentBuilder from mycroft.configuration.locale import setup_locale @@ -20,6 +21,7 @@ from ovos_bus_client.message import Message from mycroft.skills.intent_service import IntentService from ovos_utils.messagebus import get_message_lang +from ovos_utils.log import LOG from mycroft.skills.intent_services.adapt_service import (ContextManager, AdaptIntent) @@ -91,115 +93,6 @@ def check_converse_request(message, skill_id): message.data['skill_id'] == skill_id) -class ConversationTest(TestCase): - def setUp(self): - bus = mock.Mock() - self.intent_service = IntentService(bus) - self.intent_service.converse.activate_skill('atari_skill') - self.intent_service.converse.activate_skill('c64_skill') - - def _collect(message=None): - return [i[0] for i in self.intent_service.converse.active_skills] - - self.intent_service.converse._collect_converse_skills = _collect - - def test_converse(self): - """Check that the _converse method reports if the utterance is handled. - - Also check that the skill that handled the query is moved to the - top of the active skill list. - """ - def response(message, return_msg_type): - c64 = Message(return_msg_type, {'skill_id': 'c64_skill', - 'result': False}) - atari = Message(return_msg_type, {'skill_id': 'atari_skill', - 'result': True}) - msgs = {'c64_skill': c64, 'atari_skill': atari} - - return msgs[message.data['skill_id']] - - self.intent_service.converse.bus.wait_for_response.side_effect = response - - hello = ['hello old friend'] - utterance_msg = Message('recognizer_loop:utterance', - data={'lang': 'en-US', - 'utterances': hello}) - result = self.intent_service.converse.converse_with_skills(hello, "en-US", utterance_msg) - self.intent_service.converse.activate_skill(result.skill_id) - # Check that the active skill list was updated to set the responding - # Skill first. - first_active_skill = self.intent_service.active_skills[0][0] - self.assertEqual(first_active_skill, 'atari_skill') - - # Check that a skill responded that it could handle the message - self.assertTrue(result) - - def test_converse_error(self): - """Check that all skill IDs in the active_skills list are called. - even if there's an error. - """ - def response(message, return_msg_type): - c64 = Message(return_msg_type, {'skill_id': 'c64_skill', - 'result': False}) - amiga = Message(return_msg_type, - {'skill_id': 'amiga_skill', - 'error': 'skill id does not exist'}) - atari = Message(return_msg_type, {'skill_id': 'atari_skill', - 'result': False}) - msgs = {'c64_skill': c64, - 'atari_skill': atari, - 'amiga_skill': amiga} - - return msgs.get(message.data['skill_id']) - - self.intent_service.converse.activate_skill('amiga_skill') - self.intent_service.bus.wait_for_response.side_effect = response - - hello = ['hello old friend'] - utterance_msg = Message('recognizer_loop:utterance', - data={'lang': 'en-US', - 'utterances': hello}) - result = self.intent_service.converse.converse_with_skills(hello, 'en-US', utterance_msg) - - # Check that the active skill list was updated to set the responding - # Skill first. - - # Check that a skill responded that it couldn't handle the message - self.assertFalse(result) - - # Check that each skill in the list of active skills were called - call_args = self.intent_service.bus.wait_for_response.call_args_list - sent_skill_ids = [call[0][0].data['skill_id'] for call in call_args] - self.assertEqual(sent_skill_ids, - ['amiga_skill', 'c64_skill', 'atari_skill']) - - def test_reset_converse(self): - """Check that a blank stt sends the reset signal to the skills.""" - def response(message, return_msg_type): - c64 = Message(return_msg_type, - {'skill_id': 'c64_skill', - 'error': 'skill id does not exist'}) - atari = Message(return_msg_type, {'skill_id': 'atari_skill', - 'result': False}) - msgs = {'c64_skill': c64, 'atari_skill': atari} - - return msgs.get(message.data['skill_id'], None) - - reset_msg = Message('mycroft.speech.recognition.unknown', - data={'lang': 'en-US'}) - self.intent_service.bus.wait_for_response.side_effect = response - - self.intent_service.reset_converse(reset_msg) - # Check send messages - wait_for_response_mock = self.intent_service.bus.wait_for_response - c64_message = wait_for_response_mock.call_args_list[0][0][0] - self.assertTrue(check_converse_request(c64_message, 'c64_skill')) - atari_message = wait_for_response_mock.call_args_list[1][0][0] - self.assertTrue(check_converse_request(atari_message, 'atari_skill')) - #first_active_skill = self.intent_service.active_skills[0][0] - #self.assertEqual(first_active_skill, 'atari_skill') - - class TestLanguageExtraction(TestCase): @mock.patch.dict(Configuration._Configuration__patch, BASE_CONF) def test_no_lang_in_message(self):