Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed May 3, 2024
1 parent fe0d409 commit c02d017
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 88 deletions.
28 changes: 8 additions & 20 deletions test/end2end/session/test_fallback_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,11 @@ def wait_for_n_messages(n):
"mycroft.skill.handler.start",
"enclosure.active_skill",
"speak",
# self activation from skill, instead of from core
# activation from skill, because fallback consumed utterance
"intent.service.skills.activate",
"intent.service.skills.activated",
f"{self.skill_id}.activate",
"ovos.session.update_default", # because it comes from skill
# backwards compat activation for older cores
"active_skill_request",
"intent.service.skills.activated",
f"{self.skill_id}.activate",
"ovos.session.update_default", # because it comes from skill
"ovos.session.update_default",
# report handling
"mycroft.skill.handler.complete",
"mycroft.skills.fallback.response",
Expand Down Expand Up @@ -143,23 +138,16 @@ def wait_for_n_messages(n):
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[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[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"])
self.assertEqual(messages[17].msg_type, "mycroft.skill.handler.complete")
self.assertEqual(messages[17].data["handler"], "fallback")
self.assertEqual(messages[18].msg_type, "mycroft.skills.fallback.response")
self.assertTrue(messages[18].data["handled"])

# verify default session is now updated
self.assertEqual(messages[23].msg_type, "ovos.session.update_default")
self.assertEqual(messages[23].data["session_data"]["session_id"], "default")
self.assertEqual(messages[19].msg_type, "ovos.session.update_default")
self.assertEqual(messages[19].data["session_data"]["session_id"], "default")

# test second message with no session resumes default active skills
messages = []
Expand Down
149 changes: 81 additions & 68 deletions test/end2end/session/test_sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ def wait_for_n_messages(n):

# confirm all expected messages are sent
expected_messages = [
"recognizer_loop:utterance", # no session
"intent.service.skills.activated", # default session injected
f"{self.skill_id}.activate",
"recognizer_loop:utterance",
f"{self.skill_id}:ScheduleIntent",
"mycroft.skill.handler.start",
"intent.service.skills.activate",
"intent.service.skills.activated",
f"{self.skill_id}.activate",
"ovos.session.update_default",
"enclosure.active_skill",
"speak",
"mycroft.scheduler.schedule_event",
Expand All @@ -76,55 +78,60 @@ def wait_for_n_messages(n):
self.assertEqual(m.context["session"]["session_id"], "default")
self.assertEqual(m.context["lang"], "en-us")

# verify skill is activated by intent service (intent pipeline matched)
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[3].msg_type, f"{self.skill_id}:ScheduleIntent")
self.assertEqual(messages[3].data["intent_type"], f"{self.skill_id}:ScheduleIntent")
self.assertEqual(messages[1].msg_type, f"{self.skill_id}:ScheduleIntent")
self.assertEqual(messages[1].data["intent_type"], f"{self.skill_id}:ScheduleIntent")
# verify skill_id is now present in every message.context
for m in messages[3:]:
for m in messages[1:]:
self.assertEqual(m.context["skill_id"], self.skill_id)

# verify intent execution
self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start")
self.assertEqual(messages[4].data["name"], "ScheduleSkill.handle_sched_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"], "done")
self.assertEqual(messages[6].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[7].msg_type, "mycroft.scheduler.schedule_event")
self.assertEqual(messages[8].msg_type, "mycroft.skill.handler.complete")
self.assertEqual(messages[8].data["name"], "ScheduleSkill.handle_sched_intent")
self.assertEqual(messages[2].msg_type, "mycroft.skill.handler.start")
self.assertEqual(messages[2].data["name"], "ScheduleSkill.handle_sched_intent")

self.assertEqual(messages[3].msg_type, "intent.service.skills.activate")
self.assertEqual(messages[3].data["skill_id"], self.skill_id)
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[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["lang"], "en-us")
self.assertFalse(messages[8].data["expect_response"])
self.assertEqual(messages[8].data["meta"]["dialog"], "done")
self.assertEqual(messages[8].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[9].msg_type, "mycroft.scheduler.schedule_event")
self.assertEqual(messages[10].msg_type, "mycroft.skill.handler.complete")
self.assertEqual(messages[10].data["name"], "ScheduleSkill.handle_sched_intent")

# verify default session is now updated
self.assertEqual(messages[9].msg_type, "ovos.session.update_default")
self.assertEqual(messages[9].data["session_data"]["session_id"], "default")
self.assertEqual(messages[11].msg_type, "ovos.session.update_default")
self.assertEqual(messages[11].data["session_data"]["session_id"], "default")
# test deserialization of payload
sess = Session.deserialize(messages[9].data["session_data"])
sess = Session.deserialize(messages[11].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[9].data["session_data"]["active_skills"][0][0], self.skill_id)
self.assertEqual(messages[11].data["session_data"]["active_skills"][0][0], self.skill_id)

# ensure context in triggered event is the same from message that triggered the intent
intent_context = messages[3].context
self.assertEqual(messages[10].msg_type, "skill-ovos-schedule.openvoiceos:my_event")
self.assertEqual(messages[10].context, intent_context)
self.assertEqual(messages[11].msg_type, "enclosure.active_skill")
self.assertEqual(messages[11].context, intent_context)
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"]["dialog"], "trigger")
self.assertEqual(messages[12].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[4].msg_type, "intent.service.skills.activated")
intent_context = messages[4].context # when skill added to active list (last context change)

self.assertEqual(messages[12].msg_type, "skill-ovos-schedule.openvoiceos:my_event")
self.assertEqual(messages[12].context, intent_context)
self.assertEqual(messages[13].msg_type, "enclosure.active_skill")
self.assertEqual(messages[13].context, intent_context)
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["meta"]["dialog"], "trigger")
self.assertEqual(messages[14].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[14].context, intent_context)

