Skip to content

Commit

Permalink
fix/deactivate inside intent/converse (#451)
Browse files Browse the repository at this point in the history
* fix/450

closes #450

needs OpenVoiceOS/OVOS-workshop#198

* start fixing tests

* fix more tests

* also activate skill_id for OCP pipeline

* more tests updated

* update converse session tests

* update stop tests

* update more tests

* update get response tests

* use branch from workshop

* fix test

* fix test

* fix test

* requirements.txt

* explicit tests for the bug being fixed
  • Loading branch information
JarbasAl authored May 4, 2024
1 parent 6ffc43d commit b428104
Show file tree
Hide file tree
Showing 15 changed files with 1,260 additions and 1,133 deletions.
4 changes: 1 addition & 3 deletions ovos_core/intent_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,8 @@ def _emit_match_message(self, match: IntentMatch, message: Message):
message.data["utterance"] = match.utterance

if match.skill_id:
self.converse.activate_skill(match.skill_id, message=message)
# ensure skill_id is present in message.context
message.context["skill_id"] = match.skill_id
# If the service didn't report back the skill_id it
# takes on the responsibility of making the skill "active"

# Launch skill if not handled by the match function
if match.intent_type:
Expand Down
6 changes: 6 additions & 0 deletions ovos_core/intent_services/ocp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def match_high(self, utterances: List[str], lang: str, message: Message = None):
else:
return None

self.activate() # mark skill_id as active, this is a catch all for all OCP skills
return ovos_core.intent_services.IntentMatch(intent_service="OCP_intents",
intent_type=f'ocp:{match["name"]}',
intent_data=match,
Expand All @@ -365,6 +366,7 @@ def match_medium(self, utterances: List[str], lang: str, message: Message = None
# extract the query string
query = self.remove_voc(utterance, "Play", lang).strip()

self.activate() # mark skill_id as active, this is a catch all for all OCP skills
return ovos_core.intent_services.IntentMatch(intent_service="OCP_media",
intent_type=f"ocp:play",
intent_data={"media_type": media_type,
Expand All @@ -391,6 +393,7 @@ def match_fallback(self, utterances: List[str], lang: str, message: Message = No

# extract the query string
query = self.remove_voc(utterance, "Play", lang).strip()
self.activate() # mark skill_id as active, this is a catch all for all OCP skills
return ovos_core.intent_services.IntentMatch(intent_service="OCP_fallback",
intent_type=f"ocp:play",
intent_data={"media_type": media_type,
Expand All @@ -401,6 +404,9 @@ def match_fallback(self, utterances: List[str], lang: str, message: Message = No
utterance=utterance)

def _process_play_query(self, utterance: str, lang: str, match: dict = None):

self.activate() # mark skill_id as active, this is a catch all for all OCP skills

match = match or {}
# if media is currently paused, empty string means "resume playback"
if self.player_state == PlayerState.PAUSED and \
Expand Down
3 changes: 1 addition & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ ovos-plugin-manager<0.1.0, >=0.0.25
ovos-config~=0.0,>=0.0.13a8
ovos-lingua-franca>=0.4.7
ovos-backend-client~=0.1.0
ovos-workshop<0.1.0, >=0.0.16a24

ovos-workshop<0.1.0, >=0.0.16a26
# provides plugins and classic machine learning framework
ovos-classifiers<0.1.0, >=0.0.0a53

Expand Down
37 changes: 21 additions & 16 deletions test/end2end/routing/test_sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ 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",
f"{self.skill_id}:ScheduleIntent",
"mycroft.skill.handler.start",
f"{self.skill_id}:ScheduleIntent", # intent trigger
"mycroft.skill.handler.start", # intent code start

"intent.service.skills.activate", # request (from workshop)
"intent.service.skills.activated", # response (from core)
f"{self.skill_id}.activate", # skill callback
"ovos.session.update_default", # session update (active skill list ync)

"enclosure.active_skill",
"speak",
"mycroft.scheduler.schedule_event",
"mycroft.skill.handler.complete",
"ovos.session.update_default",
# event triggering after 3 seconds

"mycroft.skill.handler.complete", # intent code end
"ovos.session.update_default", # session update (end of utterance default sync)

# skill event triggering after 3 seconds
"skill-ovos-schedule.openvoiceos:my_event",
"enclosure.active_skill",
"speak"
Expand All @@ -69,16 +75,15 @@ def wait_for_n_messages(n):
for m in expected_messages:
self.assertTrue(m in mtypes)

# verify that source an destination are kept until intent trigger
for m in messages[:3]:
self.assertEqual(m.context["source"], "A")
self.assertEqual(m.context["destination"], "B")

# verify that source and destination are swapped after intent trigger
self.assertEqual(messages[3].msg_type, f"{self.skill_id}:ScheduleIntent")
for m in messages[3:]:
self.assertEqual(m.context["source"], "B")
self.assertEqual(m.context["destination"], "A")
self.assertEqual(messages[1].msg_type, f"{self.skill_id}:ScheduleIntent")
for m in messages:
if m.msg_type in ["recognizer_loop:utterance", "ovos.session.update_default"]:
self.assertEqual(messages[0].context["source"], "A")
self.assertEqual(messages[0].context["destination"], "B")
else:
self.assertEqual(m.context["source"], "B")
self.assertEqual(m.context["destination"], "A")

def tearDown(self) -> None:
self.core.stop()
23 changes: 12 additions & 11 deletions test/end2end/routing/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ 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",
f"{self.skill_id}:HelloWorldIntent",
"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.skill.handler.complete",
Expand All @@ -72,13 +74,12 @@ def wait_for_n_messages(n):
for m in messages[1:]:
self.assertEqual(m.context["session"]["session_id"], "default")

# verify that source an destination are kept until intent trigger
for m in messages[:3]:
self.assertEqual(m.context["source"], "A")
self.assertEqual(m.context["destination"], "B")

# verify that source and destination are swapped after intent trigger
self.assertEqual(messages[3].msg_type, f"{self.skill_id}:HelloWorldIntent")
for m in messages[3:]:
self.assertEqual(m.context["source"], "B")
self.assertEqual(m.context["destination"], "A")
self.assertEqual(messages[1].msg_type, f"{self.skill_id}:HelloWorldIntent")
for m in messages:
if m.msg_type in ["recognizer_loop:utterance", "ovos.session.update_default"]:
self.assertEqual(messages[0].context["source"], "A")
self.assertEqual(messages[0].context["destination"], "B")
else:
self.assertEqual(m.context["source"], "B")
self.assertEqual(m.context["destination"], "A")
Loading

0 comments on commit b428104

Please sign in to comment.