Skip to content

Commit

Permalink
test complete_intent_failure path
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 30, 2023
1 parent a03d79d commit 1356800
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions test/end2end/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 1356800

Please sign in to comment.