def test_explicit_session(self):
SessionManager.sessions = {}
Expand Down Expand Up @@ -165,10 +172,11 @@ def wait_for_n_messages(n):
# confirm all expected messages are sent
expected_messages = [
"recognizer_loop:utterance",
"intent.service.skills.activated",
f"{self.skill_id}.activate",
f"{self.skill_id}:ScheduleIntent",
"mycroft.skill.handler.start",
"intent.service.skills.activate",
"intent.service.skills.activated",
f"{self.skill_id}.activate",
"enclosure.active_skill",
"speak",
"mycroft.scheduler.schedule_event",
Expand All @@ -191,44 +199,49 @@ def wait_for_n_messages(n):
for m in messages:
self.assertEqual(m.context["session"]["session_id"], sess.session_id)

# verify skill is activated by intent service (intent pipeline matched)
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[3].msg_type, f"{self.skill_id}:ScheduleIntent")
self.assertEqual(messages[3].data["intent_type"], f"{self.skill_id}:ScheduleIntent")
self.assertEqual(messages[1].msg_type, f"{self.skill_id}:ScheduleIntent")
self.assertEqual(messages[1].data["intent_type"], f"{self.skill_id}:ScheduleIntent")
# verify skill_id is now present in every message.context
for m in messages[3:]:
for m in messages[1:]:
self.assertEqual(m.context["skill_id"], self.skill_id)

# verify skill is activated
self.assertEqual(messages[2].msg_type, "mycroft.skill.handler.start")
self.assertEqual(messages[2].data["name"], "ScheduleSkill.handle_sched_intent")
self.assertEqual(messages[3].msg_type, "intent.service.skills.activate")
self.assertEqual(messages[3].data["skill_id"], self.skill_id)
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[5].msg_type, f"{self.skill_id}.activate")

# verify intent execution
self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start")
self.assertEqual(messages[4].data["name"], "ScheduleSkill.handle_sched_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"], "done")
self.assertEqual(messages[6].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[7].msg_type, "mycroft.scheduler.schedule_event")
self.assertEqual(messages[8].msg_type, "mycroft.skill.handler.complete")
self.assertEqual(messages[8].data["name"], "ScheduleSkill.handle_sched_intent")
self.assertEqual(messages[6].msg_type, "enclosure.active_skill")
self.assertEqual(messages[6].data["skill_id"], self.skill_id)
self.assertEqual(messages[7].msg_type, "speak")
self.assertEqual(messages[7].data["lang"], "en-us")
self.assertFalse(messages[7].data["expect_response"])
self.assertEqual(messages[7].data["meta"]["dialog"], "done")
self.assertEqual(messages[7].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[8].msg_type, "mycroft.scheduler.schedule_event")
self.assertEqual(messages[9].msg_type, "mycroft.skill.handler.complete")
self.assertEqual(messages[9].data["name"], "ScheduleSkill.handle_sched_intent")

# ensure context in triggered event is the same from message that triggered the intent
intent_context = messages[3].context
self.assertEqual(messages[9].msg_type, "skill-ovos-schedule.openvoiceos:my_event")
self.assertEqual(messages[9].context, intent_context)
self.assertEqual(messages[10].msg_type, "enclosure.active_skill")
self.assertEqual(messages[4].msg_type, "intent.service.skills.activated")
intent_context = messages[4].context # when skill added to active list (last context change)

self.assertEqual(messages[10].msg_type, "skill-ovos-schedule.openvoiceos:my_event")
self.assertEqual(messages[10].context, intent_context)
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"]["dialog"], "trigger")
self.assertEqual(messages[11].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[11].msg_type, "enclosure.active_skill")
self.assertEqual(messages[11].context, intent_context)
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"]["dialog"], "trigger")
self.assertEqual(messages[12].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[12].context, intent_context)

def tearDown(self) -> None:
self.core.stop()

0 comments on commit c02d017

Please sign in to comment.