From 1356800c542a3b1c536bc8407b35d89b4b6c6b67 Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Sat, 30 Sep 2023 05:56:26 +0100 Subject: [PATCH] test complete_intent_failure path --- test/end2end/session/test_session.py | 104 +++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/test/end2end/session/test_session.py b/test/end2end/session/test_session.py index bd8ced6bbb3..282c918df45 100644 --- a/test/end2end/session/test_session.py +++ b/test/end2end/session/test_session.py @@ -268,6 +268,110 @@ def wait_for_n_messages(n): self.assertEqual(messages[10].data["session_data"]["active_skills"][0][0], self.skill_id) self.assertEqual(sess.active_skills[0][0], self.skill_id) + def test_complete_failure(self): + SessionManager.sessions = {} + SessionManager.default_session = SessionManager.sessions["default"] = Session("default") + SessionManager.default_session.lang = "en-us" + messages = [] + + def new_msg(msg): + nonlocal messages + messages.append(Message.deserialize(msg)) + print(len(messages), msg) + + def wait_for_n_messages(n): + nonlocal messages + while len(messages) < n: + sleep(0.1) + + self.core.bus.on("message", new_msg) + + utt = Message("recognizer_loop:utterance", + {"utterances": ["invalid"]}, + {"session": SessionManager.default_session.serialize()}) + self.core.bus.emit(utt) + + # confirm all expected messages are sent + expected_messages = [ + "recognizer_loop:utterance", + "skill.converse.ping", + "skill.converse.pong", + "mycroft.skills.fallback", + "mycroft.skill.handler.start", + "mycroft.skill.handler.complete", + "mycroft.skills.fallback.response", + "mycroft.skills.fallback", + "mycroft.skill.handler.start", + "mycroft.skill.handler.complete", + "mycroft.skills.fallback.response", + "mycroft.skills.fallback", + "mycroft.skill.handler.start", + "mycroft.skill.handler.complete", + "mycroft.skills.fallback.response", + "mycroft.audio.play_sound", + "complete_intent_failure", + "ovos.session.update_default" + ] + wait_for_n_messages(len(expected_messages)) + + self.assertEqual(len(expected_messages), len(messages)) + + mtypes = [m.msg_type for m in messages] + for m in expected_messages: + self.assertTrue(m in mtypes) + + # verify that contexts are kept around + for m in messages: + 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[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 fallback is triggered with pt-pt from lang disambiguation step + self.assertEqual(messages[3].msg_type, "mycroft.skills.fallback") + + # high prio 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"]) + + # 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"]) + + # 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[13].msg_type, "mycroft.skill.handler.complete") + self.assertEqual(messages[13].data["handler"], "fallback") + self.assertEqual(messages[14].msg_type, "mycroft.skills.fallback.response") + self.assertFalse(messages[14].data["handled"]) + + # complete intent failure + self.assertEqual(messages[15].msg_type, "mycroft.audio.play_sound") + self.assertEqual(messages[15].data["uri"], "snd/error.mp3") + self.assertEqual(messages[16].msg_type, "complete_intent_failure") + + # verify default session is now updated + self.assertEqual(messages[17].msg_type, "ovos.session.update_default") + self.assertEqual(messages[17].data["session_data"]["session_id"], "default") + @skip("TODO works if run standalone, otherwise has side effects in other tests") def test_complete_failure_lang_detect(self): SessionManager.sessions = {}