From 5a61e931c057b519932ae28b2c48e81ad82d87f2 Mon Sep 17 00:00:00 2001 From: miro Date: Sat, 4 May 2024 22:19:33 +0100 Subject: [PATCH] fix/deactivate_in_converse/fallback avoid the caveats documented in https://github.com/OpenVoiceOS/ovos-core/pull/451 companion to https://github.com/OpenVoiceOS/OVOS-workshop/pull/199 --- requirements/requirements.txt | 2 +- test/end2end/session/test_converse.py | 10 ----- test/end2end/session/test_fallback.py | 59 ++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 5a72256c2c8..a7f019b8a08 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -12,7 +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.16a26 +ovos-workshop<0.1.0, >=0.0.16a27 # provides plugins and classic machine learning framework ovos-classifiers<0.1.0, >=0.0.0a53 diff --git a/test/end2end/session/test_converse.py b/test/end2end/session/test_converse.py index 60a146b821c..3685c4bc3be 100644 --- a/test/end2end/session/test_converse.py +++ b/test/end2end/session/test_converse.py @@ -556,16 +556,6 @@ def wait_for_n_messages(n): "intent.service.skills.deactivated", f"{self.skill_id}.deactivate", "ovos.session.update_default", - - ########### - # TODO - activate is called here if converse return True - "intent.service.skills.activate", - "intent.service.skills.activated", - f"{self.skill_id}.activate", - "ovos.session.update_default", - # /TODO - ovos-workshop PR needed - ########### - # needs ovos-workshop PR "skill.converse.response", # conversed! # session updated diff --git a/test/end2end/session/test_fallback.py b/test/end2end/session/test_fallback.py index 90b1d97859f..955040b1c3d 100644 --- a/test/end2end/session/test_fallback.py +++ b/test/end2end/session/test_fallback.py @@ -241,4 +241,61 @@ def wait_for_n_messages(n): # test that active skills list has been updated for m in messages[10:]: - self.assertEqual(m.context["session"]["active_skills"][0][0], self.skill_id) \ No newline at end of file + self.assertEqual(m.context["session"]["active_skills"][0][0], self.skill_id) + + def test_deactivate_in_fallback(self): + messages = [] + + sess = Session("123") + sess.activate_skill(self.skill_id) # skill is active + + def new_msg(msg): + nonlocal messages + m = Message.deserialize(msg) + if m.msg_type in ["ovos.skills.settings_changed", "ovos.common_play.status"]: + return # skip these, only happen in 1st run + messages.append(m) + print(len(messages), msg) + + def wait_for_n_messages(n): + nonlocal messages + t = time.time() + while len(messages) < n: + sleep(0.1) + if time.time() - t > 10: + raise RuntimeError("did not get the number of expected messages under 10 seconds") + + self.core.bus.on("message", new_msg) + + utt = Message("fallback_deactivate") + self.core.bus.emit(utt) # set internal test skill flag + messages = [] + + utt = Message("recognizer_loop:utterance", + {"utterances": ["deactivate fallback"]}, + {"session":sess.serialize()}) + self.core.bus.emit(utt) + + expected_messages = [ + "recognizer_loop:utterance", + # skill is active, so we get converse events + f"{self.skill_id}.converse.ping", + "skill.converse.pong", + # FallbackV2 + "ovos.skills.fallback.ping", + "ovos.skills.fallback.pong", + # skill executing + f"ovos.skills.fallback.{self.skill_id}.request", + f"ovos.skills.fallback.{self.skill_id}.start", + "enclosure.active_skill", + "speak", + # deactivate skill in fallback handler + "intent.service.skills.deactivate", + "intent.service.skills.deactivated", + f"{self.skill_id}.deactivate", + # activate events suppressed + f"ovos.skills.fallback.{self.skill_id}.response" + ] + wait_for_n_messages(len(expected_messages)) + + self.assertEqual(len(expected_messages), len(messages))